<dt class="odd"><?php echo $this-> __('Shop By CATEGORY')?></dt>
            <dd class="odd" id="cssmenu">
                
                    <ul>
                        <?php
                            $product_id = Mage::registry('current_product');
                            $categoryIds = $product_id->getCategoryIds();
                              if(count($categoryIds) ){
                                    $firstCategoryId = $categoryIds[0];
                                    $_category = Mage::getModel('catalog/category')->load($firstCategoryId);
                                    //echo $_category->getId();
                                }
                            $_helper = Mage::helper('catalog/category');
                            $_categories = $_helper->getStoreCategories();
                            // $currentCategory = Mage::registry('current_category');
                            // $currentCategoryId= Mage::registry('current_category')->getId();
                            $currentCategoryId= $_category->getId();
                            $rootCategoryId = Mage::app()->getStore()->getRootCategoryId();
                            $rootCategory = Mage::getModel('catalog/category')->load($currentCategoryId);
                            $childIds = explode(',',$rootCategory->getChildren());
                            if (count($childIds) > 0):
                        ?>
                        <?php 
                            foreach($childIds as $_category):
                                $_category = Mage::getModel('catalog/category')->load($_category);
                        ?>
                                <li>
                                    <h3 class="">
                                            <!-- <a href="<?php echo $_helper->getCategoryUrl($_category) ?>"> -->
                                                <?php echo $_category->getName() ?>
                                            <!-- </a> -->
                                    </h3>
                                    <?php
                                     
                                    if ($_category->getChildren() != ''):
                                     
                                    $allsubchild = explode(',',$_category->getChildren());
                                    ?>
                                    <ul style="display: none;">
                                    <?php foreach($allsubchild as $_sub):
                                    $_subcategory = Mage::getModel('catalog/category')->load($_sub);
                                    ?>
                                    <li>
                                     
                                    <a href="<?php echo $_helper->getCategoryUrl($_subcategory) ?>">
                                    <?php echo $_subcategory->getName() ?>
                                    </a>
                                    </li>
                                    <?php endforeach; ?>
                                    </ul>
                                    <?php endif; ?>
                                </li>
                        <?php endforeach; ?>
                        <?php endif; ?>
                    </ul>
            </dd>

Categories: Magento

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *