Пользовательский макет, основанный на наборе атрибутов, не работает
Я следовал этому руководству , чтобы добавить attribute set
обновления макета страницы конкретного продукта, но это не работает.
Вот мой код:
Файл: app\code\local\Magebase\AttributeSetHandle\etc\config.xml
Код:
<?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>
Файл: app\code\local\Magebase\AttributeSetHandle\Model\Observer.php
КОД:
<?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);
}
}
}
}
В local.xml
внутри <layout></layout>
я добавил:
<PRODUCT_ATTRIBUTE_SET_Informatica>
<reference name="product.info">
<action method="setTemplate"><template>catalog/product/view-informatica.phtml</template></action>
</reference>
</PRODUCT_ATTRIBUTE_SET_Informatica>
Мой набор атрибутов называется Informatica
, а настроенное представление.phtml находится в design/frontend/[my-custom-tample]/default/template/catalog/product
Чего мне здесь не хватает?
Пожалуйста, помогите :)
Спасибо, ребята,
1
Author: Artur Rain, 2015-02-27
1 answers
Привет, сначала нужно отладить ваш current page handler
с помощью кода ниже:
Zend_Debug::dump(Mage::app()->getLayout()->getUpdate()->getHandles());
Я изменил код и добавил обработчик только для страницы просмотра продукта
<?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 ;
}
}
0
Author: Amit Bera, 2015-02-27 12:32:23