Magento Asked on January 6, 2022
I’m using DHL Shipping Method. I have set Show Method if Not Applicable
to Yes
.
Displayed Error Message
will be displayed, when it’s applicable.
I would like to show this Error Message by Specific Country.
Example: If it’s Singapore then this message will be not displayed. For other countries, it will be displayed.
Below is the solution
magentoappcodeCustomCheckoutviewfrontendrequirejs-config.js
var config = {
"map": {
"*": {
"Magento_Checkout/js/model/shipping-service" : "Custom_Checkout/js/model/shipping-service"
}
}
};
magentoappcodeCustomCheckoutviewfrontendwebjsmodelshipping-service.js
/*global define*/
define(
[
'jquery', // For jQuery Added
'Magento_Checkout/js/model/quote', // For Quote Added
'ko',
'Magento_Checkout/js/model/checkout-data-resolver'
],
function ($, quote, ko, checkoutDataResolver) {
"use strict";
var shippingRates = ko.observableArray([]);
return {
isLoading: ko.observable(false),
/**
* Set shipping rates
*
* @param ratesData
*/
setShippingRates: function (ratesData) {
// START TO REMOVE ERROR MESSAGE FOR DHL IF SG
var address = quote.shippingAddress();
$.each(ratesData, function (k, v) {
if(v.method_code == null && v.carrier_code == 'dhl' && v.error_message != '' && address.countryId == 'SG'){
ratesData.splice(k , 1);
}
});
// STOP TO REMOVE ERROR MESSAGE FOR DHL IF SG
shippingRates(ratesData);
shippingRates.valueHasMutated();
checkoutDataResolver.resolveShippingRates(ratesData);
},
/**
* Get shipping rates
*
* @returns {*}
*/
getShippingRates: function () {
return shippingRates;
}
};
}
);
If someone has solution on PHP side then it would be great.
Answered by Jackson on January 6, 2022
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP