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.

 

Combining two rules with AND?

Combining two rules with AND?

I would like to show a module for all visitors from country NL on the pages shop.browse and shop.product_details.

The problem I run into with most of my Metamod work is that I dont know how to

1. combine two rules (Do XXX when from country A AND on page B)
2. Selecting multiple categories (space between comma's or not?)

What I mean:

$vm = JomGenius("virtuemart"); // need this at the start of every rule
if ( $vm->check("pagetype = shop.browse, shop.product_details") ) {
  $category_id = $vm->info( "category_id" );
  /* when browsing a specific category on browse page (e.g. category 10, 11 and 12) */
  if ($category_id == "10, 11, 12") AND if ( $language_code == 'nl' ) return 128; /* module 128 for category 10, 11 and 12 and language NL*/

This is probably totally wrong but I hope it shows what I mean...

Blans

Edited By: blans
19-Apr-11 10:56:20

blans
Beginner Modder
ranks
useravatar
Offline
4 Posts
Administrator has disabled public posting

Re: Combining two rules with AND?

You were very, very close!

$vm = JomGenius("virtuemart");
if ( $vm->check("pagetype = shop.browse, shop.product_details") ) {
  if ( $vm->check( "category_id = 10, 11, 12") and $language_code == 'nl' ) return 128; /* module 128 for category 10, 11 and 12 and language NL*/
}


If you want to check for more than 1 value inside the "check" method, then you just list all the values with a comma (and spaces if you want, it doesn't matter) between them. The check will succeed if any one of the values is matched. (so it's an "or").

You can actually put all the checks into 1 "if" statement in this case:

$vm = JomGenius("virtuemart");
if ( $vm->check("pagetype = shop.browse, shop.product_details")
  and $vm->check( "category_id = 10, 11, 12" )
  and $language_code == 'nl' ) return 128;


Hope that makes sense,
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
3329 Posts
User info in posts
Administrator has disabled public posting

Re: Combining two rules with AND?

How would one combine to checks, with one outcome:

    check for all pages not starting with 'account' or 'checkout'

    if all pages found in (1) return 92.


I tried to modify this rule:

$vm = JomGenius("virtuemart"); // need this at the start of every rule
if ( $vm->check( "pagetype starts with account" ) ) return XXX;

i tried:

if ( $vm->check( "pagetype starts with account" ) or $vm->check( "pagetype starts with checkout" )) return XXX;

It does not work.

I even tried:

$vm->check( "pagetype not = account.billing, account.index, account.order_details, account.orders, account.shipping, account.shipto, shop.browse, checkout.index#1, checkout.index#2, checkout.index#3, checkout.index#4, checkout.thankyou" )

Also did not work.

Are you able to assist please?

jodi319
Beginner Modder
ranks
useravatar
Offline
2 Posts
Administrator has disabled public posting

Re: Combining two rules with AND?

Hi Jodi,

good question, and well presented.

When you list more than one item in JomGenius, there's an implicit "any of" in front of the list.

e.g.
$vm->check( "pagetype not = any of account.billing, account.index, account.order_details, account.orders, account.shipping, account.shipto, shop.browse, checkout.index#1, checkout.index#2, checkout.index#3, checkout.index#4, checkout.thankyou" )

What JomGenius does is then checks each of the items in turn against the value from the left hand side (pagetype in this case). If any one of them matches the condition, then the complete rule returns as TRUE.

This is fine for normal "=" matching (if 1st or 2nd or 3rd... then return true). But it doesn't work the way you think when you do a "not =". It does "if !1st or !2nd or !3rd" etc. So in fact the rule can never return true, because the value is always "not equal" to at least 1 of the items.

So there are 2 ways to do it:

Choose one of:

$vm->check( "pagetype = none of account.billing, account.index, account.order_details, account.orders, account.shipping, account.shipto, shop.browse, checkout.index#1, checkout.index#2, checkout.index#3, checkout.index#4, checkout.thankyou" )

[i.e. checks through every value, and returns TRUE if none of them match]

or:

$vm->check( "pagetype not = all of account.billing, account.index, account.order_details, account.orders, account.shipping, account.shipto, shop.browse, checkout.index#1, checkout.index#2, checkout.index#3, checkout.index#4, checkout.thankyou" )

[i.e. checks through every value, and returns TRUE if every one of them doesn't match]

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

Board Info

Board Stats:
 
Total Topics:
1698
Total Polls:
6
Total Posts:
5944
Posts this week:
4
User Info:
 
Total Users:
5534
Newest User:
kaylee
Members Online:
0
Guests Online:
108

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