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.

 

Module not showing on detail page of specific category for shopr group

Module not showing on detail page of specific category for shopr group

Hi, I like to show a module on the product detail pages of all the product under a certain category. And this module can only be shown to certain shopper group. I used the below code, but it is not working. The user group condition is working but when i added the category condition and it stopped working.

126 is the module i want to display and is positioned to this metamod module.

if ($user->usertype == "Registered") {
$id = (int)$user->id;
$query = "SELECT  shopper_group_id FROM #__vm_shopper_vendor_xref " .
   " WHERE user_id = '$id'";
$db->setQuery( $query, 0, 1 );
$row = $db->loadObject();
$groupid = $row->shopper_group_id;
if ($groupid == 6) return 126; /* for VM shopper group xxx, use module xxx */
else return xxx;
}

  if ($category_id == "28") return 126;
  return xxx; /* when viewing any other product not mentioned above */
}

will.chen
Beginner Modder
ranks
useravatar
Offline
12 Posts
Administrator has disabled public posting

Re: Module not showing on detail page of specific category for shopr group

Hi Will,

I'd actually do this with the built-in JomGenius support. It'll be easier. There are a couple of problems in the code above but I'll ignore those and just show you an easier way:

$vm = JomGenius("virtuemart");
if ($vm->check("shopper_group = 6, 7")) return XXX;
if ($vm->check("category_id = 28, 29")) return YYY;
return ZZZ; // if user is not in group 6 or 7,
            // and item is not in cat 28 or 29
// Note: Replace XXX, YYY and ZZZ with module ids to use
// in each case.


This way, the check for shopper group is done first. If the user is not in one of the groups, then the category of the item is checked. If it's not in that category, then the fallback module id is used (ZZZ).

You can learn more about JomGenius here:

http://www.metamodpro.com/jomgenius/par … andcheckvm

Hope this helps,
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
3312 Posts
User info in posts
Administrator has disabled public posting

Re: Module not showing on detail page of specific category for shopr group

Hello Stephen:

Thanks for your reply. But sorry it is still now working. I used the below code:
The result is that only category 28 shows mod 126 which is correct but any other shopper group could also see mod 126 and I just want group 6 to see it. I even put a css display none in mod 127 to hide it. But it is also not working. Please help.

Thank you.


$vm = JomGenius("virtuemart");
if ($vm->check("shopper_group = 6")) return 126;
if ($vm->check("category_id = 28")) return 126;
return 127; // if user is not in group 6,
            // and item is not in cat 28
// Note: Replace XXX, YYY and ZZZ with module ids to use
// in each case.

will.chen
Beginner Modder
ranks
useravatar
Offline
12 Posts
Administrator has disabled public posting

Re: Module not showing on detail page of specific category for shopr group

Hi Will,

Ok, I think I understand now: you want module 126 to only show to people in group 6, and ONLY on category listings for category 6 or individual products in category 6. Everyone else, on every other page, should get module 127. Correct?

So you can do it this way:

$vm = JomGenius("virtuemart");
if ( $vm->check("shopper_group = 6")
  and $vm->check("category_id = 28")) return 126;
return 127;


Hope that's what you were after,
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
3312 Posts
User info in posts
Administrator has disabled public posting

Re: Module not showing on detail page of specific category for shopr group

Hi Stephen:

Thank you! It is working now. So I see when there are two condition that needs to be met at once, combine the two if-script and use "and".

thanks.

Will

will.chen
Beginner Modder
ranks
useravatar
Offline
12 Posts
Administrator has disabled public posting

Re: Module not showing on detail page of specific category for shopr group

Yes, that's right. You can also combine conditions with the word "or", if 1 or the other is allowed to be true in order for the thing to succeed.

e.g.
if (condition1 or condition2) return XXX;

You can combine a series of "and"s and "or"s, but as soon as you get more than 2 in the same condition, then it pays to use brackets to group the ones that go together.

e.g.

if ( (condition1 or condition2) and condition3 ) ...

is different to:

if ( condition1 or (condition2 and condition3) ) ...


It's this sort of power that makes MetaMod rules so powerful. You can combine all sorts of conditions, and make the MetaMod display a different module for different conditions.

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

Board Info

Board Stats:
 
Total Topics:
1666
Total Polls:
6
Total Posts:
5909
Dormant:
User Info:
 
Total Users:
10093
Newest User:
lamanaudio
Members Online:
0
Guests Online:
305

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