We need to override the block class Mage_Catalog_Block_Product_Compare_List
and function getAttributes()
, this way we have pre sorted array list of attributes instead of having to do the changes at template level.
public function getAttributes()
{
if (is_null($this->_attributes)) {
$this->_attributes = $this->getItems()->getComparableAttributes();
}
// Remove Null Attribute From Compare List
foreach($this->_attributes as $attribute) {
$size = sizeof($this->getItems());
$count = 0;
foreach($this->getItems() as $item) {
$itemAttribute = $item->getData($attribute->getName());
$trimAttribute = trim($itemAttribute);
if(is_null($itemAttribute) || empty($trimAttribute)) {
$count++;
}
if($count == $size) {
unset($this->_attributes[$attribute->getName()]);
}
}
}
return $this->_attributes;
}