Remove items from cart after 30 minutes - Magento

Remove items from cart after 30 minutes - Magento

July 25, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Remove items from cart after 30 minutes - Magento

Automating Cart Abandonment for Magento

Managing abandoned carts is a critical aspect of e-commerce operations that often goes overlooked. As a Magento developer, you may find yourself tasked with automatically removing items from the cart after a certain period, regardless of whether the shopper is logged in or not. This blog post will guide you through implementing this functionality effectively.

The Current Challenge: Timeouts and Quote Lifetime

You’ve already attempted to solve this by adjusting the cookie session timeout to 1800 seconds (30 minutes). However, the issue lies with Magento’s quote lifetime setting, which is only adjustable in one-day increments. You’ve tried multiplying the lifetime value by 1800 instead of 86400 in your configuration, but unfortunately, this hasn’t resolved the problem.

Let’s break down why this approach didn’t work and explore a more robust solution.

Understanding Magento’s Quote Lifetime

Magento uses quotes to represent shopping carts. The quote lifetime determines when an abandoned cart is automatically deleted from the database. By default, this is set to one day (86400 seconds), which is why your adjustment to 1800 seconds wasn’t effective.

The checkout/cart/delete_quote_after configuration path you’re targeting controls this behavior across all stores in your Magento installation. However, this setting doesn’t directly influence the quote lifetime for individual quotes; it only specifies when abandoned carts are deleted during cron jobs.

A More Granular Approach: Adjusting Quote Lifetime Directly

Instead of relying on the global delete_quote_after configuration, we can adjust the quote lifetime at a more granular level. Magento provides an observer event that triggers when a quote is saved - sales_quote_save_after. We can use this event to set a custom expiration time for each individual quote.

Here’s how you can achieve this:

  1. Create an observer module in your Magento installation.
  2. Add the following configuration to your config.xml file:
<config>
    <global>
        <events>
            <sales_quote_save_after>
                <observers>
                    <your_module_model_observer>
                        <type>singleton</type>
                        <class>YourModule_Model_Observer</class>
                        <method>saveQuoteLifetime</method>
                    </your_module_model_observer>
                </observers>
            </sales_quote_save_after>
        </events>
    </global>
</config>

Replace your_module with the name of your module and YourModule_Model_Observer with the class that will handle the observer logic.

  1. Implement the saveQuoteLifetime method in your observer class:
public function saveQuoteLifetime($observer)
{
    $quote = $observer->getEvent()->getQuote();
    $quote->setExpirationDate(time() + 1800); // Set expiration time to 30 minutes from now
}

This code updates the expiration_date field of each quote to be exactly 30 minutes after the current timestamp. When this date is reached, Magento will automatically delete the abandoned cart.

Conclusion: Efficient Cart Management

Automating the removal of abandoned carts in Magento requires a deep understanding of the quote lifetime mechanism and the events that trigger quote updates. By utilizing the sales_quote_save_after event observer, you can set a custom expiration time for each individual quote, providing a more granular control over abandoned cart management.

Remember to test your implementation thoroughly across different scenarios, including both logged-in and guest shoppers. Regularly monitoring abandoned cart statistics will help you optimize this process and maximize the potential of your e-commerce platform.

For more in-depth Magento development insights and best practices, feel free to explore our blog at Laravel Company. We cover a wide range of topics to help you stay informed about the latest trends and techniques in web development.

Checkout Database Themes Configuration

Our network