如何从mod_virtuemart_cart中删除单个产品 [英] How to remove a single product from mod_virtuemart_cart
本文介绍了如何从mod_virtuemart_cart中删除单个产品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我通过链接 http://forum.virtuemart.net找到了解决方案/index.php?topic=127483.0 来自Virtuemart Projectleader:
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);
但是它不起作用.我尝试用DIRECTORY_SEPARATOR替换DS,因为我使用的是Joomla 3.x,但未做任何更改
but it doesn't work. I tried to replace DS with DIRECTORY_SEPARATOR because I use Joomla 3.x but nothing changed
同时$ cart-> emptyCart()起作用
At the same time $cart->emptyCart() works
Joomla 3.3.6,VM 3.0.3
Joomla 3.3.6, VM 3.0.3
推荐答案
这是我的解决方案
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);
}
这篇关于如何从mod_virtuemart_cart中删除单个产品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文