4

So I noticed in the api there's a addToCartUrl which allows you to add that item to walmart's cart and I use code to do that for multiple items:

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

}

}

Now that will iterate through and put the corrolating link with the product but when I run the get request and it takes me to the page it only shows one item in the walmart's cart and it gives me this error on my app page

"Invalid item or quantity. You will be redirected to Walmart shortly."

Good Lux
  • 896
  • 9
  • 19
Gabe D.
  • 61
  • 8
  • The loop make _asynchronous_ requests. As such, all of the requests can be made before Walmart has had the time to process any of them. That could explain why you only see a single item in the cart (though, I'd expect the others to show up shortly if you then refreshed the cart page). As for the "invalid item or quantity" msg, no idea. Did you ensure that all requested URLs that you build are correct? Seems like a perfect time to bust out the debugger. – enhzflep Mar 02 '16 at 03:57
  • not to mention add some error handling – charlietfl Mar 02 '16 at 05:28
  • yeah I tested all of the links they all work if I do them one at a time but not if I do them all at once, before I had a button for each item but that's not very ux friendly if a user has to click on each item to buy it and I tried the debugger and nothing seems to be wrong all the code is working @enhzflep – Gabe D. Mar 03 '16 at 19:00
  • @GabeD.- well in that case, since you're confident that your code works as intended and you're sure that the urls your code constructs are also valid, it seems reasonable to assume that the source of the problem is in fact the timing. It seems that your code is firing-off requests to Wallmart too quickly. In that case, you can 'chain' your requests, such that when one of them competes, you fire-off the next one, repeating until all have been submitted.I guess you could use an array to hold all the urls and an index to specify which should be requested next. – enhzflep Mar 03 '16 at 23:44
  • @GabeD.- You should be single-stepping your code to check this. I.e, dont just run the whole loop in the blink of an eye, step through the loop line by line and if it is a matter of timing, you'll finish the loop and open a new window successfully. The debugger is expected to be used in this instance to debug your interaction with the Walmart servers, as opposed to simply debugging your own code. ;) – enhzflep Mar 03 '16 at 23:46

0 Answers0