0

How to add a class on the product page that has a specific set attributes?

I know in xml

<reference name="root">
      <action method="addBodyClass">
          <className>account-page</className>
      </action>
</reference>

but i need for specific set attributes

1

1 Answer 1

2

Create a custom module and override Mage_Catalog_Helper_Product_View Helper OR put it to local codepool at \app\code\local\Mage\Catalog\Helper\Product\View.php

Now Update initProductLayout method of View.php helper

public function initProductLayout($product, $controller)
{
    ...

    $update->addHandle('PRODUCT_TYPE_' . $product->getTypeId());
    $update->addHandle('PRODUCT_' . $product->getId());

    //adding handle for custom VIEW pages
    $update->addHandle('CUSTOMPRODUCTVIEW_' . $product->getAttributeSetId());
    //END adding handle for custom VIEW pages

    $controller->loadLayoutUpdates();

    ...
}

Now you can use/add handles like this (in local.xml)

...

<CUSTOMPRODUCTVIEW_21>
    <reference name="root">
      <action method="addBodyClass">
          <className>CLASS-FOR-21-attr</className>
      </action>
    </reference>
</CUSTOMPRODUCTVIEW_21>
<CUSTOMPRODUCTVIEW_23>
    <reference name="root">
      <action method="addBodyClass">
          <className>CLASS-FOR-23-attr</className>
      </action>
    </reference>
</CUSTOMPRODUCTVIEW_23>

...

Where 21 and 23 are IDs of attribute sets, change them with your attribute set IDs

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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