2013-06-17 2 views
0

검색 상자를 사용하여 제품을 검색 할 때마다 왼쪽의 범주별로 필터가 있습니다. 이 필터를 만드는 코드는 다음과 같습니다.Magento - 계층 적 탐색의 카테고리 설정

여기에는 필터의 기본 카테고리 만 표시되며 하위 카테고리를 표시하고 싶습니다. 이 코드로 프로그래밍 방식으로 다른 카테고리를 설정하려고 시도했습니다.

<?php 
    $layer = Mage::getSingleton('catalog/layer'); 
    $_categ = Mage::getModel('catalog/category')->load(5); 
    $layer->setCurrentCategory($_categ); 
?> 

...하지만 변경된 사항은 없습니다. 이견있는 사람?

답변

3

템플릿에서 레이어 싱글 톤의 다른 범주를 설정하려고하면 모든 처리가 이미 적용된 것이므로 너무 늦습니다.

public function getCurrentCategory() 
{ 
    $category = $this->getData('current_category'); 

    if (is_null($category)) { 
     if ($category = Mage::registry('current_category')) { 
      $this->setData('current_category', $category); 
     } 
     else { 
      $category = Mage::getModel('catalog/category')->load(5); // Put here the ID of the category you want to use as basis for category filtering 
      $this->setData('current_category', $category); 
     } 
    } 

    return $category; 
} 
: 당신이 할 수있는 일

app/code/local/Mage/CatalogSearch/Model/로 파일 app/code/core/Mage/CatalogSearch/Model/Layer.php을 복사하고 다음과 같이보고, 기본 Mage_Catalog_Model_Layer::getCurrentCategory() 방법의 수정 된 버전을 추가하는 것입니다

관련 문제