A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2008 yearHide categories that have no products magento - page 1
User InfoPosts
Hide categories that have no products magento#1
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

posted date: 2008-12-16 16:17:00


Re: Hide categories that have no products magento#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2008-12-16 16:17:01


Re: Hide categories that have no products magento#3
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.

posted date: 2008-12-19 03:43:00


Re: Hide categories that have no products magento#4
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; ?>

posted date: 2012-07-08 10:34:00


select page: « 1 »
Copyright ©2008-2017 www.momige.com, all rights reserved.