2

I am able to get the list of categories of a current store as menu items using code:

<?php $_helper = Mage::helper('catalog/category') ?>
<?php $_categories = $_helper->getStoreCategories() ?>
<?php $currentCategory = Mage::registry('current_category') ?>
<?php if (count($_categories) > 0): ?>
        <?php foreach($_categories as $_category): ?>
            <li>
                <a href="<?php echo $_helper->getCategoryUrl($_category) ?>">
                    <?php echo $_category->getName() ?>
                </a>
                <?php $_category = Mage::getModel('catalog/category')->load($_category->getId()) ?>
                <?php $_subcategories = $_category->getChildrenCategories() ?>
                <?php if (count($_subcategories) > 0): ?>
                    <ul>
                        <?php foreach($_subcategories as $_subcategory): ?>
                            <li>
                                <a href="<?php echo $_helper->getCategoryUrl($_subcategory) ?>">
                                    <?php echo $_subcategory->getName() ?>
                                </a>
                            </li>
                        <?php endforeach; ?>
                    </ul>
                <?php endif; ?>
            </li>
        <?php endforeach; ?>
<?php endif; ?>

But, how do I get top level categories as well as all subcategories of a specific store using store id? I want to include main store categories as menu items in the second store.

2

See the file app\code\core\Mage\Catalog\Helper\Category.php on getStoreCategories() method. You can copy this to your own helper and modify the first line.

$parent     = Mage::app()->getStore($your_store_id)->getRootCategoryId();

Set $your_store_id variable to store_id of your choice.

| improve this answer | |
  • I am getting following error Fatal error: Call to a member function getStoreCategories() on a non-object in app/design/frontend/default/sales_store/template/page/html/topmenu.phtml on line 41 – FlourishDNA Jun 18 '15 at 3:48
  • I tried to implement it by using getStoreCategories() method as you mentioned but I keep getting and error and I am very new to magento so can you give me an example of the code? – FlourishDNA Jun 18 '15 at 4:25
  • Give me something that I can work with. Where did you get the code above? Did you write this code yourself? If not, which template file is it? What magento version are you using? – Vernard Luz Jun 18 '15 at 9:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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