2012-05-10 23 views
0

我期待有正常的快速搜索,並增加一個功能:來自給定類別的結果首先出現。Magento快速搜索 - 顯示給定類別的結果第一個

到目前爲止,我已修改protected function _getProductCollection()Mage_CatalogSearch_Block_Result這個工作,但它忽略了我想要在兩組結果中應用的自定義搜索結果(例如通過價格或名稱)。

我額外的代碼是:

$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)."')"); 

凡貓2根類別。

那麼,集合在哪裏被排序呢?如果我在這裏提出這個應該做我認爲的訣竅(?)。

+0

另一種可能是訪問'getCurrentOrder ()'和'getCurrentDirection()'從'Toolbar.php'中。我該怎麼做? –

回答

0

它可能不是每個人的情況下工作,但加入以下爲我工作:

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

所以我結束了一個protected function _getProductCollection()的:

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; 
}