【问题标题】:Allow only one product in cart仅允许购物车中的一种产品
【发布时间】:2016-01-05 14:49:55
【问题描述】:

运行 joomla 3.4.8 和 VM 3.0.12

我只需要在购物车中允许一件产品。我的意思是,如果客户将产品添加到购物车,然后如果他/她想添加另一种产品,则不允许它显示错误消息,例如“您的购物车中不能有多个产品”

【问题讨论】:

    标签: joomla virtuemart


    【解决方案1】:

    您可以更改购物车控制器页面中的 add() 函数来实现它。你可以写这样的代码

    $cart = VirtueMartCart::getCart();
    $prdata = $cart->cartProductsData;
    $qty = 0;
    foreach($prdata as $pdata)
        {
            $qty = $qty + $pdata['quantity'];
        }
    
    
    if ($cart) {
            $virtuemart_product_ids = vRequest::getInt('virtuemart_product_id');
            $error = false;
            if($qty>=1)
            {
                $msg = vmText::_('you can't have more than one product in cart');
                $type = 'warning';
            }
            else
            {
            $cart->add($virtuemart_product_ids,$error);
    

    在同一页面的 updatecart() 函数中使用相同的逻辑。

    如果您使用 Fancypopup addtocart,请使用 addJS 函数中的代码,而不是 add() 函数。

    【讨论】:

      猜你喜欢
      • 2017-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-17
      • 2023-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多