【发布时间】:2011-01-19 13:00:50
【问题描述】:
我想根据产品所属的属性集创建不同的产品视图: Magento 是否提供了一种方法来做到这一点?
- 更新-
按照我添加的 dan.codes 建议
$update->addHandle('PRODUCT_ATTRIBUTE_SET_ID_'.$product->getAttributeSetId());
到 Mage_Catalog_ProductController(我复制了 ProductController.php 并把它放在 local/Mage/Catalog/controllers/ 中)。
然后我将它添加到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,但它没有显示在我的产品视图页面中。
- 更新 MAGENTO 1.5 -
我注意到处理程序更新已在上次 Magento 版本中移动。
$update->addHandle('PRODUCT_TYPE_'.$product->getTypeId());
$update->addHandle('PRODUCT_'.$product->getId());
现在在 Mage/Catalog/Helper/Product/View.php 中。
我已经测试过了,它仍然很好用!
【问题讨论】:
-
它为我工作,也许它是你在你的块中所做的,只是为了确保代码正在工作,更改你的 xml 以引用根并将模板设置为不同的东西,看看页面是否变化。 `
标签: templates magento attributes product