自定义产品集合未通过分层导航进行过滤 [英] Custom Product Collection not Getting Filtered by Layered Navigation

查看:82
本文介绍了自定义产品集合未通过分层导航进行过滤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已重写产品List.php类&这是代码

I had Overridden the product List.php Class & here is the code

protected function _getProductCollection()
{   
  if (is_null($this->_productCollection)) {

    $result = array_unique($productIds);        

    $collection = Mage::getResourceModel('catalog/product_collection');
    $attributes = Mage::getSingleton('catalog/config')->getProductAttributes();
    $collection->addAttributeToSelect($attributes);
    $collection->addIdFilter($result);
    Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);

    $this->_productCollection = $collection;
    }

    return $this->_productCollection;
}

工作正常,我还在此处中添加了分层导航>并按预期显示了分层导航.

working fine, I also had added Layered Navigation as mentioned here and layered navigation appeared as expected.

唯一的问题是,当我单击分层导航中的任何过滤器时,导航会更新,并且过滤器也会添加到url,但是产品列表不会被所选过滤器过滤. 请指导我如何在产品系列中应用过滤器

The only problem is, when I click on any filter in layered navigation, navigation gets updated and filter also get added to url, but product list won't get filtered by the selected filter. Please guide me how can I apply the filters on product collection

推荐答案

我在这里可能是错的,但是您覆盖的_getProductCollection()方法似乎绕过了分层导航.我不知道您要达到的目标是什么,但是原始版本会从分层导航模型Mage_Catalog_Model_Layer中注入产品集合:

I could be wrong here, but your overridden _getProductCollection() method seems to be bypassing the layered navigation. I don’t know what your goal was that required you to do that, but the original version gets the product collection injected from the layered navigation model Mage_Catalog_Model_Layer:

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
        ...

        $origCategory = null;
        if ($this->getCategoryId()) {
            $category = Mage::getModel('catalog/category')->load($this->getCategoryId());
            if ($category->getId()) {
                $origCategory = $layer->getCurrentCategory();
                $layer->setCurrentCategory($category);
            }
        }
        $this->_productCollection = $layer->getProductCollection();

        $this->prepareSortableFieldsByCategory($layer->getCurrentCategory());

        if ($origCategory) {
            $layer->setCurrentCategory($origCategory);
        }
    }
}

也许您应该恢复到此方法的原始版本,并查看分层导航是否开始起作用,如果是这样,则说明您需要将此层逻辑扩展或合并到您的版本中.

Perhaps you should revert to the original version of this method and see if layered navigation starts working, and if so then you know that you need to extend or incorporate this layer logic into your version.

这篇关于自定义产品集合未通过分层导航进行过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆