diff --git a/uafrica/Customshipping/view/frontend/web/js/model/shipping-rates-validation-rules.js b/uafrica/Customshipping/view/frontend/web/js/model/shipping-rates-validation-rules.js new file mode 100644 index 0000000000000000000000000000000000000000..6d4a703e5b0764a90c33763c3e546830eb33e66d --- /dev/null +++ b/uafrica/Customshipping/view/frontend/web/js/model/shipping-rates-validation-rules.js @@ -0,0 +1,18 @@ +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +/*global define*/ +define( + [], + function () { + "use strict"; + return { + getRules: function() { + return { + + }; + } + }; + } +); \ No newline at end of file diff --git a/uafrica/Customshipping/view/frontend/web/js/model/shipping-rates-validator.js b/uafrica/Customshipping/view/frontend/web/js/model/shipping-rates-validator.js new file mode 100644 index 0000000000000000000000000000000000000000..b56f86536cdfe2666143317d56d1064c04541c78 --- /dev/null +++ b/uafrica/Customshipping/view/frontend/web/js/model/shipping-rates-validator.js @@ -0,0 +1,30 @@ +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +/*global define*/ +define( + [ + 'jquery', + 'mageUtils', + './shipping-rates-validation-rules', + 'mage/translate' + ], + function ($, utils, validationRules, $t) { + "use strict"; + return { + validationErrors: [], + validate: function(address) { + var self = this; + this.validationErrors = []; + $.each(validationRules.getRules(), function(field, rule) { + if (rule.required && utils.isEmpty(address[field])) { + var message = $t('Field ') + field + $t(' is required.'); + self.validationErrors.push(message); + } + }); + return !Boolean(this.validationErrors.length); + } + }; + } +); \ No newline at end of file diff --git a/uafrica/Customshipping/view/frontend/web/js/view/shipping-rates-validation.js b/uafrica/Customshipping/view/frontend/web/js/view/shipping-rates-validation.js new file mode 100644 index 0000000000000000000000000000000000000000..bfe148b4ad02dd6ee67588cf6c06fed1f2c09835 --- /dev/null +++ b/uafrica/Customshipping/view/frontend/web/js/view/shipping-rates-validation.js @@ -0,0 +1,27 @@ +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +/*browser:true*/ +/*global define*/ +define( + [ + 'uiComponent', + 'Magento_Checkout/js/model/shipping-rates-validator', + 'Magento_Checkout/js/model/shipping-rates-validation-rules', + '../model/shipping-rates-validator', + '../model/shipping-rates-validation-rules' + ], + function ( + Component, + defaultShippingRatesValidator, + defaultShippingRatesValidationRules, + sampleShippingProviderShippingRatesValidator, + sampleShippingProviderShippingRatesValidationRules + ) { + "use strict"; + defaultShippingRatesValidator.registerValidator('uafrica', sampleShippingProviderShippingRatesValidator); + defaultShippingRatesValidationRules.registerRules('uafrica', sampleShippingProviderShippingRatesValidationRules); + return Component; + } +);