使用API获取产品网址在prestashop中使用API
问题描述:
我目前正在开发一个使用Microsoft bot的.NET的ChatBot我创建了可用产品列表并使用Herocard在Carousel中显示列表,并在客户端点击它时放置一个按钮购买它带他到该产品所在的问题网页是我如何使用它的id,这样我就可以把它放在按钮BUY通过以下链接使用API获取产品网址在prestashop中使用API
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);
}
}
}
答
我解决了这个问题得到了产品网址:
http://localhost:8080/prestashopdemo/index.php?controller=product&id_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://[email protected]: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);
}
}