簡體   English   中英

Magento Layred導航未出現在我的自定義list.phtml中

[英]Magento Layred Navigation not appearing in my custom list.phtml

我有一個自定義的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"}}

布局更新中的AND

<reference name="left">

    <block type="catalog/layer_view" name="catalog.leftnav"  template="catalog/layer/view.phtml"/>

    </reference>

但是此頁面未顯示分層導航。 但是所有其他頁面(如類別頁面)都顯示常規導航。 任何想法???

分層導航過濾器正在與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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM