2

我已经覆盖了产品 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,但产品列表不会被所选过滤器过滤。请指导我如何在产品集合中应用过滤器

4

1 回答 1

4

我在这里可能是错的,但是您覆盖的_getProductCollection()方法似乎绕过了分层导航。我不知道您的目标是什么要求您这样做,但原始版本从分层导航模型中获取产品集合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);
        }
    }
}

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

于 2015-02-11T00:11:45.193 回答