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.

 

[solved]Virtuemart display a module only if category page has products

[solved]Virtuemart display a module only if category page has products

Is that posible to display a module only if category page have products?

Thank you

Edited By: metamodguy
06-Nov-13 19:30:47

patben
Beginner Modder
ranks
useravatar
Offline
12 Posts
Administrator has disabled public posting

Re: [solved]Virtuemart display a module only if category page has products

Hi,

this is not one of the built-in functions, but is not too hard to do with a little PHP. Try the following:

$vm = JomGenius("virtuemart");
$cat = $vm->info("category_id");
if ($cat) {
  $db->setQuery("select count(*) from #_" . "_virtuemart_products p"
    . ", #_" . "_virtuemart_product_categories pc "
    . " where pc.virtuemart_category_id = " . (int)$cat
    . " and pc.virtuemart_product_id = p.virtuemart_product_id "
    . " and p.published = 1";
  $num = $db->loadResult();
  if ($num > 0) return XXX;
}

// replace XXX with the module id of the module to display if category has no items.


Cheers,
Stephen

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
3328 Posts
User info in posts
Administrator has disabled public posting

Re: [solved]Virtuemart display a module only if category page has products

it not works, i want to display a module if category has products

Thank you

patben
Beginner Modder
ranks
useravatar
Offline
12 Posts
Administrator has disabled public posting

Re: [solved]Virtuemart display a module only if category page has products

Ooops, just realised there was a missing ")":

$vm = JomGenius("virtuemart");
$cat = $vm->info("category_id");
if ($cat) {
  $db->setQuery("select count(*) from #_" . "_virtuemart_products p"
    . ", #_" . "_virtuemart_product_categories pc "
    . " where pc.virtuemart_category_id = " . (int)$cat
    . " and pc.virtuemart_product_id = p.virtuemart_product_id "
    . " and p.published = 1");
  $num = $db->loadResult();
  if ($num > 0) return XXX;
}


Also, please note that this will display on product pages as well as category pages. If you ONLY want it on category pages, do the following instead:

$vm = JomGenius("virtuemart");
$cat = $vm->info("category_id");
if ($cat and $vm->check("pagetype = category")) {
  $db->setQuery("select count(*) from #_" . "_virtuemart_products p"
    . ", #_" . "_virtuemart_product_categories pc "
    . " where pc.virtuemart_category_id = " . (int)$cat
    . " and pc.virtuemart_product_id = p.virtuemart_product_id "
    . " and p.published = 1");
  $num = $db->loadResult();
  if ($num > 0) return XXX;
}

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
3328 Posts
User info in posts
Administrator has disabled public posting

Re: [solved]Virtuemart display a module only if category page has products

Thank you very much the first code works.
The second don't work but the first suit my case.

patben
Beginner Modder
ranks
useravatar
Offline
12 Posts
Administrator has disabled public posting

Board Info

Board Stats:
 
Total Topics:
1679
Total Polls:
6
Total Posts:
5933
Posts this week:
3
User Info:
 
Total Users:
4397
Newest User:
tull687318
Members Online:
0
Guests Online:
235

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