Hi,
I am struggling to create the function "remove a product from the cart" in the mod_virtuemart_cart module. With other words, I would like to delete a single product from my shopping cart module which is shown in the sidebar.
This function is already available in virtuemart (via delete product from cart overview) and I aim to reuse this function, however I have some problems with the php includes which will allow me to call the function.
The function is found in "components\com_virtuemart\helpers\cart.php", function:
public function removeProductCart($prod_id=0){
<<Code
}
Question:
Which files / code do I include which will enable me to call the "removeProductCart" function from \modules\mod_virtuemart_cart\tmpl\default.php
Specs:
Joomla! 2.5.27
VirtueMart 2.6.12.2
Thanks in advance,
use the cart itself
if (!class_exists('VirtueMartCart')) require(VMPATH_SITE . DS . 'helpers' . DS . 'cart.php');
$cart = VirtueMartCart::getCart();
$cart->removeProductCart($yourId);
refresh your cart module by ajax or reload and thats it. Btw, it would be nice if you share the code and we can add it to the core
I try this code and reload page but nothing happens. For example:
if (!class_exists('VirtueMartCart')) require(VMPATH_SITE . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'cart.php');
$cart = VirtueMartCart::getCart();
$yourId = 3;
$cart->removeProductCart($yourId);
Joomla 3.3.6, VM 3.0.3
in vm3, I think you need an array
$yourId[] = 3;
If I write:
if (!class_exists('VirtueMartCart')) require(VMPATH_SITE . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'cart.php');
$cart = VirtueMartCart::getCart();
$yourId[] = 3;
$cart->removeProductCart($yourId);
I get the warning: Illegal offset type in unset in /***/components/com_virtuemart/helpers/cart.php on line 673
unset($this->products[$prod_id]);
and ... on line 674
if(isset($this->cartProductsData[$prod_id])){
Can you write the full code? Thanks
Quote from: fmvm on February 27, 2015, 08:45:45 AM
If I write:
if (!class_exists('VirtueMartCart')) require(VMPATH_SITE . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'cart.php');
$cart = VirtueMartCart::getCart();
$yourId[] = 3;
$cart->removeProductCart($yourId);
I get the warning: Illegal offset type in unset in /***/components/com_virtuemart/helpers/cart.php on line 673
unset($this->products[$prod_id]);
and ... on line 674
if(isset($this->cartProductsData[$prod_id])){
Can you write the full code? Thanks
Is there any update for this?
Hello, How did you finally solve it? Could you share the code? well thank you