2012-05-10 1 views
0

하나의 기능을 추가하여 일반적인 빠른 검색을 원합니다 : 특정 카테고리의 결과가 먼저옵니다.Magento 빠른 검색 - 주어진 카테고리의 결과를 먼저 표시합니다.

지금까지 나는 Mage_CatalogSearch_Block_Result에서 protected function _getProductCollection()을 수정했지만 두 그룹의 결과 내에서 적용하려는 맞춤 검색 결과 (예 : 가격 또는 이름)를 무시합니다.

내 추가 코드는 다음과 같습니다

고양이 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()'을 호출합니다. 어떻게해야합니까? –

답변

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