2
votes

On a magento site, we've got one menu where we would like to always show all the products below a parent node, let's say we have got

Root
- category 1
- category 2
---- subcategory 2-1
---- subcategory 2-2

When clicking on category 2, we would like to see all products assigned to category2, 2-1 and 2-2. When clicking on Root, it should show ALL the products of the store. However, when selecting category1 from within the other sections of the store, we would like to have a default behaviour.

Normally, we would just assign a product to various categories - but as we only want this behaviour on one single section of the site, I'm not sure how to handle this.

Any ideas?

Thanks in advance.

2

2 Answers

0
votes

You can use the "Anchor" attribute of a category to achieve this, this setting controls how Magento 'rolls up' products from categories below the one it's applied to and in doing so also sets a scope for layered navigation controls (if you are using them).

To work as described you'll need to tick/untick the "Is Anchor" box on each child category under the parent appropriately.

Go to Catalog > Manage Catagories > Select a category > Display Settings > Is Anchor? (tick)

To get the behaviour you're after you'll need to set the "Is Anchor" box as follows:

Root - tick
- category 1 - untick
- category 2 - tick
-- foreach child of category 2 - tick

Then reindex anything category related.

-1
votes

Display top level and all sub categories :

$collection= Mage::helper('catalog/category');
$categories = $collection->getStoreCategories();
$currentCategory = Mage::registry('current_category');


<ul>
    <?php foreach($categories as $category): ?>
    <li><a href="<?php echo $collection->getCategoryUrl($category) ?>">
        <?php echo $category->getName() ?>
        </a>
    <?php $category = Mage::getModel('catalog/category')->load($category->getId()) ?>
    <?php $subCategory = $category->getChildrenCategories() ?>
    <?php if(count($subCategory > 0)): ?>
        <ul>
            <?php foreach($subCategory as $_subCategory):) ?>
            <li>
                <a href="<?php echo $collection->getCategoryUrl($_subCategory) ?>">
                   <?php echo $_subCategory->getName() ?>
                </a>
            </li>
            <?php endforeach; ?>
        </ul>
     <?php endif; ?>
     </li>
     <?php endforeach; ?>
 </ul>