2013-03-29 17 views

risposta

4

Si prega di provare questo, il suo bel lavoro alla mia fine

<?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

Grazie amico, sei un eroe –

8

se avete id current_category quindi categoria di carico

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

e verificare count($category->getChildren());

Altri metodi sono per i bambini di conteggio

count($category->getChildrenNodes()); 

$category->getChildrenCount(); 

questo modo è possibile controllare se categoria ha figli o no.

getChildren() i metodi forniscono ID categoria bambini e in base all'ID è possibile ottenere l'immagine della categoria e il nome della categoria.

+0

ho provato il codice, ma la sua non funziona ... mostra sempre 1 quando conto i bambini ma ha 2 figli di categoria ho messo questo codice $ current_catid = $ this-> getCategoryId(); $ category = Mage :: getModel ('catalog/category') -> load ($ current_catid); conteggio echo ($ category-> getChildren()); –

+0

Provate invece i metodi getChildre() -> count() oppure potete usare count ($ category-> getChildrenNodes()); per i bambini della categoria di conteggio – Mufaddal

+0

ho provato questo come mi hai detto $ category-> getChildren() -> count(); mi dà errore fatiscente –

1

Un po 'vecchio, ma ero alla ricerca per la stessa soluzione e @ soluzione Mufaddal non ha funzionato. Poi ho trovato getChildrenCategories().

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

avete un'altra opzione per controllare categoria bambini della categoria esiste o no ..

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

se si tratta di aiuto completo fammi sapere ...

Grazie Ravi

1

realtà dipende dal fatto che l'opzione "Use Flat Catalog Category" sia abilitata o meno.

Pertanto, il metodo migliore per controllare categoria hanno bambini della categoria o non è:

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

con $ categoria suppongo avete già, come:

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