1

I want to know how I can get all active and inactive category children's

This code get me only the active childrens.

$parentCategory = Mage::getModel('catalog/category')->load($id);        
$childCategory = Mage::getModel('catalog/category')->getCollection()        
    ->addIdFilter($parentCategory->getChildren())
    ->addAttributeToFilter('name', $categoryName)
    ->getFirstItem()    // Assuming your category names are unique ??
;

Thanks

3 Answers 3

4

Hello Check below code may be help you

    <?php
$id=10;
$collection = Mage::getResourceModel('catalog/category_collection')
    ->addAttributeToSelect('*')
   ->addAttributeToFilter('is_active', array('in' => array(0,1)))
  ->addAttributeToFilter('parent_id', $id);

echo count($collection);
?>
1
  • This works but the is_active filter is useless. is active can only be 0 or 1.
    – Marius
    Nov 14, 2014 at 7:49
2

I know it's a bit late but I just came across this function, getChildrenCategoriesWithInactive, so now I do:

$_category = Mage::getModel('catalog/category')->loadByAttribute('name', 'mycategoryname');
$_subcategories = Mage::getModel('catalog/category')->load($_category->getId())->getChildrenCategoriesWithInactive();
if($_subcategories):
     foreach ($_subcategories as $_subcategory):

etc

0

This what I did

$query = "SELECT cce.entity_id FROM catalog_category_entity as cce left join "
        . "catalog_category_entity_varchar as ccev on cce.entity_id = ccev.entity_id "
        . "where cce.parent_id = :parent_id "
        . "and ccev.attribute_id = 41 and ccev.value = :ccev_value";
$values = array('parent_id' => $id,
                'ccev_value' => $categoryName,                 
        );                    

$result = $readConnection->fetchAll($query,$values);  
if (count($result) > 0){
    return $result[0]['entity_id'];
}else{
    return '';
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.