1

I want to show only first name in bill to and ship to magento order grid.

app/code/local/Mage/Sales/Model/Resource/Order.php

/**
     * Init virtual grid records for entity
     *
     * @return Mage_Sales_Model_Resource_Order
     */
    protected function _initVirtualGridColumns()
    {
        parent::_initVirtualGridColumns();
        $adapter       = $this->getReadConnection();
        $ifnullFirst   = $adapter->getIfNullSql('{{table}}.firstname', $adapter->quote(''));
        $ifnullMiddle  = $adapter->getIfNullSql('{{table}}.middlename', $adapter->quote(''));
        $ifnullLast    = $adapter->getIfNullSql('{{table}}.lastname', $adapter->quote(''));
        $concatAddress = $adapter->getConcatSql(array(
            $ifnullFirst,
            $adapter->quote(' '),
            $ifnullMiddle,
            $adapter->quote(' '),
            $ifnullLast
        ));
        $this->addVirtualGridColumn(
                'billing_name',
                'sales/order_address',
                array('billing_address_id' => 'entity_id'),
                $concatAddress
            )
            ->addVirtualGridColumn(
                'shipping_name',
                'sales/order_address',
                 array('shipping_address_id' => 'entity_id'),
                 $concatAddress
            );

        return $this;
    }

I tried with this function but no change.

0

You need to move Order Grid core file to local folder first

app\code\core\Mage\Adminhtml\Block\Sales\Order\Grid.php to app\code\local\Mage\Adminhtml\Block\Sales\Order\Grid.php

change _prepareCollection function as below

protected function _prepareCollection()
    {
         $collection = Mage::getResourceModel($this->_getCollectionClass());
        $resource = Mage::getSingleton('core/resource');
         $collection->getSelect()->join(
            array('billing' => $resource->getTableName('sales/order_address')),
            'main_table.entity_id = billing.parent_id',
            array('billing_firstname' => 'firstname')
        )->where("billing.address_type =  'billing'");

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

replace below column code

$this->addColumn('billing_name', array(
       'header' => Mage::helper('sales')->__('Bill to Name'),
       'index' => 'billing_name',
));

replace with below

$this->addColumn('billing_firstname', array(
    'header' => Mage::helper('sales')->__('Bill to Name'),
    'index' => 'billing_firstname',
));

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.