4

所以我注意到在 api 中有一个 addToCartUrl 允许您将该项目添加到沃尔玛的购物车,我使用代码为多个项目执行此操作:

function buyIt() {
//window.open('http://c.affil.walmart.com/t/api02?l=http%3A%2F%2Faffil.walmart.com%2Fcart%2FaddToCart%3Fitems%3D' + product.itemId + '%7C1%26affp1%3DM1u8aZZoZbep0p3P7hVn_sT4Ry97xPSOvnILkAKRCH8%26affilsrc%3Dapi%26veh%3Daff%26wmlspartner%3Dreadonlyapi')
//cs.productLink = '';

if(cs.cartItemIds.length == 1){
  window.open("http://c.affil.walmart.com/t/api02?l=http%3A%2F%2Faffil.walmart.com%2Fcart%2FaddToCart%3Fitems%3D" + cs.cartItemIds[0] + "%7C1%26affp1%3DM1u8aZZoZbep0p3P7hVn_sT4Ry97xPSOvnILkAKRCH8%26affilsrc%3Dapi%26veh%3Daff%26wmlspartner%3Dreadonlyapi");

}
else{
  for(var i = 0; i<(cs.cartItemIds.length - 1); i++){
    console.log(cs.cartItemIds.length);
    console.log(cs.cartItemIds);
    //alert('http://c.affil.walmart.com/t/api02?l=http%3A%2F%2Faffil.walmart.com%2Fcart%2FaddToCart%3Fitems%3D' + cs.cartItemIds[i]+ '%7C1%26affp1%3DM1u8aZZoZbep0p3P7hVn_sT4Ry97xPSOvnILkAKRCH8%26affilsrc%3Dapi%26veh%3Daff%26wmlspartner%3Dreadonlyapi')
    $http.get("http://c.affil.walmart.com/t/api02?l=http%3A%2F%2Faffil.walmart.com%2Fcart%2FaddToCart%3Fitems%3D" + cs.cartItemIds[i] + "%7C1%26affp1%3DM1u8aZZoZbep0p3P7hVn_sT4Ry97xPSOvnILkAKRCH8%26affilsrc%3Dapi%26veh%3Daff%26wmlspartner%3Dreadonlyapi", {}).storage;
    //window.open('https://www.walmart.com/cart/?affilsrc=api&affp1=M1u8aZZoZbep0p3P7hVn_sT4Ry97xPSOvnILkAKRCH8&wmlspartner=readonlyapi&sourceid=api0298ae3c8c842840409172f10b2bfb579d&veh=aff');

  }
  window.open("http://c.affil.walmart.com/t/api02?l=http%3A%2F%2Faffil.walmart.com%2Fcart%2FaddToCart%3Fitems%3D" + cs.cartItemIds[cs.cartItemIds.length - 1] + "%7C1%26affp1%3DM1u8aZZoZbep0p3P7hVn_sT4Ry97xPSOvnILkAKRCH8%26affilsrc%3Dapi%26veh%3Daff%26wmlspartner%3Dreadonlyapi");

}

}

现在它将遍历并将相关链接与产品一起放置,但是当我运行 get 请求并将我带到页面时,它只显示沃尔玛购物车中的一个项目,它在我的应用程序页面上给了我这个错误

“商品或数量无效。您将很快被重定向到沃尔玛。”

4

0 回答 0