Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.
- Index
- » MetaMod Pro
- » MetaMod Pro General Support
- » Hide module if vm category has no items
Hide module if vm category has no items
Re: Hide module if vm category has no items
Hi,
there's no direct way to get the number of products in a given category (i.e. with JomGenius) but you should be able to get the info with a database call. Once you have that, MetaMod can do the module switching.
Try this:
$vm = JomGenius("virtuemart");
if (!$vm->check("pagetype = category")) return; // show nothing if not on a category page
$cat = $vm->info("category_id");
if (!$cat) return; // show nothing if we can't get a category id
$query = 'select count(*) from #_' . '_virtuemart_product_categories where virtuemart_category_id = \'' . (int)$cat . '\'';
$db->setQuery($query);
$c = $db->loadResult();
if ($c == 0) return XXX;
// replace XXX with module id of module to display on category pages with no products
Re: Hide module if vm category has no items
Hello there!
It looks like at 90% of the categories it works like a charm. In my case i used
if($c !=0) in order to show module to categories that contain products.
But as i told you, if for example i have in total 100 categories in 90 categories its working but in some sub categories it does not.
Can you think of a reason of not working to a few categories?
Thank you in advance
Re: Hide module if vm category has no items
Re: Hide module if vm category has no items
Actually one reason it didn't work may be that the SQL code above does not check to see if the products are actually published/showing or not. It just checks to see if the products are associated with a category. Could it be that for the categories that weren't working (i.e. not showing as empty when they should have been) actually contained a product that was disabled/unpublished in some way?
- Index
- » MetaMod Pro
- » MetaMod Pro General Support
- » Hide module if vm category has no items
Board Info
- Board Stats:
- Total Topics:
- 1689
- Total Polls:
- 6
- Total Posts:
- 5942
- Total Posts Today:
- 1
- User Info:
- Total Users:
- 7620
- Newest User:
- giachungjsc
- Members Online:
- 0
- Guests Online:
- 320
- Online:
- There are no members online
Forum Legend:
Topic
New
Locked
Sticky
Active
New/Active
New/Locked
New Sticky
Locked/Active
Active/Sticky
Sticky/Locked
Sticky/Active/Locked