Magento 2结帐运费收集

Magento 2结帐运费收集,magento,knockout.js,magento2,Magento,Knockout.js,Magento2,我试图通过3d party JS代码,而不是击倒,在结账时触发运费回忆。触发它的最好方法是什么 现在,我已将模板onepage.phtml替换为自定义模板,并尝试这种方法,但它不起作用: require([ 'jquery', 'Magento_Checkout/js/model/quote' ], function($, quote) { $('#target').on('click', function(e) {

我试图通过3d party JS代码,而不是击倒,在结账时触发运费回忆。触发它的最好方法是什么

现在,我已将模板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);
        }
    });
});

我已经试过@c0rewell方法了

  • 公司模块名称/view/frontend/requirejs-config.js
  • 公司模块名称/view/frontend/web/js/myjs.js
  • 需要([
    “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/新地址”,
    ]、函数($、报价、发货服务、费率注册表、customerAddressProcessor、newAddressProcessor){
    $('div[name=“shippingAddress.city”]选择[name=“city2”]).live('change',函数(e){
    var address=quote.shippingAddress();
    //清除缓存速率以检索新速率
    rateRegistry.set(address.getCacheKey(),null);
    var type=quote.shippingAddress().getType();
    如果(类型){
    customerAddressProcessor.getRates(地址);
    }否则{
    newAddressProcessor.getRates(地址);
    }
    });
    });@Ansyori
    我已经通过修改下面的代码来运行estimat shipping方法

    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) {
    $('div[name="shippingAddress.city"] select[name="city2"]').live('change', 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 == 'new-customer-address') {
                    newAddressProcessor.getRates(address);
                }
    });
    });
    

    我应该在哪里添加js脚本以在签出页面上工作?但不获取刷新地址。@c0rewell,对于此步骤(rateRegistry.set(address.getCacheKey(),null);),它给出了错误消息
    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) {
    $('div[name="shippingAddress.city"] select[name="city2"]').live('change', 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 == 'new-customer-address') {
                    newAddressProcessor.getRates(address);
                }
    });
    });