Magento Tips: How To Clear Magento Shopping Carts

February 4, 2013 Aleksander Tretjak Tips&Tricks
Magento Tips: How To Clear Magento Shopping Carts

One of the problems that Magento-based online store owners may encounter is that the shopping cart may not get emptied when the customer leaves the store. So the next time the user logs back into the system, the new items get merged with the old ones.

The thing is that the default Magento Quote Lifetime settings allow only to limit the period of time a unit can remain in the shopping cart. Unfortunately, there are no settings which would clear the cart when a need someone write my paper customer abandons the page or logs out of the store.

This may seem quite a beneficial ‘feature’ in terms of sales but still can be quite annoying for customers.

To solve this, some users create their own Magento extension which would listen for the log out event and remove all cart contents. But the problem here is that this method works only if customers manually log out, if they are logged out due to a session time out all the cart contents remain.

So one of the workarounds here would be trying not to customize the logout settings, but, instead, clear the previous items from cart when the customer logs back into the system – an observer on customer login event can do the task.



6 comments

  1. Recently I had this issue, as presence of these quotes in the DB drops down drastically the backend performance. After I looked here and there I made a conclusion that the only correct and viable way to clean them is with custom extension and a cron job which cleans old active quotes last modified before x days. X might be different for customer quotes and guest quotes.
    The main issues with your proposed way are:
    1) There are customers who build their shopping carts in more than one step and they can use more than one login until they decide what to buy. Thus cleaning their existing content is terrible. Do you agree?
    2) Observing only customer events does not allow you to clean guest quotes and they are much more than those for registered customers and thus we are doing only part of the job.
    3) And last but not least observer on customer login event simply does not work as if on the checkout page the customer selects to place his/her order as registered customer an immediate login action is performed and all login events are fired, which will result in cleaning his current quote. One possible solution to this is to observe load_customer_quote_before instead but still we have the same issue on the checkout.

  2. Hi,
    We are experiencing similar problems but the customers are seeing the same products in their basket from their latest purchase – even though it has completed. Our developers tell me that it’s a problem with persistent basket. From Aleksander’s post I can see how this works with abandoned carts but should it really be an issue with carts even when the transaction was completed several weeks ago?
    The customer called to pay by phone in the end because she reports that she wasn’t able to add the product she wants or remove the ‘old’ products.

  3. Milen,

    There can be several reasons for this problem:

    1. Cron has not been properly set up
    2. Incorrect cart settings in the admin panel
    3. Perhaps, there is some module which interferes into the logic of cart clearance

    But to say for sure it is necessary to check the system itself.

  4. Hello Mister Tretjak

    Thank you for explaning this point! I’m happy to find an explanation to this ‘old shopping cart content’
    I don’t have the skills to see an solution.
    Could you help me with a hint or a solution
    Consider this as an job offer!

    Kind regards
    Anis

  5. Remove all products from shopping cart in magento:

    Double click below to select all codes

    $cart = Mage::getSingleton(‘checkout/cart’);
    foreach( Mage::getSingleton(‘checkout/session’)->getQuote()->getItemsCollection() as $item ){
    $cart->removeItem( $item->getId() );
    }
    $cart->save();

    This code helps me to remove items from Magento shopping cart

  6. I have fatal error when login after changing products. So now I always clean all users carts after add\edit products in admin. It needs just to clear table:

    sales_flat_quote

Post a new comment

top
BelVG Newsletter
Subscribe to our mailing list and get interesting stuff and updates to your email inbox.
Email *