0

In the list view, I want to display the 3 most important attributes of the product below the productname.

What is the best way to fix this? Is there a way to highlight some attribute, so that these can be displayed there?

  • How do you define "most important"? – Marius Feb 18 '15 at 9:50
  • The attributes that we think are the most imported attributes. But that depends on the category. For example for Notebooks this will be the processor. But for Monitors, this will be the screen size. So we need to define this for every category. – JGeer Feb 18 '15 at 9:52
0

Here is how I would do it.
you can make a multiselect category attribute that has as options the product attributes. And for each category you select the attributes that you want displayed. below the title.

Here is a tutorial on how to add a category attribute.
But you need this category attribute to have as options the product attributes.
Here is an example on how you can add an attribute with a custom source. the example is for products but it works the same for category attributes.
Let's call the attribute important_attributes. The most important part in the example above is the method Easylife_Provider_Model_Attribute_Source_Provider::getAllOptions. that's the one that generates the attribute options.
In your case you need to replace the method with something like this:

public function toOptionArray($withEmpty = true)
{
    if (is_null($this->_options)) {
        $collection = Mage::getResourceModel('catalog/product_attribute_collection')
            ->addVisibleFilter(); //this will get you the product attributes collection. you can supply a sort order if needed
        ;
        $this->_options = array();
        if ($withEmpty) {
            $this->_options[] = array(
                'label'=>'',
                'value'=>''
            );
        }
        foreach ($collection as $attribute) {
            $this->_options[] = array(
                'label' => $attribute->getFrontendLabel(),
                'value' => $attribute->getData('attribute_code')
            );
        }
    }
    return $this->_options;
}

Now in the product listing you have to check if you are in category context (because the same list is used in search results).

if (Mage::registry('current_category')) {
    $attributeCodes = Mage::registry('current_category')->getImportantAttributes();
    if (!is_array($attributeCode)) { //sometimes this comes as an array other times as strings depending on the setting for flat catalog
        $attributeCodes = explode(',', $attributeCodes);
    }
}

And for each product in the foreach loop check this:

foreach ($attributeCodes as $code) {
    if ($_product->hasData($code)) {
        echo $_product->getAttributeText($code);
    }
}

The code is not tested, but the idea is there. I hope it helps.

0

Jelle,Magento donot have enable this feature to enable attribute from admin You need to Customization on this.

Also enable this attribute in Used in product list for getting quick data

  • Amit, thanks for your reply. Is there an easy way to add this option. So that attributes can be highlighted, so that I can echo these attributes? – JGeer Feb 18 '15 at 11:15

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.