2011-11-24 4 views
0

Magento 홈페이지에는 현재 모든 제품을 잘 보여주는이 코드 스 니펫이 있습니다. 내가 추가 할 때마다 제품 ID 2의 자식이기 때문에Magento 블록으로 여러 카테고리를 표시하는 방법

{{block type="catalog/product_list" category_id="2" template="catalog/product/list.phtml"}} 

대략, 내 카테고리 트리이

id 2 (root cat) 
-> id 3 
-> id 4 
-> id 5 

비슷합니다 - 모든 제품은 홈페이지에 표시됩니다. 내가 쫓고있는 것은 홈 페이지 제품 목록에서 특정 ID (카테고리)를 제외시킬 수있는 솔루션입니다.

나는 아무 성공 다음은이 조각을 시도했다 :

{{block type="catalog/product_list" category_id="2,3,5" template="catalog/product/list.phtml"}} 

답변

2

에 코드를 {{block type="catalog/product_list" category_id="2,3,5" template="catalog/product/list.phtml"}}가 작동하지 않습니다 블록 Mage_Catalog_Block_Product_List 부하가 하나 개의 카테고리 $category = Mage::getModel('catalog/category')->load($this->getCategoryId());을하기 때문이다.

나는 다른 범주 ID로 두 번 이상 블록을 사용할 수 있습니다, 당신의 문제에 대한 두 가지 솔루션을 참조하십시오

{{block type="catalog/product_list" category_id="2" template="catalog/product/list.phtml"}} 
{{block type="catalog/product_list" category_id="3" template="catalog/product/list.phtml"}} 
{{block type="catalog/product_list" category_id="5" template="catalog/product/list.phtml"}} 

을 또는 블록 Mage_Catalog_Block_Product_List을 덮어 쓰기이 부분의 동작을 변경

 if ($this->getCategoryId()) { 
      $category = Mage::getModel('catalog/category')->load($this->getCategoryId()); 
      if ($category->getId()) { 
       $origCategory = $layer->getCurrentCategory(); 
       $layer->setCurrentCategory($category); 
      } 
     } 
     $this->_productCollection = $layer->getProductCollection(); 

     $this->prepareSortableFieldsByCategory($layer->getCurrentCategory()); 

     if ($origCategory) { 
      $layer->setCurrentCategory($origCategory); 
     } 
+0

소리 대답 해 주셔서 감사합니다. 나중에 그 방법을 사용할 것입니다 - 지금은 시간이 제 편이 아닙니다. 감사! – tjw

관련 문제