Magento: getCollection() Method Discovery

Magento Icon

I was writing an order export module the other day, and I was needing to get some data from orders and found myself unable to get any customer information such as ->getCustomerEmail(). I was getting the order model collection with the following code:

$orders = Mage::getModel('sales/order')->getCollection();

I could have sworn that in some other context, I was able to get a bunch more information from the order model than what I was able to get from this. Then, with some help from the #magento channel on IRC, I realized that the getCollection() method seems to only return data from itself, and no other related models. It’s limited. If you just add a ‘*’ to the call, you’ll end up getting a lot more data, and I was able to then use getCustomerEmail().

$orders = Mage::getModel('sales/order')->getCollection('*');
This entry was posted in Magento. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">