1

My store has 2 different types of Attribute Sets for my Simple Products:

Default
Custom

For all my products that have the attribute set name of Custom I need to remove the following sections from the page layout:

<reference name="root">
    <remove name="header" />
    <remove name="breadcrumbs" />
    <remove name="footer" />
</reference>

Is there a way i can easily assign all products in this attribute set to always remove these 3 sections.

I know I can place the above in the Custom Design Layout section but I currently have over 100,000 products with the attribute set of Custom so going through one by one is not an option.

  • you want to change attribute set or what? – Magento 2 Oct 8 '15 at 12:09
  • No, the attribute set stays as it is but all products with the attribute set of Custom i want to remove the header footer and breadcrumbs – odd_duck Oct 8 '15 at 12:13
2

For this case, we can add new layout handler on basic of Attribute Sets at event controller_action_layout_load_before.

Event: controller_action_layout_load_before

Condition: product attribute set

So , i am start an observer on basic of this condition which is add new
handler on current layout .

Handler Format: PRODUCT_ATTRIBUTE_SET_{ProdductAttributSetName}

Observer code:

<?php
class [ModuleNameSpace]_[ModuleName]_Model_Observe{ 
/**
     * Before load layout event handler
     *
     * @param Varien_Event_Observer $observer
     */
    public function beforeLoadLayout($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 ;
    }


}

Config.xml code;

<global>
    <models>
        <[MyCustomModule_Model_Class_Groupname]>
            <class>[ModuleNameSpace]_[ModuleName]_Model</class>
        </[MyCustomModule_Model_Class_Groupname]>
    </models>
</global>
   <frontend>
        <events>
            <controller_action_layout_load_before>
                <observers>
                    <my_current_page_is_observer>
                        <class>[MyCustomModule_Model_Class_Groupname]/observer</class>
                        <method>beforeLoadLayout</method>
                    </my_current_page_is_observer>
                </observers>
            </controller_action_layout_load_before>
     </events>
   </frontend>

Now on this of this handler,you can add a new block to layout and a new phtml.

Suppose, you want to change the layout at Custom attribute set page then you can try this.

<PRODUCT_ATTRIBUTE_SET_Custom>
<reference name="root">
    <remove name="header" />
    <remove name="breadcrumbs" />
    <remove name="footer" />
</reference
</PRODUCT_ATTRIBUTE_SET_Custom>

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.