2011-08-26 5 views
-1

Magento에 하위 카테고리 목록이있는 카테고리 페이지가 있습니다. 목록에는 이미지와 이름이 있지만 그 하위 카테고리의 설명도 표시하려고합니다. 간단히 추가하려고 시도했습니다.Magento는 카테고리 list.phtml에 하위 카테고리 설명을 표시합니다.

<strong><?php echo $this->htmlEscape($_category->getDescription()) ?></strong> 

하지만 작동하지 않습니다.

편집 : 나는 전통적인 방법으로 하위 범주 얻을 : 나는 ->addAttributeToSelect(’description’)을 추가하여 category.php 파일의 공공 기능 getChildrenCategories($category)를 업데이트하려고했습니다

<?php if (!$_categoryCollection->count()): ?> 
<p class="note-msg"><?php echo $this->__('There are no subcategories matching the selection.') ?></p> 
<?php else: ?> 
<div class="category-products"> 
    <?php $_collectionSize = $_categoryCollection->count() ?> 
    <?php $_columnCount = $this->getColumnCount(); ?> 
    <?php $i=0; foreach ($_categoryCollection as $_category): ?> 
     <?php if ($i++%$_columnCount==0): ?> 
     <ul class="products-grid"> 
     <?php endif ?> 
      <li class="item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>"> 
       <a href="<?php echo $_category->getUrl() ?>" class="product-image"><img class="photo" src="<?php echo $this->getCategoryImage($_category, 214, 184); ?>" width="214" height="184" alt="<?php echo $_category->getName() ?>" /> 
       <strong><?php echo $this->htmlEscape($_category->getName()) ?></strong> 
       <strong><?php echo $_category->getDescription() ?></strong> 
       </a> 
      </li> 
     <?php if ($i%$_columnCount==0 || $i==$_collectionSize): ?> 
     </ul> 
     <?php endif ?> 
    <?php endforeach ?> 
</div> 

을했으나 제대로 동작하지 않습니다.

+0

하위 카테고리는 어떻게 구합니까? 코드를 더 추가하십시오 ... – Simon

답변

3

나는 당신이 잘못하고 있다는 것을 정확히 볼 수는 없지만 아마도 여전히 도움이 될 것입니다. list.phtml에 자식 카테고리 설명을 성공적으로 표시했습니다. 그리고 나 자신을 위해 나를 위해 일하는 것을 적용 할 수 있습니다. 중동 작동 코드의 제거 다운 버전은 다음과 같습니다

<?php $children = explode(",", $this->getCurrentCategory()->getChildren()); ?> 
<div class="category-products"> 
    <ul class="products-grid"> 
     <?php foreach($children as $child): ?> 
      <?php $_child = Mage::getModel('catalog/category')->load($child); ?> 
      <li class="item"><?php echo $_child->getDescription(); ?></li> 
     <?php endforeach; ?> 
    </ul> 
</div> 

당신이하고있는 이상 내 샘플 카탈로그 모델 객체에 getChildren() 메서드를 반환 무엇인지 사이의 큰 차이 범주 ID의 배열을 가져온 다음 범주 ID를 사용하여 해당 자식 범주 모델 인스턴스를로드합니다. 내 기억이 잘못되었을 수도 있지만, Magento 컬렉션에서 반환 된 항목에는 ID로로드 할 때 얻을 수있는 전체 데이터가 들어 있지 않습니다. 이 크게 여부 성능에 영향을 미칠 경우

나는 (내가 컬렉션을로드하는 개별 모델을로드보다 빠릅니다 가정 것) 잘 모르겠어요하지만 ... 그래서 불평 아니에요 작동

희망이 도움이됩니다.

건배, 자크

0

은 내가 그리드 뷰에서 하위 범주를 표시 내가 일하고 있어요 웹 사이트에 상대적으로 같은 생각을 가지고있다. 내가 개별적으로 카테고리/제품 정보를 ID로로드하는 방법을 사용하는 동안, 나는 "Mage :: getModel ('') -> getCollection()"메소드를 사용하는 것을 좋아합니다.

내가 내 하위 범주에 사용했습니다 무엇이며, 한 번에 모든 정보를 잡고으로 나는 그것으로 매우 행복했습니다

<?php 
    if(Mage::registry('current_category')->getId()) { 

     $_currentCategoryId = Mage::registry('current_category')->getId(); 

    } else { //Get Root Category Id if not in a category 

     $_currentCategoryId = Mage::app()->getStore()->getRootCategoryId(); 
    } 

    $_subCategories = Mage::getModel('catalog/category')->getCollection() 
         ->addAttributeToSelect('*') 
         ->addFieldToFilter('parent_id',array('eq' => $_currentCategoryId)) 
         ->addFieldToFilter('include_in_menu',array('eq' => '1')) 
         ->addFieldToFilter('is_active', array('eq' => '1')) 
         ->addAttributeToSort('position', 'asc'); 
?> 
<?php if(count($_subCategories) > 0): ?> 

<!--This is where the sub-category layout would go.--> 

<?php else: ?> 

<!--Do something else if there are no sub-categories.--> 

<?php endif; ?> 

이 보이는 모든 하위 범주를 사로 잡고 다른 페이지에서 템플릿을 표시하도록 선택하면 상점의 기본 카테고리 (루트 카테고리 ID에서)를 가져옵니다. addAttributeToSelect를 사용하면 추가 속성을 정의 할 수 있습니다.

관련 문제