Skip to content

Commit

Permalink
[FEATURE][IN23-253] Update module to be compatible with Magento 2.4.6…
Browse files Browse the repository at this point in the history
…-p3 and PHP 8.2
  • Loading branch information
borisvankatwijk committed Oct 27, 2023
1 parent 1be03d5 commit ebe9685
Show file tree
Hide file tree
Showing 18 changed files with 812 additions and 395 deletions.
181 changes: 112 additions & 69 deletions Block/Checkout/LayoutProcessor.php
Original file line number Diff line number Diff line change
@@ -1,122 +1,167 @@
<?php
/**
* Copyright © Happy Horizon Utrecht Development & Technology B.V. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Experius\AddressLines\Block\Checkout;

class LayoutProcessor implements \Magento\Checkout\Block\Checkout\LayoutProcessorInterface{

protected $scopeConfig;

protected $logger;

protected $addressLineHelper;

use Experius\AddressLines\Helper\Data;
use Magento\Checkout\Block\Checkout\LayoutProcessorInterface;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Psr\Log\LoggerInterface;

class LayoutProcessor implements LayoutProcessorInterface
{
/**
* @param ScopeConfigInterface $scopeConfig
* @param LoggerInterface $logger
* @param Data $addressLineHelper
*/
public function __construct(
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
\Psr\Log\LoggerInterface $logger,
\Experius\AddressLines\Helper\Data $addressLineHelper
){
$this->scopeConfig = $scopeConfig;
$this->logger = $logger;
$this->addressLineHelper = $addressLineHelper;
protected ScopeConfigInterface $scopeConfig,
protected LoggerInterface $logger,
protected Data $addressLineHelper
) {
}

public function process($result){

if(!$this->addressLineHelper->getModuleConfig('enabled')) {
return $result;
/**
* @inheritdoc
*/
public function process($jsLayout)
{
if (!$this->addressLineHelper->getModuleConfig('enabled')) {
return $jsLayout;
}

if(isset($result['components']['checkout']['children']['steps']['children']
['shipping-step']['children']['shippingAddress']['children']
['shipping-address-fieldset'])) {

$shippingFields = $result['components']['checkout']['children']['steps']['children']
['shipping-step']['children']['shippingAddress']['children']
['shipping-address-fieldset']['children'];
if (isset($jsLayout['components']['checkout']
['children']['steps']
['children']['shipping-step']
['children']['shippingAddress']
['children']['shipping-address-fieldset'])
) {
$shippingFields = $jsLayout['components']['checkout']
['children']['steps']
['children']['shipping-step']
['children']['shippingAddress']
['children']['shipping-address-fieldset']
['children'];

$shippingFields = $this->modifyStreetUiComponents($shippingFields);

$result['components']['checkout']['children']['steps']['children']
['shipping-step']['children']['shippingAddress']['children']
['shipping-address-fieldset']['children'] = $shippingFields;
$jsLayout['components']['checkout']
['children']['steps']
['children']['shipping-step']
['children']['shippingAddress']
['children']['shipping-address-fieldset']
['children'] = $shippingFields;

}

$result = $this->getBillingFormFields($result);
$jsLayout = $this->getBillingFormFields($jsLayout);

return $result;
return $jsLayout;
}


public function getBillingFormFields($result){

if(isset($result['components']['checkout']['children']['steps']['children']
['billing-step']['children']['payment']['children']
['payments-list'])) {

$paymentForms = $result['components']['checkout']['children']['steps']['children']
['billing-step']['children']['payment']['children']
['payments-list']['children'];

foreach ($paymentForms as $paymentMethodForm => $paymentMethodValue) {

/**
* @param $jsLayout
* @return array
*/
public function getBillingFormFields($jsLayout)
{
if (isset($jsLayout['components']['checkout']
['children']['steps']
['children']['billing-step']
['children']['payment']
['children']['payments-list'])
) {
$paymentForms = $jsLayout['components']['checkout']
['children']['steps']
['children']['billing-step']
['children']['payment']
['children']['payments-list']
['children'];

foreach (array_keys($paymentForms) as $paymentMethodForm) {
$paymentMethodCode = str_replace('-form', '', $paymentMethodForm);

if (!isset($result['components']['checkout']['children']['steps']['children']['billing-step']['children']['payment']['children']['payments-list']['children'][$paymentMethodCode . '-form'])) {
if (!isset($jsLayout['components']['checkout']
['children']['steps']
['children']['billing-step']
['children']['payment']
['children']['payments-list']
['children'][$paymentMethodCode . '-form'])
) {
continue;
}

$billingFields = $result['components']['checkout']['children']['steps']['children']
['billing-step']['children']['payment']['children']
['payments-list']['children'][$paymentMethodCode . '-form']['children']['form-fields']['children'];
$billingFields = $jsLayout['components']['checkout']
['children']['steps']
['children']['billing-step']
['children']['payment']
['children']['payments-list']
['children'][$paymentMethodCode . '-form']
['children']['form-fields']
['children'];

$billingFields = $this->modifyStreetUiComponents($billingFields);

$result['components']['checkout']['children']['steps']['children']
['billing-step']['children']['payment']['children']
['payments-list']['children'][$paymentMethodCode . '-form']['children']['form-fields']['children'] = $billingFields;

$jsLayout['components']['checkout']
['children']['steps']
['children']['billing-step']
['children']['payment']
['children']['payments-list']
['children'][$paymentMethodCode . '-form']
['children']['form-fields']
['children'] = $billingFields;
}
}

return $result;

return $jsLayout;
}

/**
* @param $addressResult
* @return array
*/
public function modifyStreetUiComponents($addressResult)
{
if(isset($addressResult['street']['label'])){
if (isset($addressResult['street']['label'])) {
unset($addressResult['street']['label']);
unset($addressResult['street']['required']);
}

if(isset($addressResult['street'])){
if (isset($addressResult['street'])) {
unset($addressResult['street']['children'][1]['validation']);
unset($addressResult['street']['children'][2]['validation']);
}

if(isset($addressResult['street']['config']['template'])) {
if (isset($addressResult['street']['config']['template'])) {
$addressResult['street']['config']['template'] = 'Experius_AddressLines/group/group';
}

if(isset($addressResult['street']['config']['additionalClasses'])) {
$addressResult['street']['config']['additionalClasses'] = $addressResult['street']['config']['additionalClasses'] . ' experius-address-lines';
if (isset($addressResult['street']['config']['additionalClasses'])) {
$addressResult['street']['config']['additionalClasses'] =
$addressResult['street']['config']['additionalClasses'] . ' experius-address-lines';
}

$lineCount = 0;

while($lineCount < 4){

$lineNumber = $lineCount+1;
while ($lineCount < 4) {

if(isset($addressResult['street']['children'][$lineCount])){
$lineNumber = $lineCount + 1;

if (isset($addressResult['street']['children'][$lineCount])) {
$label = $this->addressLineHelper->getLineLabel($lineNumber);
if ( $this->addressLineHelper->isLineEnabled($lineNumber)) {

if ($this->addressLineHelper->isLineEnabled($lineNumber)) {
$addressResult['street']['children'][$lineCount]['label'] = $label;
$addressResult['street']['children'][$lineCount]['additionalClasses'] = 'experius-address-line-one';
$addressResult['street']['children'][$lineCount]['validation'] = $this->addressLineHelper->getValidationClassesAsArrayForLine($lineNumber);
$addressResult['street']['children'][$lineCount]['required'] = ($this->addressLineHelper->isLineRequired($lineNumber)) ? True : False;
$addressResult['street']['children'][$lineCount]['validation'] =
$this->addressLineHelper->getValidationClassesAsArrayForLine($lineNumber);
$addressResult['street']['children'][$lineCount]['required'] =
(bool)$this->addressLineHelper->isLineRequired($lineNumber);
}
}

Expand All @@ -125,6 +170,4 @@ public function modifyStreetUiComponents($addressResult)

return $addressResult;
}


}
99 changes: 99 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
## 1.3.0 (2023-10-27)

[View Release]([email protected]:experius/Magento-2-Module-Experius-Address-Lines.git/commits/tag/1.3.0)

* [FEATURE][IN23-253] Update module to be compatible with Magento 2.4.6-p3 and PHP 8.2 *(Boris van Katwijk)*


## 1.2.8 (2023-04-24)

[View Release]([email protected]:experius/Magento-2-Module-Experius-Address-Lines.git/commits/tag/1.2.8)

* Fix for PHP 8.1 *(Peter Jaap Blaakmeer)*


## 1.2.7 (2017-11-30)

[View Release]([email protected]:experius/Magento-2-Module-Experius-Address-Lines.git/commits/tag/1.2.7)

* Added form_key to create account form *(Experius)*


## 1.2.6 (2017-09-04)

[View Release]([email protected]:experius/Magento-2-Module-Experius-Address-Lines.git/commits/tag/1.2.6)

* [BUGFIX] Solved error that occurred if config validation was left empty *(bartlubbersen)*


## 1.2.5 (2017-07-04)

[View Release]([email protected]:experius/Magento-2-Module-Experius-Address-Lines.git/commits/tag/1.2.5)

* [TASK] Added required validation and check if isUsedInForm for the Customer Address Edit Form *(Lewis Voncken)*


## 1.2.4 (2017-07-04)

[View Release]([email protected]:experius/Magento-2-Module-Experius-Address-Lines.git/commits/tag/1.2.4)

* [TASK] Added Required Label based on attribute is required-entry class *(Lewis Voncken)*


## 1.2.3 (2017-07-03)

[View Release]([email protected]:experius/Magento-2-Module-Experius-Address-Lines.git/commits/tag/1.2.3)

* [TASK] Added isUsedInForm to check if Address Fields telephone and company is used in Registration form *(Lewis Voncken)*
* [BUGFIX] custom street group.html template to fix layout issues on blank. Fixed issued where current additional classes where replaced instead of added *(Derrick Heesbeen)*


## 1.2.2 (2017-05-05)

[View Release]([email protected]:experius/Magento-2-Module-Experius-Address-Lines.git/commits/tag/1.2.2)

* [BUGFIX] Solved problem with check of enabled and required function *(Lewis Voncken)*
* [BUGFIX] added missing character *(Lewis Voncken)*


## 1.2.1 (2017-05-02)

[View Release]([email protected]:experius/Magento-2-Module-Experius-Address-Lines.git/commits/tag/1.2.1)

* [FEATURE] Added AddressLine Support to the Registration and AddressEdit form *(Lewis Voncken)*


## 1.0.1 (2017-01-26)

[View Release]([email protected]:experius/Magento-2-Module-Experius-Address-Lines.git/commits/tag/1.0.1)



## 1.1.0 (2017-01-26)

[View Release]([email protected]:experius/Magento-2-Module-Experius-Address-Lines.git/commits/tag/1.1.0)



## 1.2.0 (2017-01-26)

[View Release]([email protected]:experius/Magento-2-Module-Experius-Address-Lines.git/commits/tag/1.2.0)

* added license *(Derrick Heesbeen)*
* changed module name *(Derrick Heesbeen)*
* Add files via upload *(robbertstevens)*
* Correct composer.json according to Magento standards *(bartlubbersen)*
* Resolved error when compiling *(Tjitse-E)*


## 1.0.0 (2016-11-09)

[View Release]([email protected]:experius/Magento-2-Module-Experius-Address-Lines.git/commits/tag/1.0.0)

* First Commit *(Derrick Heesbeen)*
* Added configuration *(Derrick Heesbeen)*
* screenshots for readme *(Derrick Heesbeen)*
* Update README.md *(Derrick Heesbeen)*
* Update README.md *(Derrick Heesbeen)*


6 changes: 6 additions & 0 deletions COPYING.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Copyright © 2023-present Happy Horizon Utrecht Development & Technology B.V.

This file included in Experius/AddressLines is licensed under OSL 3.0

http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
Please see LICENSE.txt for the full text of the OSL 3.0 license
Loading

0 comments on commit ebe9685

Please sign in to comment.