Update multiple items with one AJAX call?

  • Posts: 22
  • Thank you received: 0
10 years 11 months ago #134988

Hi Nicholas,

Is it possible to update multiple items with a single ajax call?
This will update a single product:
www.demo.hikashop.com/index.php?option=c...kout=1&product_id=ZZ

My site let´s users configure a product , consisting of multiple products and when they are satisfied with the result, add it to the cart.
Much like a car configurator.
What the site then does, is loop through all the products they have selected and make a ajax call for each, adding all needed items to the cart.

This works, but it is a bit slow (need to make 8 ajax calls).
Is there any other way doing this with 1 call?

Please Log in or Create an account to join the conversation.

  • Posts: 82906
  • Thank you received: 13378
  • MODERATOR
10 years 11 months ago #135157

Hi,

You can do like that:

http://www.demo.hikashop.com/index.php?option=com_hikashop&ctrl=product&task=updatecart&data[ZZ]=YY&data[AA]=BB&checkout=1
That will add YY items of the product with the id ZZ and BB items of the product with the id AA in the cart at the same time.

Please Log in or Create an account to join the conversation.

  • Posts: 22
  • Thank you received: 0
10 years 11 months ago #135217

Super. Thank you :)

Please Log in or Create an account to join the conversation.

  • Posts: 22
  • Thank you received: 0
10 years 11 months ago #135321

Hi again Nicholas,
After doing some testing, I have found that this solution has a few issues.
I thought I would use this code to loop through the contents of the cart to delete all items present, before adding the new ones.
However setting the quantity to 0 does not seem to do the trick.

Another thing, if you add a product that is already in the cart, it will not add to the quantity field, but rather insert a new product in the cart. So you will have 2 identical products present in the cart.

If there is another way to simply empty the cart (ajax), please do let me know (apart from looping through and executing an ajax call for each item)

Please Log in or Create an account to join the conversation.

  • Posts: 22
  • Thank you received: 0
10 years 11 months ago #135370

I am guessing you have to get the 'cart Item ids' instead of the product ids for deleting them like this?

Please Log in or Create an account to join the conversation.

  • Posts: 22
  • Thank you received: 0
10 years 11 months ago #135373

SOLVED. (Using cart id´s will make this work)

Please Log in or Create an account to join the conversation.

Time to create page: 0.069 seconds
Powered by Kunena Forum