问题
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
回答1:
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);
}
来源:https://stackoverflow.com/questions/28691203/how-to-remove-a-single-product-from-mod-virtuemart-cart