Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.
- Index
- » MetaMod
- » MetaMod General Support
- » Using JoomGenius and Products in the...
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
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
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
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
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
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
Re: Using JoomGenius and Products in the VM Cart
Aaaaargh! Ok, finally we've nailed down the exact details - thanks
$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!
- Index
- » MetaMod
- » MetaMod General Support
- » Using JoomGenius and Products in the...
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:
- 90
- 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