I want to add a new column to the "Catalog Products" grid in Magento's admin area.
The new column will be called Currently Discounted? or Sale Item? and will display "Yes" when a product's price is more than its special_price (i.e. the product is in a sale).
So far I've been able to add the special_price column to the grid, via the code below:
$collection->joinAttribute('special_price', 'catalog_product/special_price', 'entity_id', null, 'left', $store->getId());
$this->addColumn('special_price',
array(
'header'=> Mage::helper('catalog')->__('Special Price'),
'type' => 'price',
'currency_code' => $store->getBaseCurrency()->getCode(),
'index' => 'special_price',
));
But what I really need is another column which actually performs some kind of logic to compare the special_price and print "Yes" if it's discounted and "No" if it's not.
I've added the column but for now, obviously, it's empty because its index doesn't correspond to any real source of data:
$this->addColumn('is_sale_item',
array(
'header'=> Mage::helper('catalog')->__('Sale Item?'),
'type' => 'options',
'index' => 'is_sale_item', // <--- HOW DO I POPULATE THIS INDEX?
'options' => array( 0 => 'No', 1 => 'Yes')
));
How would I achieve this? Where would I put the logic for the "is_sale_item" calculation and make it a "real" index?