I'd like to update shipping price and cart subtotal when choosing a different shipping method in the checkout page

enter image description here

Any hint on involved files and the right approach would be very helpful

没有正确的解决方案

其他提示

I've finally done it like this:

  • Create a require-config.js file in app/design/frontend/Vendor/Theme/Magento_Checkout/web/requirejs-config.js

require-config.js

var config = {
    config: {
        mixins: {
            'Magento_Checkout/js/view/summary/abstract-total': {
                'js/view/summary/abstract-total-mixin': true
            },
            'Magento_Checkout/js/view/shipping': {
                'js/view/shipping-mixin': true
            }
        }
    }
};
  • Add the defined files in require-config.js which are:

app/design/frontend/Vendor/Theme/Magento_Checkout/web/js/view/summary/abstract-total-mixin.js

abstract-total-mixin.js

define([], function () {
    'use strict';

    return function (Component) {
        return Component.extend({
            isFullMode: function () {
                if (!this.getTotals()) {
                    return false;
                }

                return true;
            }
        });
    };
});

app/design/frontend/Vendor/Theme/Magento_Checkout/web/js/view/summary/shipping-mixin.js

shipping-mixin.js

define([
    'Magento_Checkout/js/model/cart/estimate-service'
], function (estimateService) {
    'use strict';

    var mixin = {
        initialize: function () {
            this._super();
        }
    };

    return function (target) {
        return target.extend(mixin);
    };
});
许可以下: CC-BY-SA归因
scroll top