2011-04-20 9 views
15

Magento(ver。1.8.0.0)のカスタムモジュールで、特定の製品の関連製品の一覧を表示しています。カスタム製品コレクションのMagentoレイヤードナビゲーション

これを達成するために、Mage_Catalog_Block_Product_Listクラスを上書きして自分のモジュールを作成しました。基本的にはここに

は、それがどのように動作するかです:

私は製品entity_idをキャッチし、私は

list.phpと呼ばれている私のカスタム書かれたブロックの中でそれを使用することができますので、私はレジストリに製品を保管コントローラからここでは、製品のコレクションを埋める方法は次のとおりです。

protected function _getProductCollection() 
{ 
    if (is_null($this->_productCollection)) { 
     $prod = Mage::registry('chosenproduct'); 
     $this->_productCollection = $prod->getRelatedProductCollection() 
      ->addAttributeToSelect('required_options') 
      ->addAttributeToFilter(array(array('attribute'=>'accessory_manufacturer','neq'=>false))) 
      ->addAttributeToSort('position', 'asc') 
      ->addStoreFilter() 
      ->setPageSize(30) 
      ->setCurPage(1); 
     ; 

     $this->_addProductAttributesAndPrices($this->_productCollection); 
     Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($this->_productCollection); 
     $this->setProductCollection($this->_productCollection); 
    } 

    return $this->_productCollection; 
} 

私はまた、層状のナビゲーションが表示さを確認するために私のカスタムモジュールのレイアウトの.xmlに次のように追加しました:

<reference name="left"> 
     <block type="catalog/layer_view" name="catalog.leftnav" after="currency" template="catalog/layer/view.phtml"/> 
    </reference> 

階層的なナビゲーションが表示されますが、上記で追加した方法で使用されているカスタムコレクションではなく、すべての製品をコレクションと見なしているようです。

私も、私はこの$layer = Mage::getSingleton('catalog/layer');

を使用してカタログ/層を得ることができることを知っている層のクラスもprepareProductCollectionとsetCollectionというメソッドを持っていますが、何らかの理由で、私はそれを動作させることはできません。

これに関する助力?

基本的には、カスタムコレクションに含まれる製品のレイヤードナビゲーションが必要です。

ありがとう、

答えて

15

私は欲しかったことを達成できました。私はMage_Catalog_Model_Layerクラスの両方を上書きしているとMage_Catalog_Model_Category

の両方が、新しい変数は$ _customCollectionと呼ばれています:protected $_customProductCollection;

私は両方のクラスでgetProductCollection()を上書きしていると私は、メソッドの先頭でこれを追加しました:

if(isset($this->_customProductCollection)){ 
     return $this->_customProductCollection; 
    } 

私はこの両方のクラスの中でこの "customProductCollection"を設定できる方法もあります。それが設定されると、レイヤーナビゲーション/カテゴリの残りのデータはこのコレクションに基づいています。

;)

+2

この設定方法とは何ですか、どこから呼び出すのですか? – easymoden00b

関連する問題