Question

I have many sites that use the same root category of the Main Site. Each product that is added is added to the site it was added to (wow.) and also the Main Site. However, I would like categories on a per site basis to only appear if there are products on that site.

If I have:

Category1
Category2
Category3

But Site1 only has products in Category1 and Category2, whereas Site2 and Site3 have products in Category2 and Category3; I only want Category1/2 to appear on Site1 and only Category2/3 to only appear on Site2 and Site3.

However, because all products in Site1/2/3 are also added to the Main Site; the Main Site would list Category1/2/3.

No products are added directly to the Main Site. It simply serves as a repository for the other sites.

Now, if there is no really easy way to enable this (as I'm sure), would it be as simple as writing my own theme that lists categories that only have products on the site that the template is being displayed on?

I am not a novice in the technologies that Magento uses; so writing custom code is no problem. I would, however, not like to edit it that much so that upgrading my code base would be easier in the future with later versions of Magento.

Thanks,
-nelson

Was it helpful?

Solution

Well, what you can do is, create your own helper with a collection (through a model), and then filter the collection based on product count.

Only a rough draft, but I've posted some code in another magento related question: Magento products by categories. You can see how and when it adds the products count, I'd filter again when this is done.

I don't think this is extremely "great" in terms of performance, so instead of using their model classes, you could write your own, extending it and adding default filters, or shortcutting directly to the database.

As long as you stay in your skin/template, there are no larger issues with updating.

OTHER TIPS

this is a simple solution to hide categories that might help you .

The original contents of the top.phtml file should look like below.

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

Replace the code above with this code below.

<?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; ?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top