The goal is to get all the quotes for a given customer (considering id, email, whatever).

But this quotes collection seems to work differently from those of customers and products.

First attempt: getCollection

$quote_collection = Mage::getModel('sales/quote')->getCollection()
  ->addFieldToFilter('customer_id', $customer->getId())
  //or //addFieldToFilter('customer_email', $customer->getEmail())

Gives a frustrating (even by filtering on created_at)

Allowed memory size of 268435456 bytes exhausted ...

To avoid messing around with server's memory, tried appending


Which gives the error

Call to undefined method Mage_Sales_Model_Resource_Quote_Collection::limit()

Deserately, try to limit to only one result, using getFirstItem: it works perfectly and the code is now

$quote_collection = Mage::getModel('sales/quote')->getCollection()
  ->addFieldToFilter('customer_id', $customer->getId())
  ->getFirstItem(); //->limit(10);

Too well in fact, since I do not want only one quote but all of them.

Second attempt: getSelect

$quote_collection = Mage::getModel('sales/quote')->getCollection()

The sql is exatly what I want:

SELECT `main_table`.*
FROM `sales_flat_quote` AS `main_table`
WHERE ((customer_id=136))

Which gives 8 lines on the Magento sample data, for customer 136.

But I do not know a way to get the results from this query (not even that), since

$quote_collection = Mage::getModel('sales/quote')->getCollection()

Results in a error report telling:

Unrecognized method 'getItems()'

Any suggestion? TIA!

EDIT: Finally, the first part was nearlyy right, my memory issues were caused by some var_dump :)

The working code is

$quote_collection = Mage::getModel('sales/quote')->getCollection()
  ->addFieldToFilter('customer_id', $customer->getId());
foreach($quote_collection as $key => $quote)
  Mage::log('quote '.$quote_data['entity_id'].')
  Mage::log('  created at '.$quote_data['created_at']);
  if($quote_data['is_active']) {
    Mage::log('  is active');
  Mage::log('  $'.$quote_data['grand_total']);

1 Answer 1

    $quote_collection = Mage::getResourceModel('sales/quote_collection')
        ->addFieldToFilter('customer_id', 5);
    foreach ($quote_collection as $quote) {
        $data = $quote->getData();

Or if you know which field you need, for example Subtotal:

$subtotal = $quote->getSubtotal();
  • Unfortunately, this foreach does not loop the collection. Here is the print_r of the $quote_collection for customer 136: pastebin.com/gG7myfrk Commented Jul 29, 2015 at 9:46
  • About your edit of 11h51 (GMT), got exactly what I am describing in "first attempt": PHP Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 58285416 bytes) Commented Jul 29, 2015 at 12:00
  • Did you manage to check the size of sales_flat_quote table? 500Mb from sample data seems to be huge.
    – eetzen
    Commented Jul 29, 2015 at 13:23
  • The table sales_flat_quote has 408 lines, total weighting 192,0 Kio ; I think this is a memory leak but cannot figure it out. Commented Jul 29, 2015 at 13:31
  • Many thanks, your first answer was good, my PHP skills were in cause. Now, hoping that table never go too big! :) Commented Jul 29, 2015 at 14:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.