0

I have a virtual product. I know that doesn't have shipping details and hence in sales->order grid, Ship To Name column is blank but in those cases, I want to add a custom text. How can we achieve that in magento 1.9.2.2?

2 Answers 2

0

Look into the file app/design/adminhtml/default/default/template/widget/grid.phtml
Follow the lines of code added to add your custom message for the column 'Ship To Name' incase of virtual product.enter image description here Hope this will help the needy one!
If someone gets something better, please post!

3
  • this solves you problem but it's a bad way of coding it. You are editing a template that is used by all the grids. Not a good idea.
    – Marius
    Jan 11, 2017 at 8:51
  • @Marius Can you suggest something please Jan 11, 2017 at 9:06
  • I'm searching now.
    – Marius
    Jan 11, 2017 at 9:07
0

you can rewrite the class and change the column configuration to include a default value.

By default the grid column looks like this

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

you can make it look like this

$this->addColumn('shipping_name', array(
    'header' => Mage::helper('sales')->__('Ship to Name'),
    'index' => 'shipping_name',
    'default' => Mage::helper('sales')->__('Your default text here')
));

[EDIT]

An alternative would be to rewrite the grid class and implement the method _afterLoadCollection.
This is called after the collection that needs to be displayed is loaded. So you will only be affecting the items to be displayed.

you can make the method like this

protected function _afterLoadCollection()
{
    foreach ($this->getCollection() as $item) {
        if (empty(trim($item->getShippingName()))) {
            $item->setShippingName(Mage::helper('sales')->__('Your default text here'))
        }
    }
    return parent::_afterLoadCollection();
}

this way you change only your grid and do not affect all the grids.

2
  • I agree to your way too but this is not helping in my case. I checked, Shipping name coming as 2 spaces for virtual product thereby default not working there. Any suggestion/idea about the issue Jan 11, 2017 at 10:59
  • @AnuragKhandelwal See my edit.
    – Marius
    Jan 11, 2017 at 11:42

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.