在 magento 中取消设置运输并重新计算总计

发布于 2024-11-01 16:14:34 字数 181 浏览 0 评论 0原文

这是我的问题:

当我将电子课程(无运费)和常规产品(有运费)添加到我的购物车并在结账时选择运费时,成本会在报价中设置。如果我在设置后离开结帐,然后删除已发货的产品,则运费仍会在报价中设置,并且我无法取消设置......即使删除报价中的所有项目。

我试图弄清楚如何在从购物车中删除产品后取消设置运输方式并重新计算总数。

Here is my problem:

When I add an E-course (no shipping) and a regular product (has shipping) to my cart and select shipping during checkout the cost gets set in the quote. if I leave checkout after this has been set and then remove the product that has shipping, the shipping cost is still set in the quote and I can't unset it...even by removing all items in the quote.

I'm trying to figure out how to unset the shipping method and recalculate the totals after a product is removed from the cart.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

揽月 2024-11-08 16:14:34

有些东西会缓存在报价和送货地址模型中,因此如果您更改报价项目或送货,您必须执行此操作以使 Magento 重新计算总数:

    $quote->setTotalsCollectedFlag(false);
    $quote->getShippingAddress()->unsetData('cached_items_all');
    $quote->getShippingAddress()->unsetData('cached_items_nominal');
    $quote->getShippingAddress()->unsetData('cached_items_nonnominal');
    $quote->collectTotals();

它对我有用。 Magento 通常会在报价更改后将客户重定向到购物车或另一个页面,因此通常它必须在每次页面加载时计算一次总计。

A few things are cached in Quote and Shipping Address model, so you have to do this to make Magento recalculate totals if you change qoute items or shipping:

    $quote->setTotalsCollectedFlag(false);
    $quote->getShippingAddress()->unsetData('cached_items_all');
    $quote->getShippingAddress()->unsetData('cached_items_nominal');
    $quote->getShippingAddress()->unsetData('cached_items_nonnominal');
    $quote->collectTotals();

It worked for me. Magento normally redirects the customer to the cart or to another page after any quote change, so normally it has to calculate totals once per page load.

心房敞 2024-11-08 16:14:34

如果您以编程方式执行此操作,则可以尝试以下操作:

$quote->collectTotals()
$quote->getShippingAddress()->collectTotals()

If you are doing it programmatically then you can try this:

$quote->collectTotals()
$quote->getShippingAddress()->collectTotals()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文