简体   繁体   English

Magento-无法更改数量时更新购物车

[英]Magento - Update Cart On Quantity Change Not Working

I have added in quantity increment buttons to the cart: 我在购物车中添加了数量增加按钮:

在此处输入图片说明

These work to increase the quantity in the qty box, 这些可以增加数量框中的数量,

However I want the whole cart to update each time they press either increase or decrease, 但是,我希望整个购物车在每次按下增大或减小键时进行更新,

Any ideas? 有任何想法吗?

Thanks, 谢谢,

Reece 里斯

You have to make an Ajax call and execute the following functionality:- 您必须进行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;     

This is just an example, you need to manage the variables according to your need. 这只是一个示例,您需要根据需要管理变量。 Whenever button is press just make a ajax call and update cart and then you need to update it via Ajax in other place where you want. 每当按下按钮时,只需拨打ajax呼叫并更新购物车,然后就需要通过Ajax在其他需要的地方对其进行更新。 Above code provide you the way to save product quantity to cart. 上面的代码为您提供了将产品数量保存到购物车的方法。

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

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