我目前正在使用开发一个带有ChatBot的.NET,我创建了可用产品列表,并使用Herocard以旋转木马显示列表,并在客户端单击它时按一下购买按钮,然后将它带到产品所在的页面,问题是如何使用它的id获得产品url,这样我就可以将其放在BUY按钮中。
List<product> c = ListProduct.GetProductList();
List<Bukimedia.PrestaSharp.Entities.AuxEntities.language> lan = new List<Bukimedia.PrestaSharp.Entities.AuxEntities.language>();
foreach (product p in c)
{
lan = p.name;
foreach (Bukimedia.PrestaSharp.Entities.AuxEntities.language l in lan)
{
;
List<CardImage> cardImages = new List<CardImage>();
cardImages.Add(new CardImage(url: $"http://test.com/123456.jpg"));
List <CardAction> cardButtons = new List<CardAction>();
CardAction plButton = new CardAction()
{
Value =$"i don't know what i should put here",
Type = "openUrl",
Title = "Buy"
};
cardButtons.Add(plButton);
HeroCard plCard = new HeroCard()
{
Title = l.Value,
Subtitle = (p.price.ToString("C", Cultures.usa)),
Images = cardImages,
Buttons = cardButtons
};
Attachment plAttachment = plCard.ToAttachment();
replyMessage.Attachments.Add(plAttachment);
}
}
}
发布于 2017-04-25 09:52:58
我通过使用下面的url解决了这个问题:
product="+p.id
所以我的代码现在运行得很好
List<product> c = ListProduct.GetProductList();
List<Bukimedia.PrestaSharp.Entities.AuxEntities.language> lan = new List<Bukimedia.PrestaSharp.Entities.AuxEntities.language>();
foreach (product p in c)
{
lan = p.name;
foreach (Bukimedia.PrestaSharp.Entities.AuxEntities.language l in lan.Where(l => l.id == 2))
{
{
List<CardImage> cardImages = new List<CardImage>();
cardImages.Add(new CardImage(url: $"http://1234456789@localhost:8080/prestashopdemo/" + p.id_default_image + "-large_default/" + l.Value + ".jpg"));
List<CardAction> cardButtons = new List<CardAction>();
CardAction plButton = new CardAction()
{
Value = $"http://localhost:8080/prestashopdemo/index.php?controller=product&id_product="+p.id,
Type = "openUrl",
Title = "Buy"
};
cardButtons.Add(plButton);
HeroCard plCard = new HeroCard()
{
Title = l.Value,
Subtitle = (p.price.ToString("C")),
Images = cardImages,
Buttons = cardButtons
};
Attachment plAttachment = plCard.ToAttachment();
replyMessage.Attachments.Add(plAttachment);
}
}
https://stackoverflow.com/questions/43538192
复制相似问题