When customizing a Mаgentо shop it is often needed to apply different page design for each type of product. For these purposes are used handles of these types of products in the catalog.xml file:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
… <PRODUCT_TYPE_simple translate="label" module="catalog"> <label>Catalog Product View (Simple)</label> <reference name="product.info"> <block type="catalog/product_view_type_simple" name="product.info.simple" as="product_type_data" template="catalog/product/view/type/default.phtml"> <block type="core/text_list" name="product.info.simple.extra" as="product_type_data_extra" translate="label"> <label>Product Extra Info</label> </block> </block> </reference> </PRODUCT_TYPE_simple> … |
The necessary handle may not exist, but we can always create our own.
For example, let’s add a handle to a product’s Attribute Set, so that we would be able to apply changes to a product, depending on which Attribute Set it relates to.
To do this we will create a module and an observer and will register to the event controller_action_layout_load_before. In the observer we will create a method, which will verify if the module is enabled, and will add our handles.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
… /** * Return if it is not product page */ if (!($product instanceof Mage_Catalog_Model_Product)) { return FALSE; } $attributeSet = Mage::getModel('eav/entity_attribute_set') ->load($product->getAttributeSetId()); /** * Convert attribute set name. */ $nameAttributeSet = strtoupper(str_replace('-', '_', $product->formatUrlKey( $attributeSet->getAttributeSetName() ))); /* @var $update Mage_Core_Model_Layout_Update */ $update = $observer->getEvent()->getLayout()->getUpdate(); /* Remember all handles in a variable */ $handles = $update->getHandles(); $update->addHandle('PRODUCT_ATTRIBUTE_SET_' . $nameAttributeSet); $update->resetHandles(); // Remove all handles foreach ($handles as $handle) { $update->addHandle($handle); if ($handle == 'PRODUCT_TYPE_' . $product->getTypeId()) { $update->addHandle('PRODUCT_ATTRIBUTE_SET_' . $nameAttributeSet); } } … |
Aleksander! This is embarrassing tips to create custom theme for each page. I wonder is that include this in my files? I take a google search and find in blog says I would need to add this in config.xml. Can you confirm should I add this in Local xml or to where?
Cathy
Snowcore,
I do it in order to locate our new handle right after a product type handle. I.e., after the product type handle and before a handle for a particular product (PRODUCT_ID_).
Why do you call “resetHandles” method?