Workaround for attribute store labels not being displayed in Magento
February 12th, 2012
Here’s a quick workaround for a rather strange issue – sometimes, calling $attribute->getStoreLabel()
returns null
, although everything looks fine in the admin and in the database. It might be something that is slipping my mind, or it might be a bug, not really sure. However, I had to deal with it and come up with a fix, so I’d thought I’d share.
$_aIds = array(); foreach( $prod->getAttributes() as $attribute ) { //need the attribute_id which is missing from the attribute object if( !isset($_aIds[$attribute->getAttributeCode()]) ) { $_aIds[$attribute->getAttributeCode()] = $attribute->getIdByCode('catalog_product', $attribute->getAttributeCode()); } //if there's not store_label try to set it if( !$attribute->getStoreLabel() ) { $labels = $attribute->getResource()->getStoreLabelsByAttributeId( $_aIds[$attribute->getAttributeCode()] ); if( array_key_exists(Mage::app()->getStore()->getStoreId(), $labels)) { $attribute->setStoreLabel( $labels[Mage::app()->getStore()->getStoreId()] ); } else { $attribute->setStoreLabel( $attribute->getFrontendLabel() ); } } } // end workaround
Applies to Magento 1.5.x