简体   繁体   English

如何从mod_virtuemart_cart中删除单个产品

[英]How to remove a single product from mod_virtuemart_cart

I've found the solution by the link http://forum.virtuemart.net/index.php?topic=127483.0 from Virtuemart Projectleader: 我从Virtuemart Projectleader的链接http://forum.virtuemart.net/index.php?topic=127483.0找到了解决方案:

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 我尝试用DIRECTORY_SEPARATOR替换DS,因为我使用的是Joomla 3.x,但未做任何更改

At the same time $cart->emptyCart() works 同时$ cart-> emptyCart()起作用

Joomla 3.3.6, VM 3.0.3 Joomla 3.3.6,VM 3.0.3

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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM