2015-04-17 91 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