Hide categories without products magento

I have many sites that use the same root category of the main site. Each added product is added to the site to which it was added (wow), as well as to the Main site. However, I would like categories based on each site to be displayed only if there are products on this site.

If I have:

Category1
Category2
Category3

But Site1 has only products in categories1 and category2, while Site2 and Site3 have products of category 2 and category 3; I only want Category1 / 2 to appear on Site1, and only Category2 / 3 only appear on Site2 and Site3.

However, since all products in Site1 / 2/3 are also added to the main site; Category1 / 2/3 will be indicated on the Main Site.

No products are added directly to the main site. It just serves as a repository for other sites.

Now, if there is no really easy way to enable this (as I am sure), it would be as simple as writing my own topic that lists the categories that only have products on the site that the template displays on

I am not new to the technology that Magento uses; therefore, writing your own code is not difficult. However, I would not want to edit it so much that in the future it would be easier to improve my code base with later versions of Magento.

Thanks,

-nelson

+3
source share
2 answers

, , ( ), .

, , magento: Magento . , , , .

, "" , , .

/, .

+2

, .

top.phtml .

<?php $_menu = $this->renderCategoriesMenuHtml(0,'level-top') ?>
<?php if($_menu): ?>
<div>
    <ul id="nav">
        <?php echo $_menu ?>
    </ul>
</div>
<?php endif ?>

.

<?php $_menu = ''?>
<?php $excludeCat = array(); ?>
<?php foreach ($this->getStoreCategories() as $_category): ?>
    <?php if($_category->getProductCount() <=0) {
          $excludeCat[] = $_category->getId(); 
    }
    ?>
    <?php $_menu .= $this->drawItem($_category) ?>
<?php endforeach ?>
<?php if ($_menu): ?>
<div>
    <ul id="nav">
    <?php foreach ($this->getStoreCategories() as $_category): ?>
    <?php if (!in_array($_category->getId(), $excludeCat)) : ?> <?php echo $this->drawItem($_category) ?>
    <?php endif; ?>
    <?php endforeach ?>
    </ul>
</div>
<?php endif; ?>
0

All Articles