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 @@