Jump to content

Add product to cart failing sometimes - Need help


stennnn

Recommended Posts

Hello guys,

I am currently facing an issue with my website when I try to add the products to cart, sometimes it works, sometimes it simply doesn't. Ajax pop-up opens up everytime you click on "Add to cart" but sometimes it shows as follow:

erro1.thumb.jpg.c592f13f32dd9ea4473c2be7527708f6.jpg

 

Even though it shows 0 and no product information, when I check my backoffice the product is added to a cart and it is not displayed to the customer on the frontpage (shows as empty card):

image.thumb.png.4f60c51828e707daa7588aff9ad14316.png

 

The thing about this error is that I know the reason why it happens but I cannot find the way to sort it out properly. For some reason, and if you notice on the image above, Prestashop automatically linked the new cart from a customer created to an order ID on the left side. If I open the cart information to check it, it attached the cart to an order made previously like 2 years ago, as seen here:

image.thumb.png.dc07c6743963ecfc54566f9619da6d78.png

I am aware that if I delete all the database order history, that might solve it but I don't want to delete the order history. Does anyone knows what is going on or can pinpoint towards the file I need to make some changes or be looking at?

Website link is https://top-garden.net

Please be aware that add to cart sometimes work, sometimes doesn't. If possible, test the website in several browsers with different caches.

What I have done so far:

- Debug mode shows no error at all, I have fixed all errors that appear there;

 - Disabled all overrides and all non-native modules;

- Deleted all caches several times;

- Console shows no error at all;

- Changed from PHP 7.4 back to 7.3 just in case;

- Checked the geolocation settings common in other cases;

- Removed cart module and installed it fresh;

- changed the database settings of the id_cart and id_order from INT to BIGINT just in case due to orders going over 10k (just in case this change);

- Turned development mode on on Cloudfare;

- Changed to catalogue mode and replaced it.

Could this be a cache issue? I currently instaured LiteSpeedWebCache Entreprise on the server and running LiteSpeedCache module but since I have disabled it manually, cleaned caches and I still got the error on the cart I am guessing it has nothing to do with it.

Cheers

Edited by stennnn
completing information (see edit history)
Link to comment
Share on other sites

***** SOLVED ******

Managed to fix the issue a few hours ago. Just in case anyone ever needs a fix for a situation such as this in the future:

Being waken up fresh I have noticed that I had a wierd Log (Advanced Parameters -> Logs) being generated for the carts that were being attached to the old order IDs. The log was the following - 

Frontcontroller::init - Cart cannot be loaded or an order has already been placed using this cart

I instantly thought this could be a unsynchronization of the tables in DB of the tables - ps_cart and ps_orders, which I had changed yesterday from INT to BIGINT. 

Looked up online and found the solution to my problem on Stackoverflow thanks to Dmitry Sheiko:

Quote

In your case "Frontcontroller::init - Cart cannot be loaded or an order has already been placed using this cart" most likely triggered because the condition in PaymentModule::validateOrder is false. It can as well happen in the FrontController.

Anyways it comes from Cart::orderExists method. The reason cart is considered as existing can be unsynchronization of ps_cart and ps_orders tables. Try the following: run in mysql the following queries:

SELECT id_cart FROM ps_cart ORDER by id_cart DESC LIMIT 1; SELECT id_cart FROM ps_orders ORDER by id_cart DESC LIMIT 1;

To me the first was giving 345 while the second 1891, meaning AUTOINCREMENT value for ps_cart was set less then existing id_cart values in ps_orders. What makes a newly created cart quite a candidate to exist already in ps_orders.

So I simply increased the value of AUTOINCREMENT:

ALTER TABLE ps_cart AUTO_INCREMENT = 2000;

and it fixed the issue to me.

In my case I had 286 on the first query and 23758 on the second query so I changed the AUTO_INCREMENT to 30000 instead of 2000 and fixed the issue!

  • Like 1
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...