Developer forum

Forum » Rapido » Add to cart multi from url doesn't seem to work

Add to cart multi from url doesn't seem to work

Gaëtan Di Caro
Reply

Hi,

 

I'm trying to generate a url to add multiple products to the cart with the command addmulti.

Here's a url you can test on a standard rapido solution (contains product numbers that are in the default installation) : http://mysolution.com/Default.aspx?ID=530&ProductLoopCounter1=1&ProductNumber1=10122&Quantity1=2&ProductLoopCounter2=2&ProductNumber2=30001&Quantity2=5&cartcmd=addMulti&feedtype=Counter

This url seems well formed, and I use similarly-formed urls on other non-rapido solutions without any problem.

But it doesn't seem to do anything. The basket is returned as it is in json and no product is added at all.

 

What's wrong here ?


Replies

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi Gaëtan,

 

Shouldn't you be using the ProductId instead of the ProductNumber?

 

Best Regards,

Nuno Aguiar

 
Gaëtan Di Caro
Reply

Hi Nuno,

Thanks for your answer. I have no more luck with ProductID. Besides, I use ProductNumber on other solutions wihout problem.

 
Nicolai Pedersen
Reply

It has to be a POST. You cannot do it using GET.

BR Nicolai

 
Gaëtan Di Caro
Reply

That would explain why it doesn't work when I try the url myself. However in my js code I call Cart.UpdateCart, which does a POST, and I can see it as such in the network trace (as well as all the other parameters)...

 
Nicolai Pedersen
Reply

So you cannot get it to work?

We need to see your implementation to locate the error in your code...

 
Gaëtan Di Caro
Reply

Try this on a normal installation of Rapido, this should normally add 2 different products to the basket, but it doesn't. I can see a POST request is sent, with parameters which look correct. My code's job before that is just to build the url.

 

Cart.UpdateCart('miniCart', '/Default.aspx?ID=5&ProductLoopCounter1=1&ProductNumber1=10122&Quantity1=2&ProductLoopCounter2=2&ProductNumber2=30001&Quantity2=5', "&cartcmd=addmulti", false);

 
Kristian Kirkholt Dynamicweb Employee
Kristian Kirkholt
Reply
This post has been marked as an answer

Hi Gaëtan

We found that this was a problem in the core code. #53031
You will be informed when this is fixed.

Kind Regards
Dynamicweb Support
Kristian Kirkholt

Votes for this answer: 1
 
Gaëtan Di Caro
Reply

Thanks, I look forward to the fix :)

 
Kristian Kirkholt Dynamicweb Employee
Kristian Kirkholt
Reply

Hi Gaëtan

The #53031 Problem now fixed in version 9.4.18

To upgrade please choose this version from backend or download from here:

http://doc.dynamicweb.com/releases-and-downloads/releases

Let me know if you need any more help regarding this

Kind Regards
Dynamicweb Support
Kristian Kirkholt

 
Gaëtan Di Caro
Reply

It sort-of got fixed. It works but only up to a certain amount of products. If I try to add more than 33 products, the response gets a 404

 
Nicolai Pedersen
Reply
This post has been marked as an answer

Hi Gaëtan

It is because there is a limit to how much data that can be put into a get request - and that is also why it was required to be a post.

I've asked the dev team to rollback this change you got - because it has to be a post. So you have to change your request to a post in order to make addmulti work. Rapido js Cart.UpdateCart uses a post, but all the data you send is in the querystring - that is what is causing this. So it has to be in the body of the request and not on the URL as qs parameters

So instead of this:
Cart.UpdateCart('miniCart', '/Default.aspx?ID=5&ProductLoopCounter1=1&ProductNumber1=10122&Quantity1=2&ProductLoopCounter2=2&ProductNumber2=30001&Quantity2=5', "&cartcmd=addmulti", false);
You have to do this:
Cart.UpdateCart('miniCart', '/Default.aspx?ID=5', "ProductLoopCounter1=1&ProductNumber1=10122&Quantity1=2&ProductLoopCounter2=2&ProductNumber2=30001&Quantity2=5&cartcmd=addmulti", false);

and change the cart.js from this (or probably better make an overload):

xhr.open('POST', url + command + "&feedtype=Counter");
xhr.onreadystatechange = function () {...};
xhr.send();

to this:
xhr.open('POST', url + "&feedtype=Counter");
xhr.onreadystatechange = function () {...};
xhr.send(command);

Code not tested - but the essense is there...

Sorry about the confusion and inconvenience.

Votes for this answer: 1
 
Gaëtan Di Caro
Reply

Thanks, that makes sense. I have tried to implement it and at first glance it seems to have worked :)

 
Gaëtan Di Caro
Reply

Ah I spoke too fast. The request is sent and I get a 302 (found) back, but nothing is added to the basket, even with a small amount of products

Url : /Default.aspx?ID=530&feedtype=Counter

Content :

ProductLoopCounter1=1&ProductNumber1=SR101110&Quantity1=1&ProductLoopCounter2=2&ProductNumber2=SR101111&Quantity2=2&ProductLoopCounter3=3&ProductNumber3=SR101210&Quantity3=4&ProductLoopCounter4=4&ProductNumber4=SR101211&Quantity4=6&cartcmd=addmulti

 
Nicolai Pedersen
Reply

Try adding redirect=true to the Url

 
Gaëtan Di Caro
Reply

Hmm no luck still. I tried to add it to either the url or the content, same problem

 
Nicolai Pedersen
Reply

Have you tried to just post the form?

 
Gaëtan Di Caro
Reply

I've tried to create a test form, this works :

<form action="/Default.aspx?ID=530&feedtype=Counter">
        <input type="text" name="ProductLoopCounter1" value="1" />
        <input type="text" name="ProductNumber1" value="SR101110" />
        <input type="text" name="Quantity1" value="1" />
        <br />
        <input type="text" name="ProductLoopCounter2" value="2" />
        <input type="text" name="ProductNumber2" value="SR101111" />
        <input type="text" name="Quantity2" value="1" />
        <br />
        <input type="text" name="ProductLoopCounter3" value="3" />
        <input type="text" name="ProductNumber3" value="SR101210" />
        <input type="text" name="Quantity3" value="1" />
        <br />
        <input type="text" name="ProductLoopCounter4" value="4" />
        <input type="text" name="ProductNumber4" value="SR101211" />
        <input type="text" name="Quantity4" value="1" />
        <br />
        <input type="text" name="cartcmd" value="addmulti" />
        <button type="submit" value="add"></button>
    </form>

 
Nicolai Pedersen
Reply

Then you just need to find the difference between the 2 posts - probably some formatting or something like that.

 
Gaëtan Di Caro
Reply

Ok I've got it now...

After opening the request you must do that, so that it interprets the data correctly :

        xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');

And not use redirect=true.

Now it seems like it's working well.

 
Nicolai Pedersen
Reply

Pew, long way to get it working!

Thanks for sharing the result!

BR Nicolai

 

You must be logged in to post in the forum