Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.
- Index
- » MetaMod
- » MetaMod General Support
- » [solved]Virtuemart display a module...
[solved]Virtuemart display a module only if category page has products
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
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;
}
- Index
- » MetaMod
- » MetaMod General Support
- » [solved]Virtuemart display a module...
Board Info
- Board Stats:
- Total Topics:
- 1689
- Total Polls:
- 6
- Total Posts:
- 5944
- Posts this week:
- 2
- User Info:
- Total Users:
- 7658
- Newest User:
- carre82601
- Members Online:
- 0
- Guests Online:
- 181
- 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