[英]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.