How to remove a single product from mod_virtuemart_cart

一世执手 提交于 2019-12-25 04:23:00

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!