I want to show custom product comparison with standard products on the product page but the attributes that are used to compare the products may be different than magento comparision.

So I followed https://gielberkers.com/add-custom-properties-magento this blog to add the custom property to every attribute, depending on the value of this newly added property I want to show the attribute in comparison. then i have created another attribute from admin panel for product and will store the similar standard products id's in that.

After that i have registered a module created a block, fetched the current product and using the attribute which i have created from admin panel, fetched the id's of similar standard products and created collection of then, they can be 2 or 3 products

->addFieldToFilter('entity_id', array('in' => array($productIds)));

This is how collection is created

Now i have to fetch ALL the attributes of products in collection and check if the newly added property(which is added to every attribute it's type is text and i'm giving value yes if i want to show that attribute) of each attribute, if it is yes then i have to show the attribute, how to do this ? Am i going in a right direction,

Thanks in advance


Try this:

            ->addFieldToFilter('entity_id', array('in' => array($productIds)))
            ->addAttributeToFilter('custom_attribute_code', array('eq' => 'Yes'));


$collection = Mage::getModel('catalog/product')->getCollection()
            ->addFieldToFilter('entity_id', array('in' => array($productIds)));

$filters[] = array('custom_attribute_code1' => 'Yes');
$filters[] = array('custom_attribute_code2' => 'Yes');
$filters[] = array('custom_attribute_code3' => 'Yes');
$filters[] = array('custom_attribute_code4' => 'Yes');
foreach ($filters as $attributeCode => $value) {
        $collection->addAttributeToFilter($attributeCode, $value);
  • thanks for reply, i am looking to put filter on attribute option , so for example there is product "tv" and its attribute called screenSize. I created an attribute option called "compare_visible" and set it to "false" for this attribute "screenSize". I am unable to put filter on attribute options so that I can hide this attribute while doing product comparision. – Shrikant Mar 29 '16 at 7:53

I did this by coping magento product compare template file to new template file of our own and called that using block on product view page

I have modified few things in that template file, In the block class created collection of own products and replaced that with old compare collection in our template file.

Then loaded attributes of products and while iterating the attributes i have applied the condition like below

 $attributes = $product->getAttributes();

below above code the attributes label and value are printed. The attributes will not get printed unless it's Option is yes in this way we can have similar standard product comparison

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.