0

I have category structure like this.

  1. Shirts:

    • Male.
    • Female.
  2. Pents:

    • Male.
    • Female.

What I'm trying is get the category ID by giving passing the parameter like 'Petns/Male' or something like this. I spent an almost complete day to find a solution but didn't get any help.

Looking forward to Hint/Solution.

Thanks

1
  • Please explain in details so that we can understand easily to solve your problem. Commented Apr 20, 2017 at 10:43

1 Answer 1

0

Below code Put in your phtml file. @parentCategoryId pass category id.

<?php
$categoryChild = Mage::helper('your_helper')->getCustomMenuCategory($parentCategoryId);
if (count($categoryChild) > 0) {
    ?>
    <div class="child-category">
        <ul class="child-subcategories">
            <?php foreach ($categoryChild as $child): ?>
                <li>                    
                    <a href="<?php echo $child->getUrl() ?>">
                        <span><?php echo $child->getName() ?></span></a>
                </li>
            <?php endforeach; ?>
        </ul>
    </div>

and below in your helper

public function getCustomMenuCategory($categoryId) {

    try {            
            $categoryChild = Mage::getModel('catalog/category')->load($categoryId)->getChildrenCategories();
            if (count($categoryChild) > 0) {
                return $categoryChild;
            } else {
                $parentcategories = Mage::getModel('catalog/category')->load($categoryId)->getParentCategory()->getChildrenCategories();
                return $parentcategories;
            }
        } 
    } catch (Exception $ex) {
        Mage::log($ex, null, 'subcategory.log');
    }
}

Hope this will work. If this will work for you then accept it.

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.