Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Magento 未通过分层导航筛选自定义产品集合_Magento_Magento 1.8_Layered Navigation - Fatal编程技术网

Magento 未通过分层导航筛选自定义产品集合

Magento 未通过分层导航筛选自定义产品集合,magento,magento-1.8,layered-navigation,Magento,Magento 1.8,Layered Navigation,我已经重写了product List.php类&下面是代码 protected function _getProductCollection() { if (is_null($this->_productCollection)) { $result = array_unique($productIds); $collection = Mage::getResourceModel('catalog/product_collection');

我已经重写了product List.php类&下面是代码

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;
}
工作很好,我还添加了上面提到的分层导航,分层导航也如预期的那样出现

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

我可能在这里出错,但您的覆盖的_getProductCollection方法似乎绕过了分层导航。我不知道您的目标是什么,需要您这样做,但原始版本从分层导航模型Mage_Catalog_model_层注入产品集合:


也许您应该恢复到该方法的原始版本,看看分层导航是否开始工作,如果开始工作,则您知道需要将此层逻辑扩展或合并到您的版本中。

我将magento恢复到其原始版本,产品仍然未列出。在Magento2中,any1是否面临相同的问题?
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);
        }
    }
}