Magento - 更新购物车数量变更不起作用

时间:2016-05-26 09:17:23

标签: php magento

我已将数量增量按钮添加到购物车:

enter image description here

这些可以增加数量框中的数量,

但是我希望每次按下增加或减少时整个购物车都会更新,

有什么想法吗?

谢谢,

里斯

1 个答案:

答案 0 :(得分:0)

您必须进行Ajax调用并执行以下功能: -

   // Product ID and Quantity
    $pid = $_REQUEST['productId'];
    $qnt = $_REQUEST['qty'];
    $cart = Mage::getSingleton('checkout/cart');
    $items = $cart->getItems(); 
    foreach ($items as $item) :
        if($pid == $item->getId()) :
            echo $item->getQty();
            $item->setQty($qnt); 
            $cart->save();
        endif;
    endforeach;     

这只是一个例子,您需要根据需要管理变量。每当按下按钮时,只需进行ajax调用并更新购物车,然后您需要通过Ajax在您想要的其他地方更新它。上面的代码为您提供了将产品数量保存到购物车的方法。

相关问题