How to get cart items by customer id/email at the admin side in Magento?

How to get cart items by customer id/email at the admin side in Magento?

August 11, 2026 · Illustrated author avatarBy Stefan Bogdanescu
How to get cart items by customer id/email at the admin side in Magento?

Retrieving Customer Cart Items in Magento Admin

As an experienced developer, I understand the challenge you’re facing in retrieving customer cart items from the admin side of your Magento store. You want to display a grid containing all unordered cart products for a specific customer or group of customers.

Understanding Your Current Approach

You’ve attempted to load the customer by email and then retrieve their associated quote using Mage::getModel('sales/quote')->loadByCustomer(). This method should technically work, but it seems you’re not getting the expected results. Let’s troubleshoot this issue step-by-step.

Debugging Your Current Code

The first thing to notice is that your code appears to be mixing Magento 1 and Magento 2 syntax. For example, in Magento 2, Mage::getModel() is replaced by \Magento\Framework\AppObjectManager::getInstance()->create(). This could potentially cause conflicts or unexpected behavior.

Moreover, you’re using the setSharedStoreIds method, which was deprecated in Magento 1 and removed entirely in Magento 2. If you’re using Magento 2, this line of code will not work as intended:

$quote->setSharedStoreIds($storeIds);

Instead, you should use the getCustomerId() or loadByCustomer() methods directly on the quote model.

Retrieving Customer Cart Items in Magento 2

Given that your current setup seems to be using a mix of Magento versions, I’ll provide guidance based on Magento 2 best practices. Here’s how you can retrieve customer cart items:

$customerEmail = 'rasd@gmail.com';
$quoteModel = \Magento\Framework\AppObjectManager::getInstance()->create('Magento\Sales\Model\Quote');
$quoteId = $quoteModel->loadByCustomer($customerEmail)->getId();

if ($quoteId) {
    $quoteItemModel = \Magento\Framework\AppObjectManager::getInstance()->create('Magento\Quote\Model\Quote\Item');
    $collection = $quoteItemModel->getCollection()->addFieldToFilter('quote_id', $quoteId);
    
    if ($collection->count() > 0) {
        foreach ($collection as $item) {
            print_r($item->getData());
        }
    } else {
        echo "No items found for this customer.";
    }
}

This code first loads the quote by customer email using loadByCustomer(), then retrieves its ID. It then creates a new item collection and filters it by the quote ID.

Incorporating This into Your Admin Grid

To display these cart items in a grid on your admin side, you would typically create a custom module and extend an existing block or controller to add this functionality. You can follow the official Magento devdocs guide for creating a custom grid: https://developer.adobe.com/commerce/devdocs/extension-dev-guide/components/grids/overview.html

Remember to clear your cache after making changes in your admin configuration.

Troubleshooting Tips

If you’re still experiencing issues, here are some additional troubleshooting steps:

  1. Ensure that the customer email exists and is associated with a quote.
  2. Double-check your code for syntax errors or missing brackets.
  3. Enable Magento’s default logging to help identify any underlying issues.
  4. Review your system.log file for any related error messages.

Conclusion

Retrieving customer cart items in the admin side of your Magento store requires a combination of loading the correct models and creating collections with appropriate filters. By using the loadByCustomer method on the quote model and filtering by quote ID, you can efficiently retrieve the desired data for a specific customer or group of customers.

Remember to adapt this code to your specific version of Magento (1.x or 2.x) and review any dependencies or compatibility issues accordingly.

For more in-depth guidance on customizing your Magento admin experience, I recommend checking out our comprehensive guides at Laravel Company.

Magento 2 Magento 1 Checkout Catalog

Our network