2013-03-29 15 views

答えて

4

、これを試してみてくださいその作業罰金私の最後で

<?php 
$parentCategoryId = 10; 
$categories = Mage::getModel('catalog/category')->load($parentCategoryId)->getChildren(); 
$catArray = explode(',', $categories); 
foreach($catArray as $child) 
{ 
$_child = Mage::getModel('catalog/category')->load($child); 
echo $_child->getName() . '<br />'; 
echo $_child->getUrl() . '<br />'; 
echo $_child->getDescription() . '<br />'; 
} 
?> 
+0

ありがとう、あなたは英雄です –

8

あなたはcurrent_category IDをお持ちの場合は、負荷のカテゴリ

$category = Mage::getModel('catalog/category')->load(id);

count($category->getChildren());

他の方法を確認するには、カウント子供

count($category->getChildrenNodes()); 

$category->getChildrenCount(); 

のためにあなたは、カテゴリかどうかを確認することができますこの方法です子供がいるかどうか。

getChildren()のメソッドは、あなたに子供のカテゴリIDを与え、idに基づいてカテゴリ画像とカテゴリ名を取得できます。

+0

私はあなたのコードを試してみましたが、そのない:$カテゴリに

if (Mage::helper('catalog/category_flat')->isEnabled()) { $childrenCount = $category->getResource()->getChildrenAmount($category); } else { $childrenCount = $category->getResource()->getChildrenCount(); } 

を私はあなたがすでに、としていると仮定します私は子供を数えたときに常に1を表示しますが、子カテゴリが2つある 私はこのコードを入れました $ current_catid = $ this-> getCategoryId(); $ category = Mage :: getModel( 'カタログ/カテゴリ') - > load($ current_catid); エコーカウント($ category-> getChildren()); –

+0

代わりにgetChildre() - > count()メソッドを使うか、count($ category-> getChildrenNodes())を使うこともできます。カウントカテゴリの子供のために – Mufaddal

+0

あなたが私に言ったように私はこれを試しました $ category-> getChildren() - > count(); それは私に致命的なエラーを与える –

1

少し古いが、私は同じソリューションを検索し、Mufaddalのソリューションが動作しませんでした@たしてください。それから私はgetChildrenCategories()を見つけました。

$_category = Mage::registry('current_category'); 
count($_category->getChildrenCategories()); 
0

あなたは

1

実際カテゴリの子カテゴリが存在かを確認する別のオプション...それは私に知らせてフル役立つかどう

<?php 
    $currentCategoryId = Mage::registry('current_category')->getId(); 
    $collection = Mage::getModel('catalog/category')->getCollection() 
     ->addAttributeToFilter('is_active', 1) //only active categories 
     ->addAttributeToFilter('parent_id', $currentCategoryId); 
    $currentCat = Mage::registry('current_category'); 
    $subCategories = Mage::getModel('catalog/category')->load($currentCat->getParentId())->getChildrenCategories(); 

    if($collection->getSize() >= 1){//there some thing....}else{ 

//Get Subcategory.... 


foreach ($subCategories as $subCategoryId): 

        if($subCategoryId->getIsActive()) 
        { $products = Mage::getModel('catalog/category')->load($subCategoryId->getId()) 
        ->getProductCollection() 
        ->addAttributeToSelect('entity_id') 
        ->addAttributeToFilter('status', 1) 
        ->addAttributeToFilter('visibility', 4); 


         <li <?php if($subCategoryId->getId()==$currentCategoryId){?>class="active"<?php } ?>> 
          <a href="<?php echo $subCategoryId->getURL(); ?>"> 
           <?php //echo $subCategoryId->getName()." (".$products->count().")"; ?> 
           <?php echo $subCategoryId->getName(); ?> 
          </a> 
         </li> 
         } endforeach;}?> 

...

おかげ ラヴィを持っています「フラットカタログカテゴリを使用する」オプションが有効になっているかどうかによって異なります。

。したがって、カテゴリをチェックするための最良の方法は、子カテゴリまたはされていない持っている:

$category = Mage::getModel('catalog/category')->load(id); 
関連する問題