我有一个自定义list.phtml页面。我复制了list.phtml页面并将其重命名为newlist.phtml页面。唯一的区别是我改变了
$_productCollection=$this->getLoadedProductCollection();
要
$_productCollection = Mage::getModel('catalog/product')
->getCollection()->addFieldToFilter('status', array('neq' => 2))
->addAttributeToSort('created_at', 'DESC')
->addAttributeToSelect('*')
->load();
通过在管理内容中添加以下内容来使用它
{{block type="catalog/product_list" name="home.catalog.product.list" alias="products_homepage" template="catalog/product/newlist.phtml"}}
以及布局更新中的
<reference name="left">
<block type="catalog/layer_view" name="catalog.leftnav" template="catalog/layer/view.phtml"/>
</reference>
但是这个页面没有显示Layred Nav。但所有其他类似页面的页面都显示了分层导航。任何想法???
答案 0 :(得分:1)
分层导航过滤器正在使用Mage::getSingleton('catalog/layer')
对象。您正在从目录模型对象中直接查找产品集合,这会导致此处出现问题。
请在此处查看Magento的产品系列获取逻辑:
protected function _getProductCollection()
{
if (is_null($this->_productCollection)) {
$layer = $this->getLayer();
/* @var $layer Mage_Catalog_Model_Layer */
if ($this->getShowRootCategory()) {
$this->setCategoryId(Mage::app()->getStore()->getRootCategoryId());
}
// if this is a product view page
if (Mage::registry('product')) {
// get collection of categories this product is associated with
$categories = Mage::registry('product')->getCategoryCollection()
->setPage(1, 1)
->load();
// if the product is associated with any category
if ($categories->count()) {
// show products from this category
$this->setCategoryId(current($categories->getIterator()));
}
}
$origCategory = null;
if ($this->getCategoryId()) {
$category = Mage::getModel('catalog/category')->load($this->getCategoryId());
if ($category->getId()) {
$origCategory = $layer->getCurrentCategory();
$layer->setCurrentCategory($category);
$this->addModelTags($category);
}
}
$this->_productCollection = $layer->getProductCollection();
$this->prepareSortableFieldsByCategory($layer->getCurrentCategory());
if ($origCategory) {
$layer->setCurrentCategory($origCategory);
}
}
return $this->_productCollection;
}
参考app / code / core / Mage / Catalog / Block / Product / List.php