3

I've realised there are many answer which actually are technically incorrect because they only are taking into account one product. They remove any attribute that is empty or null even if the second product's attribute is not null or empty.

So I decided to post an answer.

  • In what folder I can find this block and function? – 2feyrr Oct 15 '18 at 10:53
  • @RamaChandranM this is the question. Not an answer. – André Ferraz Oct 15 '18 at 16:27
  • I am sorry mistake added comments for thsi :( i will remove it – Rama Chandran M Oct 15 '18 at 16:58
  • How do we implement the accepted answer? – HRR1337 May 17 '19 at 13:01
  • @HRR1337 following it? – André Ferraz May 17 '19 at 14:35
4

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;

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.