Developer forum

Forum » Ecommerce - Standard features » Add multiple products to Cart (Variants)

Add multiple products to Cart (Variants)

Nuno Aguiar
Reply

Hi,

 

I am trying to add multiple variants of a single product (each with it's quantity), but can't seem to get it to work

 

Any ideas where the problem is?

 

Here's the simplest example that is not working

/Default.aspx?ID=37&CartCmd=addMulti&UnitID1=&ProductLoopCounter1=1&ProductID1=PROD9&Quantity1=2&VariantID1=VO102.VO1

 

Best Regards,

Nuno


Replies

 
Nuno Aguiar
Reply

Anyone? I would really appreciate some help

 

Nuno

 
Morten Bengtson
Reply

Have you tried using the same input parameters in a form (with method="post") instead of using a link?

 
Nuno Aguiar
Reply

Hi Morten,

 

It was actually by post in an ajax call.

 

We then tried it as a link, thinking there was some problem with the ajax session, but with the same result: nothing added to the cart.

 

Can you reproduce the error?

 

Best Regards,

Nuno

 
Anders Ebdrup
Reply

Hi Nuno,

 

Can you please try to post your javascript as I think it should work when making a post to the page?

 

Best regards, Anders

 
Nuno Aguiar
Reply

Hi Anders,

 

Maybe it's just a tiny thing, but we are missing it.

 

$("#addToCartContainer").submit(function (event) {
  event.preventDefault();

  $.ajax({
    type:"POST",
    url:"/Default.aspx?ID=37&CartCmd=addMulti&UnitID1=&ProductLoopCounter1=1&ProductID1=PROD7&Quantity1=5&VariantID1=VO102.VO1&UnitID2=&ProductLoopCounter2=2&ProductID2=PROD7&Quantity2=7&VariantID2=VO103.VO1 ",
    headers:{
      "Pragma":"no-cache",
      "Cache-Control":"no-store, no-cache, must-revalidate, post-check=0, pre-check=0",
      "Expires":0,
      "Last-Modified":new Date(),
      "If-Modified-Since":new Date()
    },
    cache:false,
    dataType:'html',
    success:function (str_data) {
      // success
    }
  });

});

 

Best Regards,

Nuno

 
Anders Ebdrup
Reply

Hi Nuno,

 

Try posting the parameters instead of having them in the url. The data for the post should be in "data"-parameter for jquery.

 

See this example:

$('.js-basket-add').submit(function (e)
            var input = $(this).serialize();
            $.ajax(
            {
                url: "Default.aspx?id=1",
                type: "POST",
                data: input,
                dataType: "html",
                cache: false,
                traditional: true,
                beforeSend: function () { startLoading(); },
                complete: function (jqXHR, status) { endLoading(true); },
                success: function (data, textStatus, jqXHR) {

                },

                error: function (jqXHR, textStatus, errorThrown) {
                    console.log(jqXHR);
                    console.log(textStatus);
                    console.log(errorThrown);
                }
            });
            return false;
        }
    });

Best regards, Anders

 
Nuno Aguiar
Reply

Hi Anders,

 

D'OH!

When I look back to see Morten's email. We must have set something wrong.

 

Working perfect now, thanks.

 

Nuno

 

You must be logged in to post in the forum