0

I've found the solution by the link http://forum.virtuemart.net/index.php?topic=127483.0 from Virtuemart Projectleader:

if (!class_exists('VirtueMartCart')) require(VMPATH_SITE . DS . 'helpers' . DS . 'cart.php');
$cart = VirtueMartCart::getCart();
$cart->removeProductCart($yourId);

but it doesn't work. I tried to replace DS with DIRECTORY_SEPARATOR because I use Joomla 3.x but nothing changed

At the same time $cart->emptyCart() works

Joomla 3.3.6, VM 3.0.3

user3892905
  • 376
  • 1
  • 4
  • 14

1 Answers1

2

This is my solutions

function removeProductFromCart($product_id_to_remove){
    $cart = json_decode($_SESSION['__vm']['vmcart']);
    foreach($cart->cartProductsData as $k => $v){
        if($v->virtuemart_product_id == $product_id_to_remove) unset($cart->cartProductsData[$k]);
    }
    $_SESSION['__vm']['vmcart'] = json_encode($cart);
}
ermes
  • 36
  • 1
  • You might want to explain what this does – Machavity Mar 05 '15 at 17:17
  • **ermes** thanks, this works but with unset($cart->cartProductsData->$k) – user3892905 Mar 06 '15 at 11:01
  • Unfortunately there is one problem: if I replace [$k] to ->$k, the product is being removed but after a while isn't, so I replace back ->$k to [$k] and removing works again but after a while I get stdClass' error, then I replace [$k] to ->$k again and the circle closes – user3892905 Mar 09 '15 at 10:15