Welcome to the MetaMod and Chameleon Support Forums.

Before posting, please check out the FAQs.

helpme

 

Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.

 

Hide module if vm category has no items

Hide module if vm category has no items

Hello there,

I use Joomla 3.6.4 with Virtuemart 3.0.18. I would like an example in which i can hide/show a module at Virtuemart category page, when the specific category has no products.

Is this possible?

Thank you in advance

pm4698
Beginner Modder
ranks
useravatar
Offline
13 Posts
Administrator has disabled public posting

Re: Hide module if vm category has no items

Hello there! Anyone any ideas?

pm4698
Beginner Modder
ranks
useravatar
Offline
13 Posts
Administrator has disabled public posting

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

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3319 Posts
User info in posts
Administrator has disabled public posting

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

pm4698
Beginner Modder
ranks
useravatar
Offline
13 Posts
Administrator has disabled public posting

Re: Hide module if vm category has no items

I think i fixed it! I used if($c > 1) and it works like a charm!

pm4698
Beginner Modder
ranks
useravatar
Offline
13 Posts
Administrator has disabled public posting

Re: Hide module if vm category has no items

Ok, that's great. Not sure why >1 works when !=0 didn't... but if it works it works! Well done.

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3319 Posts
User info in posts
Administrator has disabled public posting

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?

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3319 Posts
User info in posts
Administrator has disabled public posting

Board Info

Board Stats:
 
Total Topics:
1675
Total Polls:
6
Total Posts:
5917
Posts this week:
6
User Info:
 
Total Users:
11577
Newest User:
owens65784
Members Online:
0
Guests Online:
137

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