Magento 2 结账运费收集

标签 magento knockout.js magento2

我正在尝试通过 3d 方 JS 代码(而不是 Knockout)在结帐时触发运费记忆。触发它的最佳方式是什么?

现在我已将模板 onepage.phtml 替换为自定义模板并尝试这种方法,但它不起作用:

    require([
        'jquery',
        'Magento_Checkout/js/model/quote'
    ], function($, quote) {
        $('#target').on('click', function(e) {
            console.log(quote.shippingAddress(quote.shippingAddress()));
        });
    });

最佳答案

好吧,伙计们。解决办法如下:

require([
    'jquery',
    'Magento_Checkout/js/model/quote',
    'Magento_Checkout/js/model/shipping-service',
    'Magento_Checkout/js/model/shipping-rate-registry',
    'Magento_Checkout/js/model/shipping-rate-processor/customer-address',
    'Magento_Checkout/js/model/shipping-rate-processor/new-address',
], function($, quote, shippingService, rateRegistry, customerAddressProcessor, newAddressProcessor) {
    $('#target').on('click', function(e) {
        var address = quote.shippingAddress();
        // clearing cached rates to retrieve new ones
        rateRegistry.set(address.getCacheKey(), null);
        var type = quote.shippingAddress().getType();
        if (type) {
            customerAddressProcessor.getRates(address);
        } else {
            newAddressProcessor.getRates(address);
        }
    });
});

关于Magento 2 结账运费收集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38522279/

相关文章:

php - Magento 多站点 - 批量启用和设置每个站点不同的可见性

Magento 安装 - 无法访问管理面板

php - Magento 2 InstallSchema 未被执行

安卓 : Magento 2 e-commerce Website not Working in android Webview

ubuntu - 自定义 PHP 文件不会加载(在 magento 2 安装 ubuntu + nginx 之外)

php - Mysql:查询未执行

magento 自定义管理模块保存操作不起作用

ajax - KnockoutJS 使用 Ajax 填充多个 View 模型的最佳实践

javascript - knockout 更改模板中的模型

knockout.js - knockout js中的多个数据绑定(bind)