2012-05-10 13 views
0

通常のクイック検索を希望していますが、1つの機能が追加されました。Magentoクイック検索 - 指定されたカテゴリの結果を最初に表示

protected function _getProductCollection()Mage_CatalogSearch_Block_Resultに変更されていますが、これは機能しますが、結果の2つのグループに適用するカスタム検索結果(価格や名前など)は無視されます。

私の追加のコードは次のとおりです。

猫2は、ルートカテゴリで
$initial = $this->_productCollection->getAllIds(); 
$this->_productCollection->addCategoryFilter(Mage::getModel('catalog/category')->load(3)); 

$newids = $this->_productCollection->getAllIds();//$this->_productCollection->getAllIds(); 

$merged_ids = array_merge($newids, $initial); 
$merged_ids = array_unique($merged_ids); 

$this->_productCollection->addCategoryFilter(Mage::getModel('catalog/category')->load(2)); 

$this->_productCollection->getSelect()->order("find_in_set(e.entity_id,'".implode(',',$merged_ids)."')"); 

したがって、コレクションはどこでソートされていますか?私がこれを動かすと、私は信じるトリックをするべきです(?)。

+0

() 'と' getCurrentDirection() 'を' Toolbar.php'から削除します。どうすればいい? –

答えて

0

それはすべての人の状況で動作しますが、以下を追加することが私のために働いていないことがあります。

$this->_productCollection->setOrder($this->getRequest()->getParam('order'), $this->getRequest()->getParam('dir')); 

だから私はのprotected function _getProductCollection()になってしまった:代替 `getCurrentOrderにアクセスするかもしれない

protected function _getProductCollection() 
{ 
    if (is_null($this->_productCollection)) { 
     $this->_productCollection = $this->getListBlock()->getLoadedProductCollection(); 
    } 
    $this->_productCollection->setOrder($this->getRequest()->getParam('order'), $this->getRequest()->getParam('dir')); 
    $initial = $this->_productCollection->getAllIds(); 
    $this->_productCollection->addCategoryFilter(Mage::getModel('catalog/category')->load(3)); 

    $newids = $this->_productCollection->getAllIds();//$this->_productCollection->getAllIds(); 

    $merged_ids = array_merge($newids, $initial); 
    $merged_ids = array_unique($merged_ids); 

    $this->_productCollection->addCategoryFilter(Mage::getModel('catalog/category')->load(2)); 

    $this->_productCollection->getSelect()->order("find_in_set(e.entity_id,'".implode(',',$merged_ids)."')"); 

    return $this->_productCollection; 
} 
関連する問題