[英]How to list Magento sub categories and their products on category/view.phtml
[英]In magento how can I show different-different list.phtml and view.phtml for different -different categories?
我想为不同的类别显示不同的-different list.phtml和view.phtml 。
我的代码是:
<CATEGORY_4>
<reference name="product_list">
<action method="setTemplate"><name>catalog/product/list_new.phtml</name></action>
</reference>
</CATEGORY_4>
您的代码将帮助您将不同的list.phtml用于不同的类别。 要将不同的view.phtml用于不同的类别产品,您将必须设置不同的属性属性集,并为不同的属性集分配不同的模板。 检查此链接以了解如何操作Magento:基于属性集的模板
要么
如果类别页面和产品视图页面使用相同的页面布局,例如:类别页面和产品视图页面使用1column.phtml页面布局,则可以按照以下步骤为不同的类别使用不同的list.phtml和view.phtml 。
<reference name="product_list"> <action method="setTemplate"><name>catalog/product/your-list-filename.phtml</name></action> </reference> <reference name="product.info"> <action method="setTemplate"><template>catalog/product/your-view-filename.phtml</template></action> </reference>
对要更改的所有类别重复此操作。
感谢您的帖子。 我只是用这个
<reference name="product.info">
<action method="setTemplate"><template>catalog/product/your-view-filename.phtml</template> </action>
</reference>
而且工作正常。 但是如果我将一种产品设置为多个类别,则无法处理布局。 它称为同一文件“ your-view-filename.phtml”。 甚至我都经历过这两个类别。
使用方法:
<reference name="product.info">
<action method="setTemplate"><template>catalog/product/your-view-filename.phtml</template> </action>
</reference>
仅当您从定义产品的类别页面访问产品时,才应用产品布局。 例如,如果您从主页访问产品,则该产品不适用。 我将布局应用于属于已定义类别的所有产品所做的工作是从Mage_Catalog_Model_Design重写函数getDesignSettings():
public function getDesignSettings($object)
{
if ($object instanceof Mage_Catalog_Model_Product) {
$customCat = 'XX';
$productCats = $object->getAvailableInCategories();
if (in_array($customCat, $productCats))
$currentCategory = Mage::getModel('catalog/category')->load($customCat);
else
$currentCategory = $object->getCategory();
} else {
$currentCategory = $object;
}
$category = null;
if ($currentCategory) {
$category = $currentCategory->getParentDesignCategory($currentCategory);
}
if ($object instanceof Mage_Catalog_Model_Product) {
if ($category && $category->getCustomApplyToProducts()) {
return $this->_mergeSettings($this->_extractSettings($category), $this->_extractSettings($object));
} else {
return $this->_extractSettings($object);
}
} else {
return $this->_extractSettings($category);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.