[Skip to main content](#vessel-content)

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

##

- **[PeterChain](/forum/user/570-peterchain "View PeterChain's Profile")**
- [![PeterChain's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar570.png)](/forum/user/570-peterchain "View PeterChain's Profile") Topic Author
- [ Offline](/forum/user/570-peterchain)

Less More

- Posts: 640
- Thank you received: 16
-
-

2 years 10 months ago [\#358301](#358301) by [PeterChain](/forum/user/570-peterchain "View PeterChain's Profile")  *[Cart for a certain user gets deleted and a new cart is created](/forum/35-orders-management/907598-cart-for-a-certain-user-gets-deleted-and-a-new-cart-is-created#358301 "-- HikaShop version -- : HikaShop Business 4.3.0 &#91;2006081059&#93; -- 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&#95;Id&#95;number XX and now has a differnt cart&#95;id&#95;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.")* was created by *[PeterChain](/forum/user/570-peterchain "View PeterChain's Profile")*

-- 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](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzM1LW9yZGVycy1tYW5hZ2VtZW50LzkwNzU5OC1jYXJ0LWZvci1hLWNlcnRhaW4tdXNlci1nZXRzLWRlbGV0ZWQtYW5kLWEtbmV3LWNhcnQtaXMtY3JlYXRlZD90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86584
- Thank you received: 14325
-
-

2 years 10 months ago [\#358309](#358309) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Cart for a certain user gets deleted and a new cart is created](/forum/35-orders-management/907598-cart-for-a-certain-user-gets-deleted-and-a-new-cart-is-created#358309 "-- HikaShop version -- : HikaShop Business 4.3.0 &#91;2006081059&#93; -- 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&#95;Id&#95;number XX and now has a differnt cart&#95;id&#95;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.")*

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&gt;Carts menu in the backend, but that's out of the scope of what you're describing.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzM1LW9yZGVycy1tYW5hZ2VtZW50LzkwNzU5OC1jYXJ0LWZvci1hLWNlcnRhaW4tdXNlci1nZXRzLWRlbGV0ZWQtYW5kLWEtbmV3LWNhcnQtaXMtY3JlYXRlZD90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[PeterChain](/forum/user/570-peterchain "View PeterChain's Profile")**
- [![PeterChain's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar570.png)](/forum/user/570-peterchain "View PeterChain's Profile") Topic Author
- [ Offline](/forum/user/570-peterchain)

Less More

- Posts: 640
- Thank you received: 16
-
-

2 years 10 months ago [\#358317](#358317) by [PeterChain](/forum/user/570-peterchain "View PeterChain's Profile")  Replied by *[PeterChain](/forum/user/570-peterchain "View PeterChain's Profile")* on topic *[Cart for a certain user gets deleted and a new cart is created](/forum/35-orders-management/907598-cart-for-a-certain-user-gets-deleted-and-a-new-cart-is-created#358317 "-- HikaShop version -- : HikaShop Business 4.3.0 &#91;2006081059&#93; -- 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&#95;Id&#95;number XX and now has a differnt cart&#95;id&#95;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.")*

Thank you very much for your answer.

I think this may explain the situation we are facing.

Best regards,

Peter

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzM1LW9yZGVycy1tYW5hZ2VtZW50LzkwNzU5OC1jYXJ0LWZvci1hLWNlcnRhaW4tdXNlci1nZXRzLWRlbGV0ZWQtYW5kLWEtbmV3LWNhcnQtaXMtY3JlYXRlZD90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[PeterChain](/forum/user/570-peterchain "View PeterChain's Profile")**
- [![PeterChain's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar570.png)](/forum/user/570-peterchain "View PeterChain's Profile") Topic Author
- [ Offline](/forum/user/570-peterchain)

Less More

- Posts: 640
- Thank you received: 16
-
-

2 years 10 months ago [\#358336](#358336) by [PeterChain](/forum/user/570-peterchain "View PeterChain's Profile")  Replied by *[PeterChain](/forum/user/570-peterchain "View PeterChain's Profile")* on topic *[Cart for a certain user gets deleted and a new cart is created](/forum/35-orders-management/907598-cart-for-a-certain-user-gets-deleted-and-a-new-cart-is-created#358336 "-- HikaShop version -- : HikaShop Business 4.3.0 &#91;2006081059&#93; -- 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&#95;Id&#95;number XX and now has a differnt cart&#95;id&#95;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.")*

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-&gt;to-&gt;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](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzM1LW9yZGVycy1tYW5hZ2VtZW50LzkwNzU5OC1jYXJ0LWZvci1hLWNlcnRhaW4tdXNlci1nZXRzLWRlbGV0ZWQtYW5kLWEtbmV3LWNhcnQtaXMtY3JlYXRlZD90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86584
- Thank you received: 14325
-
-

2 years 10 months ago [\#358342](#358342) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Cart for a certain user gets deleted and a new cart is created](/forum/35-orders-management/907598-cart-for-a-certain-user-gets-deleted-and-a-new-cart-is-created#358342 "-- HikaShop version -- : HikaShop Business 4.3.0 &#91;2006081059&#93; -- 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&#95;Id&#95;number XX and now has a differnt cart&#95;id&#95;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.")*

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(&amp;$products, &amp;$cart, &amp;$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: Code:

$cartClass = hikashop_get('class.cart'); $cartClass-&gt;addMessage($cart, array('msg' =&gt; implode('&lt;br/&gt;', $messages), 'product_id' =&gt; $id, 'type' =&gt; '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](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzM1LW9yZGVycy1tYW5hZ2VtZW50LzkwNzU5OC1jYXJ0LWZvci1hLWNlcnRhaW4tdXNlci1nZXRzLWRlbGV0ZWQtYW5kLWEtbmV3LWNhcnQtaXMtY3JlYXRlZD90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

Board Categories HikaShop Install &amp; Update Product &amp; Category Display Content Creation Sales and Orders Orders management Reports &amp; Statistics Customers Checkout Payment Methods Shipping Methods Import &amp; Export (CSV, XLS…) Specific Features Affilation Taxes Wishlist Vote Carousel &amp; Slider Mass Actions Filters &amp; Search Discount &amp; Coupon Feature Request Integrations Showcase General Talk about HikaShop Development HikaShop 3.0 Beta Translation Commercial Jobs HikaShop Components HikaMarket Market: Feature requests Market: How to? Market: Bug Report HikaSerial General talk about HikaSerial Serial: Bug Report Serial: How to? Support en Français de HikaSerial (French Support) HikaSubscription HikaAuction Auction: Feature requests Auction: How to? Auction: Bug report Hikashop around the world Support en Français (French Support) Russian FAQ. Курс выживания с Hikashop. Частые вопросы и о Расширения Hikashop Наши сайты на Hikashop 日本語版サポート(Japanese Support) Thai German Archives Bug Report How to?

[](/forum/topics/feed/mode-topics?format=feed&type=rss)

Time to create page: 0.069 seconds

[Powered by](/forum/credits) [Kunena Forum](https://www.kunena.org)
