Question

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

Was it helpful?

Solution

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()?

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top