Get all abandoned carts in Magento

Get all abandoned carts in Magento

October 8, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Get all abandoned carts in Magento

Fetching Abandoned Carts in Magento

When it comes to e-commerce platforms like Magento, abandoned carts are a significant concern for online retailers. These are carts that customers have added items to but haven’t completed the purchase. Understanding how to identify and retrieve these abandoned carts programmatically is crucial for effective customer engagement strategies.

What Constitutes an Abandoned Cart?

Before diving into the code, let’s clarify what Magento considers as being abandoned. By default, Magento defines a cart as abandoned if it hasn’t been updated in 6 hours (this can be configured). An update could be adding or removing products from the cart, which resets the abandonment timer.

Getting Abandoned Carts

The sales_order_grid_collection model is your gateway to retrieve abandoned carts. This collection holds all the orders, including those that haven’t been converted yet (meaning they are still in a quote state).

Here’s an example of how you can fetch all abandoned quotes:

<?php
require_once 'app/Mage.php';
Mage::init();

$quoteCollection = Mage::getModel('sales/quote')->getCollection()
    ->addFieldToFilter('is_active', 1)
    ->addFieldToFilter('status', array('eq' => Mage_Sales_Model_Quote::STATUS_REAL))
    ->setPageSize(50)
    ->load();

$abandonedCarts = array();
foreach ($quoteCollection as $quote) {
    // Check if the quote was updated more than 6 hours ago
    if (time() - strtotime($quote->getUpdatedAt()) > 21600) {
        $abandonedCarts[] = array(
            'id' => $quote->getId(),
            'customer_email' => $quote->getCustomerEmail()
        );
    }
}
?>

In this script, we first initialize the Magento application and then create a new quote collection. We filter to include only active quotes that are in the real state (not aborted). The setPageSize method is used for pagination purposes.

The foreach loop iterates through each quote. For every quote updated more than 6 hours ago, we add it to our $abandonedCarts array along with its ID and customer’s email address.

Configuring Magento

Remember, the abandonment threshold of 6 hours is a default setting. You can configure this based on your business requirements by editing the sales_order_grid_collection model or using configuration settings in the admin panel under Sales > Configuration > Cart.

Engaging Abandoned Carts

Once you have retrieved these abandoned carts, there are multiple strategies you could employ:

  • Send Reminder Emails: You can send automated reminder emails to encourage customers to complete their purchases. Be sure to comply with all relevant privacy and data protection regulations.
  • Offer Incentives: Consider offering special discounts or promotions to entice the customer back.

For more advanced techniques like using the Quote API for real-time updates or integrating this functionality into a Laravel application, I would recommend checking out our in-depth guides on LaravelCompany.

Conclusion

Retrieving abandoned carts is a vital aspect of e-commerce management. By understanding Magento’s default behavior and using the appropriate models like sales_order_grid_collection, you can effectively identify these lost opportunities.

Remember, the key lies in striking the right balance between reminders and incentives without overwhelming your customers with intrusive marketing.

Checkout Catalog Admin Configuration

Our network