2

join 2 collection in custom Grid Magento.I am using the below code. I want to join with sales_flat_order to get get Shipping address & Grand Total. how to do ?

$customerId = $this->getRequest()->getParam('id');//customer Id
$collection = Mage::getModel('modulename/modelname')
    ->getCollection()
    ->addFieldToFilter('customer_id', $customerId);

1 Answer 1

3

Please try with this:

$collection
    ->getSelect()
    ->join(
        array('so' => $this->getTable('sales/order')),
        'main_table.order_id = so.entity_id',
        array('so.grand_total')
    )
    ->join(
        array('soa' => $this->getTable('sales/order_address')),
        "(main_table.order_id = soa.parent_id AND soa.address_type = 'shipping')",
        array('soa.*')
    );

replace order_id with the column name that you used in your table for the order ID.

Also you can view/read this - http://www.magentocommerce.com/wiki/1_-_installation_and_configuration/using_collections_in_magento .

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.