0

1つの機能を追加して、通常のクイック検索を実行したいと考えています。特定のカテゴリの結果が最初に表示されます。

これまでに変更 protected function _getProductCollection()を加えましたがMage_CatalogSearch_Block_Result、これは機能しますが、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)."')"); 

ここで、猫2はルートカテゴリです。

では、コレクションはどこにソートされていますか?これをそこに移動すると、私が信じているトリックを実行するはずです(?)。

4

1 に答える 1

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;
}
于 2012-05-10T14:12:06.157 に答える