Cart for a certain user gets deleted and a new cart is created

  • Posts: 636
  • Thank you received: 16
11 months 1 week ago #358301

-- HikaShop version -- : HikaShop Business 4.3.0 [2006081059]
-- Joomla version -- : 3.9.x
-- PHP version -- : 7.3

It happened several times lately.

A user is adding items to its cart as usual and suddenly he gets out of the session, then when relogining that cart does not exist anymore and he has a new empty cart.

When checking in DB backups that we make every ten minutes, we see that he had a cart_Id_number XX and now has a differnt cart_id_number YY, so it seems that some process we don't control is destroying the old cart and creating a new one for that user.

We need to know in which scenarios this can happen.

Since the beginning of the project the cart is set to 200 weeks expiration.

We don't see what and where can cause this unsolicited CART deletion and replacement.

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

  • Posts: 83024
  • Thank you received: 13403
  • MODERATOR
11 months 1 week ago #358309

Bonjour,

If a logged in user has products in his cart and then logs out (or is logged out because the session expires), if he adds something to his , now empty, cart as a guest and then logs in, the new cart will take over the old cart. If you have the "enable multiple cart" setting turned on, then both carts will be linked to his user account. But if that setting is turned off, then the new cart he had during his guest session will replace the old cart he had while logged in.
I would suppose that it's probably what's going on.

Note that HikaShop doesn't normally create empty carts. Normally, a cart is created because the user clicked on the "add to cart" button of a product and he doesn't already have a cart linked to his current session.
There are ways to create empty carts, like if you click on the "new" button of the Customers>Carts menu in the backend, but that's out of the scope of what you're describing.

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

  • Posts: 636
  • Thank you received: 16
11 months 1 week ago #358317

Thank you very much for your answer.

I think this may explain the situation we are facing.

Best regards,

Peter

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

  • Posts: 636
  • Thank you received: 16
11 months 1 week ago #358336

We have built a sophisticated way to handle orders in the backend, so we suspect MULTIPLE CART = TRUE could behave wrong with our solution.

What ways are avaiable to prevent Frontend Guest Mode from being able to handle and store product->to->cart submits and therefore we can stay with MULTIPLE CARTS = FALSE coniguration ?

What we would like to get is that on clicking Add to cart, if the user is logged out (unadvertedly) the system does not try not even try to store the product in the cart, and if so, blocks the process so the loss of former logged cart is not happening.

I understand we can intercept the Add to cart button process and check for the user sessions to be still alive, but maybe there is a cleaner more elegant way already available.

thank you.

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

  • Posts: 83024
  • Thank you received: 13403
  • MODERATOR
11 months 1 week ago #358342

Hi,

There is nothing ready-made to do that.
One simple solution is to make view overrides of where add to cart buttons are displayed (in product / quantity and in product / add_to_cart_ajax ). There, you can check if the user is logged in or not and if not, change the "onclick" of the button and the fallback_url to, for example, redirect to the login form with an appropriate message.
That's quite lightweight as a solution. The biggest flaw here is that the user session might expire between the time it displays the page on his browser and the time he clicks on the button, circumventing this check.

A more complex, but more elegant solution, would be to implement the onBeforeProductQuantityCheck(&$products, &$cart, &$options) event in a custom plugin. In it, you can check if the user is logged in, and if not, you can set the "qty" to 0 in the products in the $products array and add a messsage like so:

			$cartClass = hikashop_get('class.cart');
			$cartClass->addMessage($cart, array('msg' => implode('<br/>', $messages), 'product_id' => $id, 'type' => 'error'));
We're using the same principle in the cart reservation plugin available on our marketplace in order to block users from add products to their cart if others already have the last elements of the stock in their cart.

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

Time to create page: 0.076 seconds
Powered by Kunena Forum