1

I have sales/order_grid_collection

where I'm getting the desired attributes on my grid, but the last one attribute I need is the billing street of the order, how can I get that programmatically?

Here is my code:

public function _prepareCollection()
{
    $collection = Mage::getResourceModel('sales/order_grid_collection')->addAttributeToSelect('*');

    $this->setCollection($collection);
    parent::_prepareCollection();
}

protected function _prepareColumns()
{
    $this->addColumn('real_order_id', array(
        'header' => $this->_getHelper()->__('#'),
        'width' => '80px',
        'type'  => 'text',
        'index' => 'increment_id'
    ));
    $this->addColumn('created_at', array(
        'header' => $this->_getHelper()->__('Date'),
        'index' => 'created_at',
        'type' => 'datetime',
        'width' => '100px'
    ));
    $this->addColumn('billing_name', array(
        'header' => $this->_getHelper()->__('Customer'),
        'index' => 'billing_name'
    ));
    // THIS IS THE ATTRIBUTE I NEED TO SHOW:
    $this->addColumn('billing_street', array(
        'header' => $this->_getHelper()->__('Address'),
        'index' => 'billing_street'
    ));
    //--------------------------------------------------
    $this->addColumn('status', array(
        'header' => $this->_getHelper()->__('Status'),
        'index' => 'status',
        'type'  => 'options',
        'width' => '70px',
        'options' => Mage::getSingleton('sales/order_config')->getStatuses()
    ));

    return parent::_prepareColumns();
}

Thanks in advance.

1 Answer 1

0

You need to join the table sales_flat_order_address, to get the billing information.

protected function _prepareCollection()
{
    $collection = Mage::getResourceModel($this->_getCollectionClass());
    $collection->getSelect()
                ->join(array('address' => $collection->getTable("sales/order_address")), 
                    'main_table.entity_id = address.parent_id AND address.address_type = "billing"'
                    )
                ->columns('address.street as billing_street');
    $this->setCollection($collection);
    return parent::_prepareCollection();
}
0

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.