KNKM
KNKM

Reputation: 169

Magento join two collections

I need to get data from:

$collection =  Mage::getResourceModel('sales/order_grid_collection')

Also I need to get the state column value from sales_flat_order table.

How to join these two and get data?

Upvotes: 0

Views: 6637

Answers (1)

Jonathan Hussey
Jonathan Hussey

Reputation: 1044

You need to add a join to the select object for the collection. In this case it's pretty straight forward as the 2 tables involved (sales_flat_order_grid and sales_flat_order) are very easily linked by the entity_id column common to both tables:

$collection = Mage::getResourceModel('sales/order_grid_collection');
$select = $collection->getSelect();
$resource = Mage::getSingleton('core/resource');

$select->join(
    array('order' => $resource->getTableName('sales/order')),
    'main_table.entity_id = order.entity_id',
    array('state')
);

Upvotes: 1

Related Questions