假设我有两个类别,A 和 B。
我将 A 设置为在 Catalog -> 上使用“layout_a”。目录类别 ->点击类别->单击“自定义设计”选项卡,
我将 B 设置为在目录上使用“layout_b”->目录类别 ->点击类别->单击自定义设计选项卡
当我访问类别 A 和 B 时,他们使用我在管理面板上设置的自己的布局来显示产品。当我单击产品列表页面上的某个项目时,产品视图页面不使用自定义设计。
如何强制产品视图页面使用其类别的自定义设计?
Let's say I have two categegories, A and B.
I set A to use 'layout_a' on Catalog -> Catalog Categories -> Click a category -> click custom design tab
I set B to use 'layout_b' on Catalog -> Catalog Categories -> Click a category -> click custom design tab
When I visit category A and B, theydisplays products using their own layout that I set on the admin panel. When I click an item on the product listing page, product view page does not use custom design.
How do I enforce product view page to use its category's custom design?
发布评论
评论(4)
创建一个具有下拉类型和名称属性代码“which_category”的属性。在选项选项卡上填写“category_a”和“category_b”
在/app/design/frontend/default/YOURTEMP/template/catalog/product/中创建两个文件
:view_cat_a.phtml和view_cat_b.phtml
您可以设计您的特定类别基于view.phtml的产品视图页面。
将 view.phtml 更改为:
创建产品时,您可以选择属性上的类别(在 attribute_set 中定义它们)
Create an attribute with dropdown type and name attribute code 'which_category'. On the options tab fill in 'category_a' and 'category_b'
Create two files in /app/design/frontend/default/YOURTEMP/template/catalog/product/
lets say: view_cat_a.phtml and view_cat_b.phtml
You can design your specific category product view page based on view.phtml.
Change view.phtml to:
When you create a product you can choose the category on the attribute (define them in attribute_set)
您可以在“产品目录”>“管理产品”>“设计”上应用自定义设计更新,然后根据“类别”应用
这是否可以满足您的需求?
You can apply the Custom Design updates on the product Catalog>Manage Products>Design and then apply as per the Categories
Does that achieve what you need?
我自己找到了答案。
打开位于 /app/code/Mage/Catalog/controllers/ProductController.php 的产品控制器
添加以下代码到 _initProductLayout 方法
$update->addHandle('CATEGORY_'.$product->getCategoryId());
打开目录布局 xml 位于 /app/design/frontend/default/default/layout/catalog.xml
添加
I found the answer by myself.
Open product controller located in /app/code/Mage/Catalog/controllers/ProductController.php
add the following code into _initProductLayout method
$update->addHandle('CATEGORY_'.$product->getCategoryId());
Open catalog layout xml located in /app/design/frontend/default/default/layout/catalog.xml
add
在 Magento 的当前版本中,还有另一种方法可以在不更改核心代码的情况下执行此操作。假设您有一个用于类别产品显示的自定义模板。在管理中,转到目录 -> 类别 -> 管理类别,然后选择要应用修改后的产品模板的类别。将“应用到产品”更改为“是”,并将以下内容放入“自定义布局更新”中;
其中 NEW_VIEW 是您要使用的新模板的名称。如果您有子类别,则可能需要将其“使用父类别设置”设置为“是”才能使其浮动。
In the current versions of Magento there is another way to do this without changing core code. Lets say you have a custom template for the product display of a category. In Admin go to Catalog->Categories->Manage Categories and select the category you want to apply the modified product template to. Change "Apply to Products" to Yes and put the following in the Custom Layout Update;
Where NEW_VIEW is the name of the new template you want to use. If you have sub-categories you may need to have their "Use Parent Category Settings" set to Yes in order for it to float through.