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 に答える