1

I've followed this tutorial to add attribute set specific product page layout updates, but it doesn't work.

Here's my code:

file: app\code\local\Magebase\AttributeSetHandle\etc\config.xml

Code:

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Magebase_AttributeSetHandle>
            <version>0.1.0</version>
        </Magebase_AttributeSetHandle>
    </modules>
    <global>
        <events>
            <controller_action_layout_load_before>
                <observers>
                    <attributesethandle>
                        <class>Magebase_AttributeSetHandle_Model_Observer</class>
                        <method>addAttributeSetHandle</method>
                    </attributesethandle>
                </observers>
            </controller_action_layout_load_before>
        </events>
    </global>
</config>

File: app\code\local\Magebase\AttributeSetHandle\Model\Observer.php

CODE:

<?php
class Magebase_AttributeSetHandle_Model_Observer
{
    /**
     * Converts attribute set name of current product to nice name ([a-z0-9_]+).
     * Adds layout handle PRODUCT_ATTRIBUTE_SET_<attribute_set_nicename> after
     * PRODUCT_TYPE_<product_type_id> handle
     *
     * Event: controller_action_layout_load_before
     *
     * @param Varien_Event_Observer $observer
     */
    public function addAttributeSetHandle(Varien_Event_Observer $observer)
    {
        $product = Mage::registry('current_product');

        /**
         * Return if it is not product page
         */
        if (!($product instanceof Mage_Catalog_Model_Product)) {
            return;
        }

        $attributeSet = Mage::getModel('eav/entity_attribute_set')->load($product->getAttributeSetId());
        /**
         * Convert attribute set name to alphanumeric + underscore string
         */
        $niceName = str_replace('-', '_', $product->formatUrlKey($attributeSet->getAttributeSetName()));

        /* @var $update Mage_Core_Model_Layout_Update */
        $update = $observer->getEvent()->getLayout()->getUpdate();
        $handles = $update->getHandles(); // Store all handles in a variable
        $update->resetHandles(); // Remove all handles

        /**
         * Rearrange layout handles to ensure PRODUCT_<product_id>
         * handle is added last
         */
        foreach ($handles as $handle) {
            $update->addHandle($handle);
            if ($handle == 'PRODUCT_TYPE_' . $product->getTypeId()) {
                $update->addHandle('PRODUCT_ATTRIBUTE_SET_' . $niceName);
            }
        }
    }
}

In the local.xml inside the <layout></layout> i've added:

<PRODUCT_ATTRIBUTE_SET_Informatica>
    <reference name="product.info">
      <action method="setTemplate"><template>catalog/product/view-informatica.phtml</template></action>
    </reference>
</PRODUCT_ATTRIBUTE_SET_Informatica>

My attribute set is named Informatica and the customized view.phtml is located in design/frontend/[my-custom-tample]/default/template/catalog/product

What am I missing here?

Please help :)

Thanks guys,

  • remove $update->resetHandles(); // Remove all handles – Amit Bera Feb 27 '15 at 12:08
  • done, but nothing happens... Still the same layout? Cleared cache, reindexed.. – Artur Rain Feb 27 '15 at 12:24
0

Hi first need debug your current page handler by below code:

Zend_Debug::dump(Mage::app()->getLayout()->getUpdate()->getHandles());

I have modify code and add the handler only for product view page

<?php
class Magebase_AttributeSetHandle_Model_Observer
{
    public function addAttributeSetHandle(Varien_Event_Observer $observer)
    {
        if($observer->getEvent()->getAction()->getFullActionName()=='catalog_product_view'){
            $product = Mage::registry('current_product');
            if($product):
            $layout = $observer->getEvent()->getLayout();
            $attributeSet = Mage::getModel('eav/entity_attribute_set')->load($product->getAttributeSetId());
            $handle = str_replace('-', '_', $product->formatUrlKey($attributeSet->getAttributeSetName()));

            $layout->getUpdate()->addHandle('PRODUCT_ATTRIBUTE_SET_'.$handle);
            // check all Handler 
            //Zend_Debug::dump($layout->getUpdate()->getHandles());
            endif;
        }
        return ;
    }
}
  • Here's what comes out: array(11) { [0] => string(7) "default" [1] => string(8) "STORE_es" [2] => string(28) "THEME_frontend_tytes_default" [3] => string(20) "catalog_product_view" [4] => string(19) "PRODUCT_TYPE_simple" [5] => string(33) "PRODUCT_ATTRIBUTE_SET_informatica" [6] => string(10) "PRODUCT_77" [7] => string(19) "customer_logged_out" [8] => string(19) "MAP_price_msrp_item" [9] => string(14) "SHORTCUT_popup" [10] => string(17) "SHORTCUT_uk_popup" } – Artur Rain Feb 27 '15 at 12:27
  • you see your handler is PRODUCT_ATTRIBUTE_SET_informatica but you used PRODUCT_ATTRIBUTE_SET_Informatica – Amit Bera Feb 27 '15 at 12:28
  • Done, please modify it, specify that the uppercase is important :) For further solution seekers ;) Thanks a lot for the help. – Artur Rain Feb 27 '15 at 12:31
  • you are welcome – Amit Bera Feb 27 '15 at 12:37
  • @AmitBera could you pls help me magento.stackexchange.com/q/221316/57334 – zus Apr 6 '18 at 7:39

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.