如何从Magento中删除报价中的项目? [英] How to remove item from quote in Magento?

查看:74
本文介绍了如何从Magento中删除报价中的项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在结帐过程中,有时我会以编程方式从会话的报价中删除项目.所以我尝试了这段代码:

During the checkout process I sometimes want to programmatically remove items from the session's quote. So I tried this code:

$quote = Mage::getSingleton('checkout/session')->getQuote();
$all_quote_items = $quote->getAllItems();
foreach ($all_quote_items as $item) {
    $quote->removeItem($item->getId())->save();
}

但是,在此循环之后,$quote对象中的项目列表仍然相同,即未删除任何项目.

However, after this loop the list of items in the $quote object is still the same, i.e. no items have been removed.

有什么主意我在这里想念的吗?

Any ideas what I am missing here?

使用Magento 1.4.1.1

Using Magento 1.4.1.1

推荐答案

尝试

$cartHelper = Mage::helper('checkout/cart');
$items = $cartHelper->getCart()->getItems();        
foreach ($items as $item) 
{
   $itemId = $item->getItemId();
   $cartHelper->getCart()->removeItem($itemId)->save();
} 

请参见 http://www.magentocommerce.com/boards/viewthread/30113/

这篇关于如何从Magento中删除报价中的项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆