Magento - 产品属性集的特定自定义设计布局
Magento - Specific Custom Design Layout for Product Attribute Set
我的商店有 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 种产品具有自定义属性集,因此无法逐一进行。
对于这种情况,我们可以在 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>
现在在这个处理程序中,您可以添加一个新的块到布局和一个新的 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>
我的商店有 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 种产品具有自定义属性集,因此无法逐一进行。
对于这种情况,我们可以在 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>
现在在这个处理程序中,您可以添加一个新的块到布局和一个新的 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>