diff --git a/Block/Adminhtml/Config/Support/Tab.php b/Block/Adminhtml/Config/Support/Tab.php index bf8883d..51298c1 100644 --- a/Block/Adminhtml/Config/Support/Tab.php +++ b/Block/Adminhtml/Config/Support/Tab.php @@ -40,7 +40,7 @@ class Tab extends Template implements RendererInterface { const MODULE_NAME = 'TIG_Postcode'; - const EXTENSION_VERSION = '1.5.1'; + const EXTENSION_VERSION = '1.5.2'; // @codingStandardsIgnoreLine protected $_template = 'TIG_Postcode::config/support/tab.phtml'; diff --git a/Plugin/Checkout/Model/GuestPaymentInformationManagement.php b/Plugin/Checkout/Model/GuestPaymentInformationManagement.php index 43b2ede..14c5c94 100644 --- a/Plugin/Checkout/Model/GuestPaymentInformationManagement.php +++ b/Plugin/Checkout/Model/GuestPaymentInformationManagement.php @@ -64,9 +64,11 @@ public function beforeSavePaymentInformation( $cartId, $email, PaymentInterface $paymentMethod, - AddressInterface $address + AddressInterface $address = null ) { - $extAttributes = $address->getExtensionAttributes(); - $this->fieldsHelper->copyFieldsFromExtensionAttributesToObject($extAttributes, $address); + if ($address) { + $extAttributes = $address->getExtensionAttributes(); + $this->fieldsHelper->copyFieldsFromExtensionAttributesToObject($extAttributes, $address); + } } } diff --git a/Plugin/Checkout/Model/PaymentInformationManagement.php b/Plugin/Checkout/Model/PaymentInformationManagement.php index c4c3d19..b3e18e3 100644 --- a/Plugin/Checkout/Model/PaymentInformationManagement.php +++ b/Plugin/Checkout/Model/PaymentInformationManagement.php @@ -32,9 +32,11 @@ public function beforeSavePaymentInformation( \Magento\Checkout\Model\PaymentInformationManagement $subject, $cartId, PaymentInterface $paymentMethod, - AddressInterface $address + AddressInterface $address = null ) { - $extAttributes = $address->getExtensionAttributes(); - $this->fieldsHelper->copyFieldsFromExtensionAttributesToObject($extAttributes, $address); + if ($address) { + $extAttributes = $address->getExtensionAttributes(); + $this->fieldsHelper->copyFieldsFromExtensionAttributesToObject($extAttributes, $address); + } } } diff --git a/Plugin/Model/Checkout/LayoutProcessorPlugin.php b/Plugin/Model/Checkout/LayoutProcessorPlugin.php index 526bc7d..0b5e2ad 100644 --- a/Plugin/Model/Checkout/LayoutProcessorPlugin.php +++ b/Plugin/Model/Checkout/LayoutProcessorPlugin.php @@ -152,7 +152,7 @@ public function createHousenumberFieldsDefinition($dataScope) */ private function getParentPath($path, $delimiter = '/', $count = 1) { - $splitPath = explode($delimiter, $path); + $splitPath = !empty($path) ? explode($delimiter, $path) : []; for ($i = 0; $i < $count; $i++) { array_pop($splitPath); } diff --git a/Plugin/Model/Osc/LayoutProcessorPlugin.php b/Plugin/Model/Osc/LayoutProcessorPlugin.php index 00ce5f1..9b29d0a 100644 --- a/Plugin/Model/Osc/LayoutProcessorPlugin.php +++ b/Plugin/Model/Osc/LayoutProcessorPlugin.php @@ -152,7 +152,7 @@ public function createHousenumberFieldsDefinition($dataScope) */ private function getParentPath($path, $delimiter = '/', $count = 1) { - $splitPath = explode($delimiter, $path); + $splitPath = !empty($path) ? explode($delimiter, $path) : []; for ($i = 0; $i < $count; $i++) { array_pop($splitPath); } diff --git a/Plugin/Model/ResourceModel/Country/CollectionPlugin.php b/Plugin/Model/ResourceModel/Country/CollectionPlugin.php index 7b6074e..c173e66 100644 --- a/Plugin/Model/ResourceModel/Country/CollectionPlugin.php +++ b/Plugin/Model/ResourceModel/Country/CollectionPlugin.php @@ -75,7 +75,7 @@ public function __construct( private function getPostcodeNLConfig($sortOrderBase, $sortOrderIncrement): array { return [ - 'enabled' => $this->moduleConfiguration->isNLCheckEnabled(), + 'enabled' => $this->moduleConfiguration->isNLCheckEnabled() && !$this->moduleConfiguration->isModusOff(), 'postcode' => [ 'sortOrder' => $sortOrderBase, 'classes' => [ @@ -103,7 +103,7 @@ private function getPostcodeNLConfig($sortOrderBase, $sortOrderIncrement): array ], 'tig_street' => [ 'sortOrder' => $sortOrderBase + 3 * $sortOrderIncrement, - 'visible' => true, + 'visible' => false, 'classes' => [ 'tig_street_field' => true, 'tig_postcode_nl' => true @@ -136,7 +136,7 @@ private function getPostcodeNLConfig($sortOrderBase, $sortOrderIncrement): array */ private function getPostcodeBEConfig($sortOrderBase, $sortOrderIncrement) { return [ - 'enabled' => $this->moduleConfiguration->isBECheckEnabled(), + 'enabled' => $this->moduleConfiguration->isBECheckEnabled() && !$this->moduleConfiguration->isModusOff(), 'postcode' => [ 'sortOrder' => $sortOrderBase, 'classes' => [ diff --git a/README.md b/README.md index f255234..5865540 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,89 @@ -# TIG Postcode validation Magento 2 +

-[![Coverage Status](https://coveralls.io/repos/github/tig-nl/postcode-magento2/badge.svg?branch=%28no+branch%29)](https://coveralls.io/github/tig-nl/postcode-magento2?branch=%28no+branch%29) [![Build Status](https://travis-ci.org/tig-nl/postcode-magento2.svg?branch=master)](https://travis-ci.org/tig-nl/postcode-magento2) +# Postcode Service Magento 2 +[![Latest Stable Version](https://img.shields.io/github/v/release/tig-nl/postcode-magento2?style=for-the-badge&color=227cff)](https://github.com/tig-nl/postcode-magento2/releases/latest) +![TIG Postcode Service 2.3.7 versions](https://img.shields.io/badge/Tested%20with%20Magento-2.3.7-%2300cf00?style=for-the-badge) +![TIG Postcode Service 2.4.5 versions](https://img.shields.io/badge/Tested%20with%20Magento-2.4.5-%2300cf00?style=for-the-badge) +[![Total Extension downloads](https://img.shields.io/packagist/dt/tig/postcode-magento2?style=for-the-badge&color=227cff)](https://packagist.org/packages/tig-nl/postcode-magento2/stats) +![Build Status](https://img.shields.io/travis/tig-nl/postcode-magento2/master?style=for-the-badge) -Install the extension with composer + +## Requirements +- Magento version 2.4.5, 2.4.4, 2.3.7 or 2.3.6 +- PHP 7.3+ + +## Installation +We strongly recommend that you use a Staging Environment for the installation, and to also make a backup of your environment. + +### Installation using composer (recommended) +To install the extension login to your environment using SSH. Then navigate to the Magento 2 root directory and run the following commands in the same order as described: + +Enable maintenance mode: +~~~~shell +php bin/magento maintenance:enable ~~~~ + +1. Install the extension: +~~~~shell composer require tig/postcode-magento2 ~~~~ +2. Enable the Postcode Service Magento 2 extension +~~~~shell +php bin/magento module:enable TIG_Postcode +~~~~ + +3. Update the Magento 2 environment: +~~~~shell +php bin/magento setup:upgrade +~~~~ + +When your Magento environment is running in production mode, you also need to run the following comands: + +4. Compile DI: +~~~~shell +php bin/magento setup:di:compile +~~~~ + +5. Deploy static content: +~~~~shell +php bin/magento setup:static-content:deploy +~~~~ + +6. Disable maintenance mode: +~~~~shell +php bin/magento maintenance:disable +~~~~ + +### Installation manually +1. Download the extension directly from [github](https://github.com/tig-nl/postcode-magento2) by clicking on *Code* and then *Download ZIP*. +2. Create the directory *app/code/TIG/Postcode* (Case-sensitive) +3. Extract the zip and upload the code into *app/code/TIG/Postcode* +4. Enable the Postcode Service Magento 2 extension +~~~~shell +php bin/magento module:enable TIG_Postcode +~~~~ + +5. Update the Magento 2 environment: +~~~~shell +php bin/magento setup:upgrade +~~~~ + +## Update +To update the Postcode Service Extension run the following commands: +~~~~shell +composer update tig/postcode-magento2 +php bin/magento setup:upgrade +~~~~ + +## Examples + +### Dutch Postcode Service within the Magento 2 checkout +![Postcode Service Magento 2 Checkout NL](https://postcodeservice.com/wp-content/uploads/2022/08/postcodeservice-magento-2-nl.gif "Postcode Service Magento 2 Checkout NL") + +### Belgium Postcode Service within the Magento 2 checkout +![Postcode Service Magento 2 Checkout BE](https://postcodeservice.com/wp-content/uploads/2022/08/postcodeservice-magento-2-be.gif "Postcode Service Magento 2 Checkout NL") +## Documentation For further installation guidance https://developers.postcodeservice.com/ diff --git a/Services/Validation/Response.php b/Services/Validation/Response.php index 3b1053b..95d90fe 100644 --- a/Services/Validation/Response.php +++ b/Services/Validation/Response.php @@ -99,7 +99,7 @@ private function checkKeys($data) */ private function checkStreetNameValue($data) { - if (strpos($data['straatnaam'], 'limiet bereikt') !== false) { + if (strpos($data['straatnaam'] ?? '', 'limiet bereikt') !== false) { return false; } diff --git a/Test/Unit/Block/Adminhtml/Config/Support/TabTest.php b/Test/Unit/Block/Adminhtml/Config/Support/TabTest.php index 5211bde..bde7ed6 100644 --- a/Test/Unit/Block/Adminhtml/Config/Support/TabTest.php +++ b/Test/Unit/Block/Adminhtml/Config/Support/TabTest.php @@ -42,7 +42,7 @@ class TabTest extends TestCase public function testGetVersionNumber() { $instance = $this->getInstance(); - $this->assertSame('1.5.1', $instance->getVersionNumber()); + $this->assertSame('1.5.2', $instance->getVersionNumber()); } public function testGetSupportedMagentoVersions() @@ -51,7 +51,7 @@ public function testGetSupportedMagentoVersions() 'moduleConfiguration' => $this->getConfigurationMock() ]); - $this->assertSame('2.3.7, 2.4.4', $instance->getSupportedMagentoVersions()); + $this->assertSame('2.3.7, 2.4.5-p1', $instance->getSupportedMagentoVersions()); } /**+ @@ -62,7 +62,7 @@ private function getConfigurationMock() $mock = $this->getFakeMock(ModuleConfiguration::class)->getMock(); $mockExpects = $mock->expects($this->once()); $mockExpects->method('getSupportedMagentoVersions'); - $mockExpects->willReturn('2.3.7, 2.4.4'); + $mockExpects->willReturn('2.3.7, 2.4.5-p1'); return $mock; } diff --git a/composer.json b/composer.json index eca67c0..e109dd3 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ "magento/module-quote": ">=101.0.5,<=101.0.11|~101.1|~101.2" }, "type": "magento2-module", - "version": "1.5.1", + "version": "1.5.2", "license": "CC-BY-NC-ND-3.0", "authors": [ { diff --git a/etc/config.xml b/etc/config.xml index 8a58f05..9910ee9 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -33,7 +33,7 @@ - 2.3.7, 2.4.4 + 2.3.7, 2.4.5-p1 0 diff --git a/i18n/en_US.csv b/i18n/en_US.csv index bb94626..7150460 100644 --- a/i18n/en_US.csv +++ b/i18n/en_US.csv @@ -32,6 +32,7 @@ Extension status,Extension status "Can not find the address, please fill in manually","Can not find the address, please fill in manually" "Housenumber","Housenumber" "Addition","Addition" +"Housenumber addition","Housenumber addition" "Please select a postcode before filling the street field.","Please select a postcode before filling the street field." "Enable Netherlands check","Enable Netherlands check" "Enable Belgium check","Enable Belgium check" diff --git a/i18n/fr_FR.csv b/i18n/fr_FR.csv index 9eda719..1f69f62 100644 --- a/i18n/fr_FR.csv +++ b/i18n/fr_FR.csv @@ -32,6 +32,7 @@ Disabled,Désactivé "Can not find the address, please fill in manually","Adresse introuvable, veuillez la renseigner manuellement" "Housenumber","Numéro" "Addition","Complément d'adresse" +"Housenumber addition","Ajout de numéro de maison" "Please select a postcode before filling the street field.","Veuillez sélectionner un code postal avant de renseigner le chanp Adresse" "Enable Netherlands check","Activer la vérification pour les Pays-Bas" "Enable Belgium check","Activer la vérification pour la Belgique" diff --git a/i18n/nl_BE.csv b/i18n/nl_BE.csv index d4276cd..6e3c058 100644 --- a/i18n/nl_BE.csv +++ b/i18n/nl_BE.csv @@ -30,15 +30,15 @@ Support,Support "Support by phone","Telefonisch support" "24/7 SLA support","24/7 SLA support" "Can not find the address, please fill in manually","Het adres kan niet gevonden worden, vul alsjeblieft handmatig in" -"House number","Huisnummer" +"Housenumber","Huisnummer" "Addition","Bus" - +"Housenumber addition","Huisnummer toevoeging" "Back-end merging","Back-end samenvoeging" "These settings have impact on how street address data is stored in the database.","Deze instellingen hebben invloed op hoe adres data wordt opgeslagen in de database." "Tampering with the settings may affect the workflow of third party extensions. Use at your own risk.","Het aanpassen van deze instellingen kan de werking van extensies van derden beïnvloeden. Gebruik op eigen risico." "Street address field","Straatnaam veld" "House number field","Huisnummer veld" -"House number addition field","Toevoeging veld" +"Housenumber addition field","Toevoeging veld" "Street address line %1","Adres regel %1" "These settings have no impact on the front-end.","Deze instellingen hebben geen invloed op de frontend." "This extension is developed by Total Internet Group (TIG).","Deze instellingen hebben geen invloed op de frontend." diff --git a/i18n/nl_NL.csv b/i18n/nl_NL.csv index 7bc7a35..d775d4a 100644 --- a/i18n/nl_NL.csv +++ b/i18n/nl_NL.csv @@ -30,15 +30,15 @@ Support,Support "Support by phone","Telefonisch support" "24/7 SLA support","24/7 SLA support" "Can not find the address, please fill in manually","Het adres kan niet gevonden worden, vul alsjeblieft handmatig in" -"House number","Huisnummer" +"Housenumber","Huisnummer" "Addition","Toevoeging" - +"Housenumber addition","Huisnummer toevoeging" "Back-end merging","Back-end samenvoeging" "These settings have impact on how street address data is stored in the database.","Deze instellingen hebben invloed op hoe adres data wordt opgeslagen in de database." "Tampering with the settings may affect the workflow of third party extensions. Use at your own risk.","Het aanpassen van deze instellingen kan de werking van extensies van derden beïnvloeden. Gebruik op eigen risico." "Street address field","Straatnaam veld" "House number field","Huisnummer veld" -"House number addition field","Toevoeging veld" +"Housenumber addition field","Toevoeging veld" "Street address line %1","Adres regel %1" "These settings have no impact on the front-end.","Deze instellingen hebben geen invloed op de frontend." "This extension is developed by Total Internet Group (TIG).","Deze instellingen hebben geen invloed op de frontend." diff --git a/view/base/web/js/postcode-handler/postcode-handler.js b/view/base/web/js/postcode-handler/postcode-handler.js index f347742..19b76c8 100644 --- a/view/base/web/js/postcode-handler/postcode-handler.js +++ b/view/base/web/js/postcode-handler/postcode-handler.js @@ -134,11 +134,11 @@ define([ */ PostcodeHandler.prototype.reset = function() { if (!('tig_postcode' in this.config) || this.config.tig_postcode['enabled'] === false) { - this.currentState = STATE_DISABLED; + this.setCurrentState(STATE_DISABLED); return; } - this.currentState = STATE_INIT; + this.setCurrentState(STATE_INIT); this.postcodeService.setFieldsConfig(this.config.tig_postcode); } diff --git a/view/base/web/js/postcode-handler/postcode-nl.js b/view/base/web/js/postcode-handler/postcode-nl.js index 0284930..741694c 100644 --- a/view/base/web/js/postcode-handler/postcode-nl.js +++ b/view/base/web/js/postcode-handler/postcode-nl.js @@ -33,13 +33,15 @@ define([ 'underscore', './postcode-handler', '../helper/field-types', - '../helper/postcode-api' + '../helper/postcode-api', + 'mage/translate' ], function ( $, _, PostcodeHandler, FieldTypes, - PostcodeApi + PostcodeApi, + $t ) { 'use strict'; @@ -84,7 +86,7 @@ define([ if (data.success !== true) { self.setCurrentState(states.POSTCODE_CALL_FAILED); - self.getPostcodeService().getElement(FieldTypes.postcode).error('Sorry, we could not find the address on the given zip code and house number combination. If you are sure that the zip code and house number are correct, please fill in the address details manually.'); + self.getPostcodeService().getElement(FieldTypes.postcode).error($t('Sorry, we could not find the address on the given zip code and house number combination. If you are sure that the zip code and house number are correct, please fill in the address details manually.')); return; }