1

I have one problem. Is there a way to set custom attributes to my products when the product is in a category.

Example:
I have two Categories. When I add a product in the first category, I will show the custom attribute brand. When I add a product in the second category I will show the attribute material.

Has anyone a idea?

  • Did you manage to get your issue resolved? – Sander Mangel Apr 16 '15 at 7:36
1

have you tried to achieve this using attribute sets? I think it's more correct to create two attribute sets - one containing "brand" attribute and another containing "material" attribute.

1

This is not possible out of the box. However, you could do this by rewriting the Mage_Catalog_Block_Product_View_Attributes block class from a custom module editing the getAdditionalData method to check for the current_category registry key.

The method already has an argument for excluding certain attributes so depending on the category you could exclude or hide either the brand or material attribute.

Set both attributes to display on product page and this will result the attribute either being shown or hidden depending on the category used to navigate to the product

public function getAdditionalData(array $excludeAttr = array())
{
    $category = Mage::registry('current_category');
    if ($category->getId() == [category X id]) {
        $excludeAttr[] = '[brand_attribute_code]';
    } elseif ($category->getId() == [category Y id]) {
        $excludeAttr[] = '[material_attribute_code]';
    }

    return parent::getAdditionalData($excludeAttr);
}

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.