b374k
m1n1 1.01
Apache/2.4.41 (Ubuntu)
Linux vmi616275.contaboserver.net 5.4.0-84-generic #94-Ubuntu SMP Thu Aug 26 20:27:37 UTC 2021 x86_64
uid=33(www-data) gid=33(www-data) groups=33(www-data)
server ip : 62.171.164.128 | your ip : 127.0.0.1
safemode OFF
 >  / home / dev2.destoffenstraat.com / app / code / Geissweb / Euvat / Plugin / CheckoutLayout /
Filename/home/dev2.destoffenstraat.com/app/code/Geissweb/Euvat/Plugin/CheckoutLayout/DefaultCheckout.php
Size8.69 kb
Permissionrwxrwxrwx
Ownerroot : root
Create time17-Aug-2025 10:26
Last modified09-Jul-2024 08:41
Last accessed21-Aug-2025 02:07
Actionsedit | rename | delete | download (gzip)
Viewtext | code | image
<?php
/**
* ||GEISSWEB| EU VAT Enhanced
*
* NOTICE OF LICENSE
*
* This source file is subject to the GEISSWEB End User License Agreement
* that is available through the world-wide-web at this URL: https://www.geissweb.de/legal-information/eula
*
* DISCLAIMER
*
* Do not edit this file if you wish to update the extension in the future. If you wish to customize the extension
* for your needs please refer to our support for more information.
*
* @copyright Copyright (c) 2015 GEISS Weblösungen (https://www.geissweb.de)
* @license https://www.geissweb.de/legal-information/eula GEISSWEB End User License Agreement
*/
declare(strict_types=1);

namespace Geissweb\Euvat\Plugin\CheckoutLayout;

use Geissweb\Euvat\Helper\Configuration;
use Geissweb\Euvat\Logger\Logger;
use Magento\Checkout\Block\Checkout\LayoutProcessor;

/**
* Class CheckoutLayout
*/
class DefaultCheckout
{
/**
* @var \Geissweb\Euvat\Helper\Configuration
*/
public Configuration $configHelper;

/**
* @var \Geissweb\Euvat\Logger\Logger
*/
public Logger $logger;

/**
* CheckoutLayout constructor.
*
* @param Configuration $config
* @param Logger $logger
*/
public function __construct(
Configuration $config,
Logger $logger
) {
$this->configHelper = $config;
$this->logger = $logger;
}

/**
* Process layout changes
*
* @param LayoutProcessor $subject
* @param array $jsLayout
* @return array $jsLayout
*/
public function afterProcess(
LayoutProcessor $subject,
array $jsLayout
): array {
if (!$this->configHelper->isValidationEnabled()) {
return $jsLayout;
}

$originalLayout = [];
if (isset($jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']
['shippingAddress']['children']['shipping-address-fieldset']['children']['vat_id'])
) {
$originalLayout = $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']
['children']['shippingAddress']['children']['shipping-address-fieldset']['children']['vat_id'];
$this->logger->customLog("[CheckoutLayoutAfterProcess] OriginalLayout: "
. var_export($originalLayout, true));
}

$formFieldValidationAtCheckout = $this->configHelper->getFieldValidationAtCheckout();

$configParam = $originalLayout['config'] ?? [];
$fieldLayout = [
'label' => __('VAT Number'),
'component' => 'Geissweb_Euvat/js/form/element/vat-number-co',
'config' => $this->configHelper->getVatFieldConfig($configParam, 'shippingAddress'),
'dataScopePrefix' => $originalLayout['dataScopePrefix'] ?? 'shippingAddress',
'dataScope' => $originalLayout['dataScope'] ?? 'shippingAddress.vat_id',
'provider' => 'checkoutProvider',
'visible' => true,
'sortOrder' => $originalLayout['sortOrder'] ?? 120,
'validation' => $formFieldValidationAtCheckout
];
$fieldLayout = array_merge($originalLayout, $fieldLayout);
$this->logger->customLog("[CheckoutLayoutAfterProcess] Modified layout: "
. var_export($fieldLayout, true));

//Mageplaza_Osc
if ($this->configHelper->getIsMageplazaCheckoutEnabled()) {
$fieldLayout['component'] = 'Geissweb_Euvat/js/form/element/vat-number-mageplaza';
$fieldLayout['config'] = $this->configHelper->getVatFieldConfigMageplaza($configParam);
}

//Swissup_Firecheckout
if ($this->configHelper->getIsFireCheckoutEnabled()) {
$fieldLayout['config']['template'] = 'Geissweb_Euvat/vatfield-firecheckout';
}

/**
* This adjustment will be removed from version 1.22.0
*
* @deprecated
*/
if ($this->configHelper->getIsAmastyCheckoutEnabled()) {
$fieldLayout['component'] = 'Geissweb_Euvat/js/form/element/vat-number-amasty';
}

//Add field to shipping address
$jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']
['shippingAddress']['children']['shipping-address-fieldset']['children']['vat_id'] = $fieldLayout;

$this->logger->customLog(var_export($jsLayout['components']['checkout']['children']['steps']
['children']['shipping-step']['children']['shippingAddress']['children']['shipping-address-fieldset']
['children']['vat_id'], true));

//Add field to billing addresses
if (isset($jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']
['payment']['children']['payments-list']['children'])
) {
foreach ($jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']
['payment']['children']['payments-list']['children'] as $paymentGroup => $groupConfig) {
if (!$this->isDisallowedPaymentGroup($paymentGroup)) {
$scopeName = str_replace("-form", '', $paymentGroup);
$fieldLayout['config'] = $this->configHelper->getVatFieldConfig(
$configParam,
'billingAddress' . $scopeName
);
$fieldLayout['dataScopePrefix'] = 'billingAddress' . $scopeName;
$fieldLayout['dataScope'] = 'billingAddress' . $scopeName . '.vat_id';
$jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']
['payment']['children']['payments-list']['children'][$paymentGroup]['children']
['form-fields']['children']['vat_id'] = $fieldLayout;
}
}
}

//Add field to billing address when address is set to be shown on "Payment Page" instead of "Payment Method"
if (isset($jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']
['payment']['children']['afterMethods']['children']['billing-address-form']['children']['form-fields']
['children']['vat_id'])
) {
$billingFieldLayout = $jsLayout['components']['checkout']['children']['steps']['children']['billing-step']
['children']['payment']['children']['afterMethods']['children']['billing-address-form']['children']
['form-fields']['children']['vat_id'];

$billingConfigParam = $billingFieldLayout['config'] ?? [];
$billingFieldLayout = [
'component' => 'Geissweb_Euvat/js/form/element/vat-number-co',
'config' => $this->configHelper->getVatFieldConfig($billingConfigParam, 'billingAddressshared'),
'dataScopePrefix' => 'billingAddressshared',
'dataScope' => 'billingAddressshared.vat_id',
'provider' => 'checkoutProvider',
'visible' => true,
'validation' => $formFieldValidationAtCheckout
];
$billingFieldLayout = array_merge($billingFieldLayout, $billingFieldLayout);
$jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']
['payment']['children']['afterMethods']['children']['billing-address-form']['children']['form-fields']
['children']['vat_id'] = $billingFieldLayout;

$this->logger->customLog(var_export($jsLayout['components']['checkout']['children']['steps']['children']
['billing-step']['children']['payment']['children']['afterMethods']['children']['billing-address-form']
['children']['form-fields']['children']['vat_id'], true));
}

if (isset($formFieldValidationAtCheckout['valid-vat-required'])) {
$jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']
['payment']['children']['additional-payment-validators']['children']['vat-id-required-validator'] = [
'component' => 'Geissweb_Euvat/js/view/vat-validators'
];
}

return $jsLayout;
}

/**
* Check if payment group is disallowed
*
* @param string|null $paymentGroup
* @return bool
*/
private function isDisallowedPaymentGroup(?string $paymentGroup) : bool
{
$paymentGroups = [
'before-place-order',
'paypal-captcha',
'braintree-recaptcha',
'paypal-method-extra-content', // EE
'braintree-recaptcha-container' // EE
];
if (in_array($paymentGroup, $paymentGroups)) {
return true;
}
return false;
}
}