Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.
- Index
- » MetaMod
- » MetaMod General Support
- » Menu position for each category and...
Menu position for each category and all of it's child categories in VM
Menu position for each category and all of it's child categories in VM
Hi,
I need a recipe for positioning a different menu for each category in virtuemart and all of the child categories under it
for example
- Cat1
- - Cat1.1
- - Cat1.2
- - Cat1.3
- - - Cat1.3.1
- - - Cat1.3.2
- Cat2
- - Cat2.1
- - Cat2.2
- - Cat2.3
- - - Cat2.3.1
- - - Cat2.3.2
I need to assign a menu for each first level category that will appear on it and also on all of it's child categories (sub-categories)
Please help
Re: Menu position for each category and all of it's child categories in VM
Hi Masterde,
hmm, that's a good question. I was going to suggest this page but realised that that page is for article categories, not VM categories.
The biggest danger with this recipe is having to do too many database calls if the product is nested too deep in categories.
Can you tell me if there's a maximum depth of categories that you will be using? In the example above there are 3 levels. I can probably make a database query that can search 3 levels deep all in one query - or more, if I know what the maximum depth is going to be. So can you tell me the maximum depth?
Cheers,
Stephen
Re: Menu position for each category and all of it's child categories in VM
Ok, here's a very cool recipe with a maximum depth of 5. This recipe finds the category id of the top-level category (or categories) that this product has been assigned to. Then at the bottom of the recipe, you put in your own checks for particular top-level category ids, then return appropriate module ids for them.
There's just 1 "gotcha" - if your product is in more than 1 top category, then the way this recipe is set up, you'll only get the module(s) corresponding to that first category detected. I hope that's not a problem.
Code:
/* this top section does a lookup if you are on a product details page. */
/* you can delete this section if you don't want the modules on product details pages. */
if ($option == "com_virtuemart" and JRequest::getVar("page") == "shop.product_details" ) {
$product_id = JRequest::getInt("product_id");
$query = "select distinct
coalesce(
cx5.category_child_id,
cx4.category_child_id,
cx3.category_child_id,
cx2.category_child_id,
cx1.category_child_id )
from #__vm_product_category_xref pcx
left outer join #__vm_category_xref cx1 on pcx.category_id = cx1.category_child_id
left outer join #__vm_category_xref cx2 on cx1.category_parent_id = cx2.category_child_id
left outer join #__vm_category_xref cx3 on cx2.category_parent_id = cx3.category_child_id
left outer join #__vm_category_xref cx4 on cx3.category_parent_id = cx4.category_child_id
left outer join #__vm_category_xref cx5 on cx4.category_parent_id = cx5.category_child_id
where pcx.product_id = $product_id";
$db->setQuery( $query );
$res = $db->loadResultArray();
}
/* end of product details page section */
if ($option == "com_virtuemart" and JRequest::getVar("page") != "shop.product_details" ) {
$category_id = JRequest::getInt("category_id");
if ($category_id > 0) {
$query = "select distinct
coalesce(
cx5.category_child_id,
cx4.category_child_id,
cx3.category_child_id,
cx2.category_child_id,
cx1.category_child_id )
from #__vm_category_xref cx1
left outer join #__vm_category_xref cx2 on cx1.category_parent_id = cx2.category_child_id
left outer join #__vm_category_xref cx3 on cx2.category_parent_id = cx3.category_child_id
left outer join #__vm_category_xref cx4 on cx3.category_parent_id = cx4.category_child_id
left outer join #__vm_category_xref cx5 on cx4.category_parent_id = cx5.category_child_id
where cx1.category_child_id = $category_id";
$db->setQuery( $query );
$res = $db->loadResultArray();
}
}
/* here's where to customise the rules */
if ( is_array($res) and count($res) > 0 ) {
/* replace VVV, WWW, XXX, YYY etc with the module ids to return for each top-level category */
if ( in_array(2,$res) ) return VVV; /* module id VVV for top-level cat 2 */
if ( in_array(3,$res) ) return WWW;
if ( in_array(4,$res) ) return XXX;
if ( in_array(5,$res) ) return YYY;
}
Re: Menu position for each category and all of it's child categories in VM
Dear Stephen Brandon,
Thank you for you efforts It's exactly as I wanted it, but I have something else to ask you
Can you please give me a recipe that does the same thing but not for a top-level category for a mid-level category
What I want is to show a banner for a sub-category and for all sub-categories and products under it.
Thanks in advance
A Fan of MetaMod Pro and The Team Behind It
Re: Menu position for each category and all of it's child categories in VM
Is it just a particular category that you want to target, or do you have several different categories that might need a different banner for each one?
There are several ways of setting this up and I'm just thinking of the most appropriate way to do it.
Cheers,
Stephen
Re: Menu position for each category and all of it's child categories in VM
Ok I just went ahead with this anyway - I think this is going to suit. Can you let me know if it works for you?
It should detect if the stated category ids appear in the list of "parents" for the given product or category. Like the last one, it can check up to 5 levels deep.
Code:
/* this top section does a lookup if you are on a product details page. */
/* you can delete this section if you don't want the modules on product details pages. */
if ($option == "com_virtuemart" and JRequest::getVar("page") == "shop.product_details" ) {
$product_id = JRequest::getInt("product_id");
$query = "select distinct
cx5.category_child_id as c5,
cx4.category_child_id as c4,
cx3.category_child_id as c3,
cx2.category_child_id as c2,
cx1.category_child_id as c1
from #__vm_product_category_xref pcx
left outer join #__vm_category_xref cx1 on pcx.category_id = cx1.category_child_id
left outer join #__vm_category_xref cx2 on cx1.category_parent_id = cx2.category_child_id
left outer join #__vm_category_xref cx3 on cx2.category_parent_id = cx3.category_child_id
left outer join #__vm_category_xref cx4 on cx3.category_parent_id = cx4.category_child_id
left outer join #__vm_category_xref cx5 on cx4.category_parent_id = cx5.category_child_id
where pcx.product_id = $product_id";
$db->setQuery( $query );
$res = $db->loadRowList();
}
/* end of product details page section */
if ($option == "com_virtuemart" and JRequest::getVar("page") != "shop.product_details" ) {
$category_id = JRequest::getInt("category_id");
if ($category_id > 0) {
$query = "select distinct
cx5.category_child_id as c5,
cx4.category_child_id as c4,
cx3.category_child_id as c3,
cx2.category_child_id as c2,
cx1.category_child_id as c1
from #__vm_category_xref cx1
left outer join #__vm_category_xref cx2 on cx1.category_parent_id = cx2.category_child_id
left outer join #__vm_category_xref cx3 on cx2.category_parent_id = cx3.category_child_id
left outer join #__vm_category_xref cx4 on cx3.category_parent_id = cx4.category_child_id
left outer join #__vm_category_xref cx5 on cx4.category_parent_id = cx5.category_child_id
where cx1.category_child_id = $category_id";
$db->setQuery( $query );
$res = $db->loadRowList();
}
}
/* here's where to customise the rules */
if ( is_array($res) and count($res) > 0 ) {
foreach ($res as $r) {
/* replace VVV, WWW, XXX, YYY etc with the module ids to return for each category */
if ( in_array(2,$r) ) return VVV; /* module id VVV for top-level cat 2 */
if ( in_array(3,$r) ) return WWW;
if ( in_array(4,$r) ) return XXX;
if ( in_array(5,$r) ) return YYY;
}
}
Re: Menu position for each category and all of it's child categories in VM
Hi Touchdowntech,
this thread is quite old, and lots of that code is now integrated into JomGenius. In particular JomGenius has a parameter called "ancestor_category_ids" that contains all the category ids of the parent, grandparent etc categories for the current item (or the current category if you are on a category page).
So you can do things like this:
$vm = JomGenius("virtuemart");
if ($vm->check("ancestor_category_ids = 5")) return XXX;
// replace XXX with module id to display
That code snippet will display the module if the current product (or category) has a parent, grandparent etc that is category "5". In other words, ALL categories and ALL products "beneath" category 5 will have the module displayed on them.
Is that what you are after?
Cheers,
Stephen
- Index
- » MetaMod
- » MetaMod General Support
- » Menu position for each category and...
Board Info
- Board Stats:
- Total Topics:
- 1689
- Total Polls:
- 6
- Total Posts:
- 5942
- Posts this week:
- 2
- User Info:
- Total Users:
- 7628
- Newest User:
- horlogekorting34
- Members Online:
- 0
- Guests Online:
- 102
- 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