在Checkout-Cart页面上删除购物车项目后,如何使用Ajax更新运费?


15

我的运费是根据购物车中的商品计算出来的,现在删除Checkout/Cart页面上的商品后,我需要更新运费。到目前为止,页面上的删除项目会Checkout/Cart更新总部分,但不会刷新运费。如果有人使用Ajax从购物车中删除商品,可以指导我如何触发获取运费,这将是非常有用的。


您对此有任何解决方案吗?
深渊

Answers:


1

希望你一切都好。

请尝试使用此JavaScript代码。希望对您有所帮助。

define(
    [
        'Magento_Checkout/js/model/quote',
        'Magento_Checkout/js/model/shipping-rate-processor/new-address',
        'Magento_Checkout/js/model/shipping-rate-processor/customer-address',
        'Magento_Checkout/js/model/shipping-rate-registry'

    ],
    function (quote, defaultProcessor, customerAddressProcessor, rateRegistry) {
       'use strict';

       var processors = [];

       rateRegistry.set(quote.shippingAddress().getCacheKey(), null);

       processors.default =  defaultProcessor;
       processors['customer-address'] = customerAddressProcessor;

       var type = quote.shippingAddress().getType();

       if (processors[type]) {
          processors[type].getRates(quote.shippingAddress());
       } else {
          processors.default.getRates(quote.shippingAddress());
       }

    }
);

0
 requirejs([
    'Magento_Checkout/js/model/quote',
    'Magento_Checkout/js/model/shipping-rate-registry'
], function(quote, rateRegistry){


    var address = quote.shippingAddress();

    address.trigger_reload = new Date().getTime();

    rateRegistry.set(address.getKey(), null);
    rateRegistry.set(address.getCacheKey(), null);

    quote.shippingAddress(address);
});
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.