0

I am try to add columns in Admin > sales >order by overriding method.

Copied

app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php

to

app/code/local/Mage/Adminhtml/Block/Sales/Order/Grid.php

& using Renderer, created Renderer at

app/code/local/Mage/Adminhtml/Block/Sales/Order/Renderer/Productsname.php

but getting some product repeating like in the image I add following code in Grid.php to protected function _prepareColumns()

$this->addColumn('name', array(
        'header' => Mage::helper('sales')->__('NAME'),
        'index' => 'productname',
        'type' => 'text',
        'renderer' => 'Mage_Adminhtml_Block_Sales_Order_Renderer_Productsname',
    ));

& following code in Productsname.php

    <?php
class Mage_Adminhtml_Block_Sales_Order_Renderer_Productsname extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
{
    public function render(Varien_Object $row)
    {                    
        $order=Mage::getModel('sales/order')->load($row->getData('entity_id'));              
        $str="";

        foreach($order->getAllItems() as $_item){                      
            $str .= $_item->getname()."<br>";
    }       
        unset($order);
        return $str;
    }
}
?>

enter image description here

  • Any grouped, configurable or bundle products involved? – Jonathan Hussey Nov 5 '14 at 11:43
  • 1
    Did you try getAllVisibleItems() instead of getAllItems()? – Renon Stewart Nov 5 '14 at 11:58
  • @R.S. I think you can put your comment as an answer if you make it look like an answer :) – Marius Nov 5 '14 at 12:06
2

Try

$order->getAllVisibleItems()

getAllVisibleItems() - will show you only the parent item

getAllItem() - will show both products (config and simple)

See Magento – What is the difference between getAllVisibleItems() and getAllItems()?

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.