2014-09-24 59 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