Jump to content

Ajax add to cart forgetting other items already in cart


Recommended Posts

I've got PS 1.5 with a custom theme and I want it like the demo store where when you click "add to shopping bag" it doesn't advance to the next page but rather stays on the current page and adds it to your cart in an ajax manner.


I noticed that the ajax-cart.js file wants to apply the hooks to the body only if it has the ID #product, for some reason mine does not so I just removed this requirement and the Jquery hooks get attached correctly.


Whilst it will hit the server and add the item to the cart and refresh the cart without going to another page, I noticed that it forgets whatever is currently in the cart and creates a new one for you (checked this via the admin, a new cart gets created).


it's like the server side is forgetting the cart, and creating a new one but I don't know why. If I flick to the default theme the same thing happens. Any pointers?

Link to comment
Share on other sites

1. Undo any code modifications you did

2. Goto Modules > Front Office Features > Cart Block, and make sure Ajax cart is enabled

3. Goto Preferences > Themes, select the Default theme and confirm Ajax cart is working as intended.

4. Now select your custom theme. If Ajax cart is now not working then the theme is incompatible - contact the theme maker..

Edited by Holspeed (see edit history)
Link to comment
Share on other sites

Yep default theme it works fine.


Any pointers as to what the cause may be? I'm a developer, so I can debug this however not sure where to begin with this issue.


EDIT: all of a sudden it started working on my custom theme, then just now it stopped working again on my custom theme AND the default theme.


Looks like it's not an issue with the custom theme but PrestaShop in general?


EDIT 2: seems to be the same issue as http://www.prestashop.com/forums/topic/207984-cart-forgets-products-added-to-it/ however I already don't have www. in my SEO configuration it's just "dev.sitename.com"


Now my cart is forgotten as soon as I navigate to another page, not just when adding to it. grrrrrr!!!!!

Edited by seesomethingelse (see edit history)
Link to comment
Share on other sites

  • 2 months later...

I think I am too late but here it goes:



Delete/Comment the following lines from file (/classes/shop/Shop.php)

// Optimization - don't redirect and allow WS and other script to work

//if (!$id_shop)

//$id_shop = Configuration::get('PS_SHOP_DEFAULT');



The problem occurs whenever you access your shop using any other web address which is different from what you have set as shop domain in your configuration. For ex., your shop domain url configured is www.creatingideas.co.in while you access your site using http://creatingideas.co.in ..... Cookie management fails at this place which clean up your cart whenever you reload your page or you goto your cart/checkout page.


Hope it helps and will help a lot many others facing this issue.


Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...