2014-09-24 47 views
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; 
} 

工作正常,我也加入了分层导航提到here和分层的导航表现为代码预期。

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

+0

是否有任何1在Magento2中面临同样的问题? – 2016-10-05 07:03:29

回答

2

我可能在这里是错误的,但是您重写的_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); 
     } 
    } 
} 

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

+0

我将magento还原为原始版本,产品仍未列出。 – sousatg 2016-03-09 12:25:10