简体   繁体   English

Magento Layred导航未出现在我的自定义list.phtml中

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

I have a custom list.phtml page. 我有一个自定义的list.phtml页面。 I have copied list.phtml page and rename it to newlist.phtml page. 我已经复制了list.phtml页面,并将其重命名为newlist.phtml页面。 The only difference is I have changed the 唯一的区别是我已经更改了

$_productCollection=$this->getLoadedProductCollection();

TO

$_productCollection = Mage::getModel('catalog/product')
                        ->getCollection()->addFieldToFilter('status', array('neq' => 2))
                        ->addAttributeToSort('created_at', 'DESC')
                        ->addAttributeToSelect('*')
                        ->load();

And using it by Adding the below in admin content 并通过在管理内容中添加以下内容来使用它

{{block type="catalog/product_list" name="home.catalog.product.list" alias="products_homepage" template="catalog/product/newlist.phtml"}}

AND below in layout update 布局更新中的AND

<reference name="left">

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

    </reference>

But this page does not showing the Layred Nav. 但是此页面未显示分层导航。 But all other page like category pages shows the layred nav. 但是所有其他页面(如类别页面)都显示常规导航。 Any idea??? 任何想法???

Layered navigation filters are working with Mage::getSingleton('catalog/layer') object. 分层导航过滤器正在与Mage::getSingleton('catalog/layer')对象一起使用。 You are directly finding product collection from catalog model object and this is causing issues here. 您直接从目录模型对象中找到产品集合,这在这里引起问题。

See Magento's product collection fetching logic here: 请在此处查看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- app/code/core/Mage/Catalog/Block/Product/List.php 参考-app / code / core / Mage / Catalog / Block / Product / List.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM