我正在創建一個magento擴展程序。其中我想以編程方式更新購物車中的商品數量。我正在使用下面的代碼來顯示購物車中的物品。Magento:以編程方式更新購物車的數量
$quote = Mage::getSingleton('checkout/session')->getQuote();
$cartItems = $quote->getAllVisibleItems();
foreach ($cartItems as $item) {
//Do something
}
我想要的是更新特定產品的購物車數量。我知道這是可以做到這樣的
$pid=15;
$quote = Mage::getSingleton('checkout/session')->getQuote();
$cartItems = $quote->getAllVisibleItems();
foreach ($cartItems as $item) {
if($pid==$item->getId())
$item->setQty($qty);
}
但我不喜歡這種方法,因爲它會經歷每一個產品更新單個product.I奇蹟的數量是否有更新的方式數量在一行i:e中,不用於循環。
你正在使用什麼事件? – 2013-11-26 10:06:53
檢查此:http://www.onlinecode.org/magento-update-cart-quantity/ – 2017-03-16 05:51:50