Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

New files to perform shipping validation #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/view/frontend/layout/checkout_cart_index.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="checkout.cart.shipping">
<arguments>
<argument name="jsLayout" xsi:type="array">
<item name="components" xsi:type="array">
<item name="summary-block-config" xsi:type="array">
<item name="children" xsi:type="array">
<item name="shipping-rates-validation" xsi:type="array">
<item name="children" xsi:type="array">
<item name="rm-rates-validation" xsi:type="array">
<item name="component" xsi:type="string">Meanbee_RoyalMail/js/view/shipping-rates-validation</item>
</item>
</item>
</item>
</item>
</item>
</item>
</argument>
</arguments>
</referenceBlock>
</body>
</page>
35 changes: 35 additions & 0 deletions src/view/frontend/layout/checkout_index_index.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="checkout.root">
<arguments>
<argument name="jsLayout" xsi:type="array">
<item name="components" xsi:type="array">
<item name="checkout" xsi:type="array">
<item name="children" xsi:type="array">
<item name="steps" xsi:type="array">
<item name="children" xsi:type="array">
<item name="shipping-step" xsi:type="array">
<item name="children" xsi:type="array">
<item name="step-config" xsi:type="array">
<item name="children" xsi:type="array">
<item name="shipping-rates-validation" xsi:type="array">
<item name="children" xsi:type="array">
<item name="rm-rates-validation>" xsi:type="array">
<item name="component" xsi:type="string">Meanbee_RoyalMail/js/view/shipping-rates-validation</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</argument>
</arguments>
</referenceBlock>
</body>
</page>
15 changes: 15 additions & 0 deletions src/view/frontend/web/js/model/shipping-rates-validation-rules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
define(
[],
function () {
'use strict';
return {
getRules: function() {
return {
'country_id': {
'required': true
}
};
}
};
}
)
26 changes: 26 additions & 0 deletions src/view/frontend/web/js/model/shipping-rates-validator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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);
}
};
}
);
21 changes: 21 additions & 0 deletions src/view/frontend/web/js/view/shipping-rates-validation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
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,
shippingRatesValidator,
shippingRatesValidationRules
) {
'use strict';
defaultShippingRatesValidator.registerValidator('rm', shippingRatesValidator);
defaultShippingRatesValidationRules.registerRules('rm', shippingRatesValidationRules);
return Component;
}
);