2015-04-17 90 views
1

我有一个自定义list.phtml页面。我已经复制list.phtml页面并将其重命名为newlist.phtml页面。唯一不同的是我已经改变了Magento Layred导航不出现在我的自定义list.phtml

$_productCollection=$this->getLoadedProductCollection(); 

TO

$_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。但所有其他页面(如类别页面)都会显示导航。任何想法???

回答

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; 
    } 

Refer-应用程序/代码/核心/法师/目录/座/产品/ list.php的

+0

哦!感谢您的答复。因为我刚刚进入了magento世界。那么你能告诉我该怎么做才能显示Layred Nav?提前致谢 – Parangan