【问题标题】:Get Products URLs in prestashop using API使用 API 在 prestashop 中获取产品 URL
【发布时间】:2017-09-18 04:33:07
【问题描述】:

我目前正在使用 Microsoft bot Framework 使用 .NET 开发一个 ChatBot 我创建了可用产品列表并使用 Herocard 在轮播中显示该列表,并在客户单击它时放置一个按钮 BUY 将他带到产品定位问题是我如何使用其 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);
            }

        }
    }

【问题讨论】:

    标签: c# api url prestashop bots


    【解决方案1】:

    我通过使用下面的网址解决了这个问题:

    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://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);
                    }
    
                }
    

    【讨论】:

      猜你喜欢
      • 2014-05-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多