【问题标题】:Magento - Specific Custom Design Layout for Product Attribute SetMagento - 产品属性集的特定定制设计布局
【发布时间】:2016-01-06 01:11:58
【问题描述】:

我的商店有 2 种不同类型的 Attribute Sets 用于我的 Simple Products

Default
Custom

对于属性集名称为Custom 的所有产品,我需要从页面布局中删除以下部分:

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

有没有一种方法可以轻松地分配此属性集中的所有产品以始终删除这 3 个部分。

我知道我可以将以上内容放在 Custom Design Layout 部分,但我目前有超过 100,000 种具有自定义属性集的产品,因此无法逐个浏览。

【问题讨论】:

    标签: magento layout attributes product


    【解决方案1】:

    对于这种情况,我们可以在Attribute Sets 的基本事件controller_action_layout_load_before 上添加新的布局处理程序。

    事件: controller_action_layout_load_before

    条件:产品属性集

    所以,我开始观察这个基本条件,即添加新的
    当前布局上的处理程序 .

    处理程序格式: PRODUCT_ATTRIBUTE_SET_{ProdductAttributSetName}

    观察者代码:

    <?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 代码;

    <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>
    

    现在在这个处理程序的 this 上,你可以添加一个新的块到布局和一个新的 phtml。

    假设你想改变Custom attribute set page的布局,那么你可以试试这个。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-23
      相关资源
      最近更新 更多