VirtueMart 2.6.10 and Joomla! 2.5.24 and php5.4
I want to be able to add a product to the cart. I can empty the cart if required:
if (!class_exists('VirtueMartCart')) require(VMPATH_SITE . DS . 'helpers' . DS . 'cart.php');
$cart->emptyCart();
Now I believe I need to do:
$cart->add(Yourstuff);
but I am unsure what the data should look like in the array 'Yourstuff'
eg. I want to add a single product (id=77, qty=1). What form does the array 'Yourstuff' take?
Any help will be greatly appreciated.
Look at this example: http://forum.virtuemart.net/index.php?topic=94539.msg337937#msg337937
or https://www.spiralscripts.co.uk/joomla-plugins/vm2-product-snapshot-detail
Hi Jenkinhill, Thank you for your reply.
Neither solution you have suggested will fit my requirements. They both create a link for the user to click "Add to cart".
eg option=com_virtuemart&view=cart&task=add&quantity[]=1&virtuemart_product_id[]=77&virtuemart_category_id[]=1
I want to add the product (or multiple products) directly as a result of an event that has already occurred.
Hence the need to prepare the array "Yourstuff" to execute:
$cart->add(Yourstuff);
Ok I have worked it out myself. I can now replace one product with another product when the required event has occurred:
$cart = VirtueMartCart::getCart();
$produst_ids=array();
$product_ids[0]=77;
$success = true;
$cart->add($product_ids,$success);
$cart->updateProductCart(76,0);
Hope this helps someone else with a similar need.