Hello every one i want to add a column in sales order grid to show custom attribute of products for exp : color Thanks you very much for help.
Asked
Active
Viewed 1,575 times
-1
-
Override the Mage_Adminhtml_Block_Sales_Order_Grid and you can set the grid collection and column. Add the column and set the value in collection $this->addColumn('color', array( 'header' => Mage::helper('sales')->__('# Color'), 'width' => '80', 'name' => 'color', 'index' => 'color', )); – user3040610 Jan 12 '15 at 06:32
-
I am getting following error :- SQLSTATE[42S22]: Column not found: 1054 Unknown column 'color' in 'order clause', query was: SELECT `main_table`.* FROM `sales_flat_order_grid` AS `main_table` ORDER BY color ASC LIMIT 20 – user3932271 Jan 12 '15 at 06:46
-
yes you have to get the color column results and set to the collections. – user3040610 Jan 12 '15 at 07:02
-
Hello @user3040610 how can i set value in collection please help me i am new in magento thanks. – user3932271 Jan 12 '15 at 07:26
-
check this link http://www.atwix.com/magento/customize-orders-grid/ – user3040610 Jan 12 '15 at 07:28
-
Sorry but it's not help me @user3040610 i want to show custom attribute of product like :- color ,cost etc. – user3932271 Jan 12 '15 at 08:09
1 Answers
2
Step 1 :- Copy app\code\core\Mage\Adminhtml\Block\Sales\Order\grid.php to app\code\local\Mage\Adminhtml\Block\Sales\Order\grid.php Find protected function _prepareColumns() To Add column use this code:-
$this->addColumn('color ', array(
'header' => Mage::helper('sales')->__('color #'),
'index' => 'color',
'sortable' => false,
'filter' => false,
'renderer' => 'Mage_Adminhtml_Block_Sales_Order_Renderer_Productatt',
));
Step 2:- Create a new file at :-
app\code\local\Mage\Adminhtml\Block\Sales\Order\Renderer\Productatt.php add this code :-
class Mage_Adminhtml_Block_Sales_Order_Renderer_Productatt 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')); $attribute =""; foreach($order->getAllVisibleItems() as $_item){ $product = Mage::getModel('catalog/product')->load($_item->getProductId()); if($product->getAttributeText('color')){ $attribute .= $product->getAttributeText('color'); } } unset($order); return $attribute; } }

Arunendra
- 570
- 2
- 10
- 34
-
May i know how to solve this error, Fatal error: Uncaught Error: Call to a member function getSource() on boolean in C:\wamp\www\anc\app\code\core\Mage\Catalog\Model\Product.php on line 1385 – Gem Jan 12 '18 at 05:08