From 023c8243ade0e9154e9c744832d0ea308f5ac009 Mon Sep 17 00:00:00 2001 From: Ian Heggaton Date: Sat, 28 Apr 2018 14:41:07 +1000 Subject: [PATCH 1/6] Formatting --- Block/Checkout/LayoutProcessor.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Block/Checkout/LayoutProcessor.php b/Block/Checkout/LayoutProcessor.php index 2b246de..7f9dc4f 100644 --- a/Block/Checkout/LayoutProcessor.php +++ b/Block/Checkout/LayoutProcessor.php @@ -106,12 +106,12 @@ public function modifyStreetUiComponents($addressResult) $lineCount = 0; while($lineCount < 4){ - + $lineNumber = $lineCount+1; if(isset($addressResult['street']['children'][$lineCount])){ $label = $this->addressLineHelper->getLineLabel($lineNumber); - + if ( $this->addressLineHelper->isLineEnabled($lineNumber)) { $addressResult['street']['children'][$lineCount]['label'] = $label; $addressResult['street']['children'][$lineCount]['additionalClasses'] = 'experius-address-line-one'; @@ -125,6 +125,4 @@ public function modifyStreetUiComponents($addressResult) return $addressResult; } - - } From 81d2bbffa52c16febd3d93599b3af7ccfe1569fa Mon Sep 17 00:00:00 2001 From: Ian Heggaton Date: Sat, 28 Apr 2018 15:33:30 +1000 Subject: [PATCH 2/6] Added option to enable/disable PO Boxes --- etc/adminhtml/system.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 0b717d7..f6cb8bb 100755 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -105,6 +105,11 @@ Necessary for registrion page and address edit. + + + Magento\Config\Model\Config\Source\Yesno + From 02314d85be3fe17c5535a8aff9b2fc8c3f13098f Mon Sep 17 00:00:00 2001 From: Ian Heggaton Date: Sat, 28 Apr 2018 16:38:00 +1000 Subject: [PATCH 3/6] Implemented PO Box Support Will now determine if any of the address lines have a PO Box (and variants) and will fail validation if enabled --- Helper/Data.php | 20 ++++++++++++++++++- etc/adminhtml/system.xml | 2 +- etc/config.xml | 1 + .../experius/customer/address/edit.phtml | 17 ++++++++++++++++ .../experius/customer/form/register.phtml | 13 +++++++++++- 5 files changed, 50 insertions(+), 3 deletions(-) diff --git a/Helper/Data.php b/Helper/Data.php index a152100..a157cec 100644 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -81,7 +81,7 @@ public function getValidationClassesForLine($lineNumber) return $validationClassesString; } - public function getValidationClassesAsArrayForLine($lineNumber) + public function getValidationClassesAsArrayForLine($lineNumber) { $group = "experius_address_lines/experius_address_line{$lineNumber}"; @@ -102,9 +102,27 @@ public function getValidationClassesAsArrayForLine($lineNumber) if($this->isLineRequired($lineNumber)){ $validationClassesArray['required-entry'] = 1; } + if ($this->getEnablePOBoxRule()) { + $validationClassesArray = $this->getPOBoxRule($validationClassesArray); + } + $this->_logger->debug(print_r($validationClassesArray, true)); return $validationClassesArray; } + public function getEnablePOBoxRule() + { + $group = "experius_address_lines"; + + return !$this->getModuleConfig("shipping_po_box", $group); + } + + + public function getPOBoxRule($existingClasses) + { + $existingClasses['po-box-validation'] = true; + return $existingClasses; + } + /** * Return form attribute IDs by form code * diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index f6cb8bb..311d9e0 100755 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -107,7 +107,7 @@ - + Magento\Config\Model\Config\Source\Yesno diff --git a/etc/config.xml b/etc/config.xml index 6018499..23ccf20 100755 --- a/etc/config.xml +++ b/etc/config.xml @@ -31,6 +31,7 @@ + 1 diff --git a/view/frontend/templates/experius/customer/address/edit.phtml b/view/frontend/templates/experius/customer/address/edit.phtml index 8a7d5be..5c4c9eb 100644 --- a/view/frontend/templates/experius/customer/address/edit.phtml +++ b/view/frontend/templates/experius/customer/address/edit.phtml @@ -178,3 +178,20 @@ } } + +helper('Experius\AddressLines\Helper\Data')->getEnablePOBoxRule()): ?> + + diff --git a/view/frontend/templates/experius/customer/form/register.phtml b/view/frontend/templates/experius/customer/form/register.phtml index 87971be..1ee1344 100644 --- a/view/frontend/templates/experius/customer/form/register.phtml +++ b/view/frontend/templates/experius/customer/form/register.phtml @@ -194,7 +194,9 @@ + getShowAddressFields()): ?> diff --git a/view/frontend/templates/experius/customer/form/register.phtml b/view/frontend/templates/experius/customer/form/register.phtml index 1ee1344..7292bcd 100644 --- a/view/frontend/templates/experius/customer/form/register.phtml +++ b/view/frontend/templates/experius/customer/form/register.phtml @@ -78,7 +78,10 @@
-
+ helper('Experius\AddressLines\Helper\Data')->getEnablePOBoxRule()): ?> +
PO Boxes not allowed
+ +
@@ -225,9 +228,9 @@ require([ helper('Experius\AddressLines\Helper\Data')->getEnablePOBoxRule()): ?> $.validator.addMethod( 'po-box-validation', function (value) { - var re = /^box.*|.*po\s+box.*|.*p[\.\s]o\.?\sbox.*/i; + var re = helper('Experius\AddressLines\Helper\Data')->getPOValidationRegex(); ?>; return !re.test(value); - }, $.mage.__("We don't ship to PO Boxes") + }, "helper('Experius\AddressLines\Helper\Data')->getPOErrorMessage(); ?>" ); }); diff --git a/view/frontend/web/css/source/_module.less b/view/frontend/web/css/source/_module.less index b6ecbbd..e96b4ca 100644 --- a/view/frontend/web/css/source/_module.less +++ b/view/frontend/web/css/source/_module.less @@ -5,7 +5,7 @@ & when (@media-common = true) { .experius-address-lines { - .field{ + .field { margin: 0 0 20px; } @@ -13,5 +13,12 @@ display: none !important; } + label + .info { + font-weight: normal; + font-style: italic; + margin-bottom: 1em; + } + } + } \ No newline at end of file From f20f7508c35f4e76ac07783c6585dace1df98d95 Mon Sep 17 00:00:00 2001 From: Ian Heggaton Date: Sun, 29 Apr 2018 13:38:29 +1000 Subject: [PATCH 5/6] Updated Readme --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index da1a816..60c39ff 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -**Experius Address Lines,** +**Experius Address Lines** Adds labels to address lines and adds configuration per address line. @@ -8,6 +8,8 @@ Configuration Per Line - Label - Validation Classes +Also has an option for disabling PO Boxes in the address + Stores > Configuration > Customers > Customer Configuration > Address Lines **Screenshots** From f56f028608f6e12eba2d05660a9ef076a48276b6 Mon Sep 17 00:00:00 2001 From: Ian Heggaton Date: Wed, 2 May 2018 23:04:57 +1000 Subject: [PATCH 6/6] Made changes to the validation message and is now working on the one page checkout screen for new customers --- Helper/Data.php | 5 ----- etc/adminhtml/system.xml | 4 ---- etc/config.xml | 1 - etc/module.xml | 0 .../layout/customer_account_create.xml | 0 .../frontend/layout/customer_address_form.xml | 0 view/frontend/requirejs-config.js | 9 +++++++++ .../experius/customer/address/edit.phtml | 2 +- .../experius/customer/form/register.phtml | 2 +- view/frontend/web/js/validator-mixin.js | 19 +++++++++++++++++++ 10 files changed, 30 insertions(+), 12 deletions(-) mode change 100755 => 100644 etc/adminhtml/system.xml mode change 100755 => 100644 etc/config.xml mode change 100755 => 100644 etc/module.xml mode change 100755 => 100644 view/frontend/layout/customer_account_create.xml mode change 100755 => 100644 view/frontend/layout/customer_address_form.xml create mode 100644 view/frontend/requirejs-config.js create mode 100644 view/frontend/web/js/validator-mixin.js diff --git a/Helper/Data.php b/Helper/Data.php index 413014f..629c972 100644 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -125,11 +125,6 @@ public function getPOBoxRule($existingClasses) return $existingClasses; } - public function getPOErrorMessage() - { - return $this->getModuleConfig("shipping_po_box_error_msg", "experius_address_lines"); - } - /** * Return form attribute IDs by form code * diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml old mode 100755 new mode 100644 index 63b3fd7..358cacc --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -109,10 +109,6 @@ Magento\Config\Model\Config\Source\Yesno - - - The error to show when the user enters a PO Box, parcel locker, etc. - diff --git a/etc/config.xml b/etc/config.xml old mode 100755 new mode 100644 index a70225a..2b09530 --- a/etc/config.xml +++ b/etc/config.xml @@ -33,7 +33,6 @@ 1 - We don't ship to PO Boxes, Parcel Lockers, or any postal service. Courier only. diff --git a/etc/module.xml b/etc/module.xml old mode 100755 new mode 100644 diff --git a/view/frontend/layout/customer_account_create.xml b/view/frontend/layout/customer_account_create.xml old mode 100755 new mode 100644 diff --git a/view/frontend/layout/customer_address_form.xml b/view/frontend/layout/customer_address_form.xml old mode 100755 new mode 100644 diff --git a/view/frontend/requirejs-config.js b/view/frontend/requirejs-config.js new file mode 100644 index 0000000..4199e60 --- /dev/null +++ b/view/frontend/requirejs-config.js @@ -0,0 +1,9 @@ +var config = { + config: { + mixins: { + 'Magento_Ui/js/lib/validation/validator': { + 'Experius_AddressLines/js/validator-mixin': true + } + } + } +}; \ No newline at end of file diff --git a/view/frontend/templates/experius/customer/address/edit.phtml b/view/frontend/templates/experius/customer/address/edit.phtml index 8dbf55f..4344a31 100644 --- a/view/frontend/templates/experius/customer/address/edit.phtml +++ b/view/frontend/templates/experius/customer/address/edit.phtml @@ -193,7 +193,7 @@ 'po-box-validation', function (value) { var re = helper('Experius\AddressLines\Helper\Data')->getPOValidationRegex(); ?>; return !re.test(value); - }, "helper('Experius\AddressLines\Helper\Data')->getPOErrorMessage(); ?>" + }, $.mage.__("We don't ship to PO Boxes, Parcel Lockers, or any postal service. Courier only.") ); }); diff --git a/view/frontend/templates/experius/customer/form/register.phtml b/view/frontend/templates/experius/customer/form/register.phtml index 7292bcd..eafa07d 100644 --- a/view/frontend/templates/experius/customer/form/register.phtml +++ b/view/frontend/templates/experius/customer/form/register.phtml @@ -230,7 +230,7 @@ require([ 'po-box-validation', function (value) { var re = helper('Experius\AddressLines\Helper\Data')->getPOValidationRegex(); ?>; return !re.test(value); - }, "helper('Experius\AddressLines\Helper\Data')->getPOErrorMessage(); ?>" + }, $.mage.__("We don't ship to PO Boxes, Parcel Lockers, or any postal service. Courier only.") ); }); diff --git a/view/frontend/web/js/validator-mixin.js b/view/frontend/web/js/validator-mixin.js new file mode 100644 index 0000000..25f0942 --- /dev/null +++ b/view/frontend/web/js/validator-mixin.js @@ -0,0 +1,19 @@ +define([ + 'jquery', + 'moment' +], function ($, moment) { + 'use strict'; + + return function (validator) { + + validator.addRule( + 'po-box-validation', + function (value) { + var re = /^parcel.*|^locker.*|^box.*|.*po\s*box.*|.*p[\.\s]o\.?\sbox.*/i + return !re.test(value); + }, $.mage.__("We don't ship to PO Boxes, Parcel Lockers, or any postal service. Courier only.") + ); + + return validator; + }; +})