Archive for April, 2013

Add Label for New Product in Magento Product List

Add following code to display new label for new products.

<?php  $now = date(‘Y-m-d’);
$newsFrom= substr($_product->getData(‘news_from_date’),0,10);
$newsTo=  substr($_product->getData(‘news_to_date’),0,10);

if (($now>=$newsFrom && $now<=$newsTo)||($now>=$newsFrom && $newsFrom!=” && $newsTo==” ))
{?><img alt=”” src=”<?php echo $this->getSkinUrl(‘images/icon-new.png’);?>”><?php }?>

Advertisements

Add Dropdown Attribute Value in Magento Product Grid

If you have to show “size” dropdown attribute in magento product grid, then take following steps.

In _prepareCollection() function, add following line.

->joinAttribute(‘size’,’catalog_product/size’, ‘entity_id’, null,’left’, $store->getId())

OR

->addAttributeToSelect(‘size’)

Now, In _prepareColumns() function, add following code.

$attribute = Mage::getModel(‘eav/config’)->getAttribute(‘catalog_product’, ‘size’);
$options = array();
foreach( $attribute->getSource()->getAllOptions(true, true) as $option ) {
if($option[‘value’] != ”){
$options[$option[‘value’]] = $option[‘label’];
}
}
$this->addColumn(‘size’,
array(
‘header’=> Mage::helper(‘catalog’)->__(‘Size’),
‘width’ => ’80px’,
‘index’ => ‘size’,
‘type’  => ‘options’,
‘options’ => $options,
));

Thats it!!

Magento warning array_key_exists()

When you have face array_key_exists() type of error in Magento then please following below steps.

-> Open file app\code\core\Mage\Captcha\Model\Observer.php

-> Go to line no. 166.

-> Replace array_key_exists  function with  property_exists function.

Thats it….