Magento的:基于属性集模板 [英] Magento: template based on attribute set
问题描述
我想根据设定的产品属性来创建不同的产品的看法属于:
确实的Magento提供一种方式来做到这一点?
I want to create different product views based on the attribute set the product belongs to: does Magento provide a way to do this?
- 更新 -
继担。codeS建议我增加了
Following dan.codes suggestion I've added
$update->addHandle('PRODUCT_ATTRIBUTE_SET_ID_'.$product->getAttributeSetId());
要Mage_Catalog_ProductController(我复制ProductController.php并把它放到地方/法师/目录/控制器/).
to Mage_Catalog_ProductController (I duplicated ProductController.php and put it in local/Mage/Catalog/controllers/).
然后我说这的catalog.xml
Then I added this to catalog.xml
<PRODUCT_ATTRIBUTE_SET_ID_9> // PRODUCT ID of Book Attribute Set
<label>Catalog Product View (Book)</label>
<reference name="product.info">
<block type="catalog/product_view_type_book" name="product.info.book" as="product_type_data" template="catalog/product/view/attribute_set/book.phtml">
<block type="core/text_list" name="product.info.book.extra" as="product_type_data_extra"/>
</block>
</reference>
</PRODUCT_ATTRIBUTE_SET_ID_9>
就在
<PRODUCT_TYPE_virtual translate="label" module="catalog">
<label>Catalog Product View (Virtual)</label>
<reference name="product.info">
<block type="catalog/product_view_type_virtual" name="product.info.virtual" as="product_type_data" template="catalog/product/view/type/virtual.phtml">
<block type="core/text_list" name="product.info.virtual.extra" as="product_type_data_extra"/>
</block>
</reference>
</PRODUCT_TYPE_virtual>
然后我创建目录/产品/浏览/ attribute_set / book.phtml,但它不显示在我的产品视图页面。
I then created catalog/product/view/attribute_set/book.phtml, but it is not displayed in my product view page.
- 更新Magento的1.5 -
我注意到,处理程序更新,在过去的Magento发布以来感动。
I've noticed that the handler update has moved in the last Magento release.
$update->addHandle('PRODUCT_TYPE_'.$product->getTypeId());
$update->addHandle('PRODUCT_'.$product->getId());
在法师/目录/助手/产品/ View.php了。结果
我测试过,它仍然伟大工程!
is in Mage/Catalog/Helper/Product/View.php now.
I've tested and it still works great!
推荐答案
没有它没有,但你可以通过在那里的code为Mage_Catalog_ProductController延长_initProductLayout方法扩展功能这样做,这
No it doesn't but you can extend the functionality to do so by extending the _initProductLayout method in Mage_Catalog_ProductController under where the code is this
$update = $this->getLayout()->getUpdate();
$update->addHandle('default');
$this->addActionLayoutHandles();
$update->addHandle('PRODUCT_TYPE_'.$product->getTypeId());
$update->addHandle('PRODUCT_'.$product->getId());
您可以添加
$update->addHandle('PRODUCT_ATTRIBUTE_SET_ID_'.$product->getAttributeSetId());
然后在你的layout.xml你可以有
Then in your layout.xml you could have
<PRODUCT_ATTRIBUTE_SET_ID_IDHERE>
<reference name="root">
<action method="setTemplate"><template>template/path/here.html</template></action>
</reference>
</PRODUCT_ATTRIBUTE_SET_ID_IDHERE>
这篇关于Magento的:基于属性集模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!