2

I'm trying to add Billing Company and Shipping Company to the Sales Order Grid (Magento CE 1.9.0.1) but everything I have tried appears to have no effect - I don't even see the new column with empty data and there's nothing in the log to suggest what's wrong either. Wondered if someone might be able to help?

I'm duplicating this file: /app/code/core/Mage/Adminhtml/Block/Sales/order/Grid.php as /app/code/local/Mage/Adminhtml/Block/Sales/order/Grid.php and then modifying as follows;

(_prepareCollection and _prepareColumns stripped back to simply show the new code)

protected function _prepareCollection()
{
    $collection = Mage::getResourceModel($this->_getCollectionClass());

    //New line
    $collection->getSelect()->join('sales_flat_order_address', 'main_table.entity_id = sales_flat_order_address.parent_id' ,array('company'=> 'company' ));
    $collection->addFieldToFilter('sales_flat_order_address.address_type', array('eq' => 'billing'));

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

protected function _prepareColumns()
{

    [...]

    $this->addColumn('company', array(
        'header' => Mage::helper('sales')->__('Billing Company'),
        'index' => 'company',
    ));

    [...]
}
0

Try this

protected function _prepareCollection()
            {
                $collection = Mage::getResourceModel($this->_getCollectionClass());

                 $collection->getSelect()->join(array('billing'=>'sales_flat_order_address'),'main_table.entity_id=billing.parent_id and billing.address_type="billing"',array('*'));

                $collection->getSelect()->join(array('shipping'=>'sales_flat_order_address'),'main_table.entity_id=shipping.parent_id and shipping.address_type="shipping"',array('shipping.company as  shipping_company'));

                $this->setCollection($collection);

                 parent::_prepareCollection();
       return Mage_Adminhtml_Block_Widget_Grid::_prepareCollection();
            }

And add columns in _prepareColumns()

  $this->addColumn('company', array(
                'header' => Mage::helper('sales')->__(' Billing company'),
                'index' => 'company',
                'filter_index' => 'billing.company',
            ));
             $this->addColumn('shipping_company', array(
                'header' => Mage::helper('sales')->__(' Shipping company'),
                'index' => 'shipping_company',
                'filter_index' => 'shipping_company',
            ));
  • Thank you. It seems that this doesn't work either for me. :/ – doubleplusgood Jun 28 '16 at 14:31
  • did you used any extension – Magento 2 Jun 28 '16 at 14:35
  • Make sure you are editing correct file bcz it's working code – Magento 2 Jun 28 '16 at 14:35
  • I believe it is the correct file. I have also tried it on one other Magento site and I can't get it to work there either. :/ I also have caching disabled so the update should be visible right away. I have also disabled some modules that were using Mage_Adminhtml_Block_Sales_Order_Grid. – doubleplusgood Jun 28 '16 at 15:02
  • I now have the columns appearing and data pulled in. However, if I try to search in the shipping company it throws an error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'shipping_company' in 'where clause' – doubleplusgood Jul 1 '16 at 11:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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