2017-04-21 59 views
0

我目前正在開發一個使用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); 
      } 

     } 
    } 

回答

0

我解決了這個問題得到了產品網址:

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

      } 
相關問題