【问题标题】:Magento Layred Navigation not appearing in my custom list.phtmlMagento 分层导航未出现在我的自定义 list.phtml 中
【发布时间】:2015-04-17 10:39:27
【问题描述】:

我有一个自定义 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>

但此页面未显示分层导航。但所有其他页面(如类别页面)都显示分层导航。有什么想法???

【问题讨论】:

    标签: php magento magento-1.8


    【解决方案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

    【讨论】:

    • 哦!感谢您的答复。因为我刚刚进入magento世界。那么你能告诉我应该怎么做才能显示Layred Nav吗?提前致谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多