Having problem to add new column in admin >sales > order grid ,product name is repeating
-
12-12-2019 - |
문제
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;
}
}
?>
해결책
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()?
제휴하지 않습니다 magento.stackexchange