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.

 

Using JoomGenius and Products in the VM Cart

Using JoomGenius and Products in the VM Cart

I am using the following code, to test it works okay

Code:

$vm = JomGenius("virtuemart");

if ( $vm ) {
  echo "pid " . $vm->info( "cart_product_ids" );
} else {

echo '';
}

I would like to build on this to display a message when product_id 132,134,133 are in the cart. At the moment I can only get the word "array" displayed rather just the values out of the array. In otherwords how do I get the values out of the array to do an if against it.

Thanks Steve

uglykidjoe
Beginner Modder
ranks
useravatar
Offline
13 Posts
Administrator has disabled public posting

Re: Using JoomGenius and Products in the VM Cart

Hi uglykidjoe,

Welcome to the world of JomGenius! It's easier than you think.

If you use $vm->info( "cart_product_ids" ) then as you have seen, you get an array. If you want to use this in PHP, that's fine. But JomGenius has much easier ways of checking for particular values.

If you want to check that array for 1 or more specific values, then use:

if ( $vm->check( "cart_product_ids = 132, 134, 133" ) ) echo "found one!";

If you want to check to see that the cart contains one of these 3 products, use this:

if ( $vm->check( "all of cart_product_ids = 132, 134, 133" ) ) echo "you are purchasing 132, 133 and 134!";

That last rule has interesting logic. JomGenius takes to mean "every item in the array on the left has to equal at least one of the items on the right". This is a good example of when this is useful.

If you want to check that a specific product is NOT in the cart, use this:

if ( $vm->check( "all of cart_product_ids = none of 132, 134, 133" ) ) echo "you are not purchasing any of 132, 133 or 134";

(i.e. it checks through every item in the cart to make sure it matches none of the items in the list on the right)


Ok, that's probably overkill. You probably just want to use the first one, to trigger when any of the mentioned products are in the cart.

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

Re: Using JoomGenius and Products in the VM Cart

Hi Stephen thanks ever so much that worked perfectly!

Please could you suggest a way of redirecting users to another page if they try to add to the cart if product_id either 132, 133 and 134 are in the cart but allow any combinations of 132, 133 and 134 to be added still

Thanks again Steve

uglykidjoe
Beginner Modder
ranks
useravatar
Offline
13 Posts
Administrator has disabled public posting

Re: Using JoomGenius and Products in the VM Cart

I think this is going beyond what you should be doing with MetaMod! By the time MetaMod is viewing this information, the product will already have been added to the cart, so there's no way that MetaMod can actually remove it from the cart, or prevent it from going in, in the first place.

Sorry, I think you need to find a way to do this deeper inside Virtuemart (though I think this will be very difficult unless you can find a VM genius to code it).

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

Re: Using JoomGenius and Products in the VM Cart

I was thinking of a way of preventing viewing the other products (or visiting pages) once 132,133 and 134 are in the cart and sending the user to another page explaining why

Could I do that?

uglykidjoe
Beginner Modder
ranks
useravatar
Offline
13 Posts
Administrator has disabled public posting

Re: Using JoomGenius and Products in the VM Cart

Hmmm... maybe.

so which types of pages should people not be allowed to visit once the cart contains 132 AND 133 AND 134?
- no product pages at all?

So you could do that like this:

$vm = JomGenius("virtuemart");
if ( $vm->check("pagetype = shop.product_details")
and $vm->check( "cart_product_ids = 132" )
and $vm->check( "cart_product_ids = 133" )
and $vm->check( "cart_product_ids = 134" ) ) {
  $app = &JFactory::getApplication();
  $app->redirect("http://www.example.com/YouCantBuyThat.html");
}


This does pretty much as it reads: it checks to see if the person is going to a product details page. If so, and if 132 and 133 and 134 are already in the cart, then it redirects to the other page.

I never imagined anyone would want to do this!!! But it should work.

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

Re: Using JoomGenius and Products in the VM Cart

Thank you I'll give it a go - the reason I want to stop of products is because of the different delivery vehicle used.

Thank you

uglykidjoe
Beginner Modder
ranks
useravatar
Offline
13 Posts
Administrator has disabled public posting

Re: Using JoomGenius and Products in the VM Cart

Thanks, but not quite there - really need 'or' rather than 'and' logic

Once product 132, 133 or 134 have been added nothing else can be added to the cart unless its also 132, 133 or 134 if you see what I mean.


Thanks Steve

uglykidjoe
Beginner Modder
ranks
useravatar
Offline
13 Posts
Administrator has disabled public posting

Re: Using JoomGenius and Products in the VM Cart

Aaaaargh! Ok, finally we've nailed down the exact details - thanks smile

$vm = JomGenius("virtuemart");
if ( $vm->check("pagetype = shop.product_details")
  and $vm->check( "cart_product_ids = 132, 133, 134" )
  and $vm->check( "product_id = none of 132, 133, 134" )
) {
  $app = &JFactory::getApplication();
  $app->redirect("http://www.example.com/YouCantBuyThat.html");
}

So that says:
- if you're on a product details page
- and you have any of 132, 133, 134 in the cart
- and the one you are trying to look at is not in the list 132, 133, 134
... then redirect.

Gosh this is powerful!

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

Board Info

Board Stats:
 
Total Topics:
1685
Total Polls:
6
Total Posts:
5912
Total Posts Today:
4
User Info:
 
Total Users:
11504
Newest User:
toko solo
Members Online:
0
Guests Online:
127

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