|
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/AheadworksOsc.php |
Size | 6.04 kb |
Permission | rwxrwxrwx |
Owner | root : root |
Create time | 17-Aug-2025 10:26 |
Last modified | 09-Jul-2024 08:41 |
Last accessed | 22-Aug-2025 10:51 |
Actions | edit | rename | delete | download (gzip) |
View | text | 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 Aheadworks\OneStepCheckout\Block\Checkout;
use Geissweb\Euvat\Helper\Configuration;
use Geissweb\Euvat\Logger\Logger;
use Magento\Framework\Serialize\SerializerInterface;
use Magento\Framework\Module\Manager;
use Magento\Framework\Stdlib\ArrayManager;
/**
* Checkout Layout Modifier for AW Checkout
*/
class AheadworksOsc
{
private Configuration $configHelper;
private Logger $logger;
private SerializerInterface $serializer;
private Manager $moduleManager;
private ArrayManager $arrayManager;
/**
* CheckoutLayout constructor.
*
* @param \Geissweb\Euvat\Helper\Configuration $config
* @param \Geissweb\Euvat\Logger\Logger $logger
* @param \Magento\Framework\Serialize\SerializerInterface $serializer
* @param \Magento\Framework\Module\Manager $moduleManager
* @param \Magento\Framework\Stdlib\ArrayManager $arrayManager
*/
public function __construct(
Configuration $config,
Logger $logger,
SerializerInterface $serializer,
Manager $moduleManager,
ArrayManager $arrayManager
) {
$this->configHelper = $config;
$this->logger = $logger;
$this->serializer = $serializer;
$this->moduleManager = $moduleManager;
$this->arrayManager = $arrayManager;
}
/**
* Add VAT fields to layout
*
* @param \Aheadworks\OneStepCheckout\Block\Checkout $subject
* @param string $originalJsLayout
*
* @return string|bool $jsLayout
*/
public function afterGetJsLayout(
Checkout $subject,
$originalJsLayout
) {
// Check if module is enabled
if (!$this->moduleManager->isEnabled('Aheadworks_OneStepCheckout')
|| !$this->configHelper->getConfig('aw_osc/general/enabled')
|| !$this->configHelper->isValidationEnabled()
) {
return $originalJsLayout;
}
$jsLayout = $this->serializer->unserialize($originalJsLayout);
//$this->logger->customLog("Aheadworks complete OriginalLayout: ".var_export($jsLayout, true));
$vatIdSections = $this->arrayManager->findPaths('vat_id', $jsLayout);
foreach ($vatIdSections as $vatIdSectionPath) {
$sectionData = $this->arrayManager->get($vatIdSectionPath, $jsLayout);
if (is_array($sectionData) && isset($sectionData['config'])) {
if (strpos($vatIdSectionPath, 'billing') !== false) {
[$awShippingIsVisible, $awShippingSortOrder] = $this->loadAheadworksVatIdConfig('billing');
$fieldLayout = [
'component' => 'Geissweb_Euvat/js/form/element/vat-number-aheadworks',
'config' => $this->configHelper->getVatFieldConfigAheadworks($sectionData['config'], 'billingAddress'),
'dataScope' => 'billingAddress.vat_id',
'visible' => $awShippingIsVisible,
'sortOrder' => $awShippingSortOrder,
'validation' => $this->configHelper->getFieldValidationAtCheckout()
];
} elseif (strpos($vatIdSectionPath, 'shipping') !== false) {
[$awShippingIsVisible, $awShippingSortOrder] = $this->loadAheadworksVatIdConfig('shipping');
$fieldLayout = [
'component' => 'Geissweb_Euvat/js/form/element/vat-number-aheadworks',
'config' => $this->configHelper->getVatFieldConfigAheadworks($sectionData['config'], 'shippingAddress'),
'dataScope' => 'shippingAddress.vat_id',
'visible' => $awShippingIsVisible,
'sortOrder' => $awShippingSortOrder,
'validation' => $this->configHelper->getFieldValidationAtCheckout()
];
}
if (isset($fieldLayout)) {
$sectionDataModded = array_merge($sectionData, $fieldLayout);
$jsLayout = $this->arrayManager->replace($vatIdSectionPath, $jsLayout, $sectionDataModded);
unset($fieldLayout);
}
}
}
$this->logger->customLog("Aheadworks MODDED layout: ".var_export($jsLayout, true));
return $this->serializer->serialize($jsLayout);
}
private function loadAheadworksVatIdConfig(string $addressType): array
{
try {
// load custom aheadworks config for shipping address vat_id
$awConfigByPath = $this->configHelper->getConfig(
'aw_osc/'.$addressType.'_customization/fields_customization'
);
if ($awConfigByPath) {
$awFieldConfig = $this->serializer->unserialize($awConfigByPath, ['allowed_classes' => false]);
if (isset($awFieldConfig['attributes']['vat_id']['visible'])) {
$awIsVisible = (bool)$awFieldConfig['attributes']['vat_id']['visible'];
}
if (isset($awFieldConfig['rows']['vat_id']['sort_order'])) {
$awSortOrder = (int)$awFieldConfig['rows']['vat_id']['sort_order'];
}
}
return [$awIsVisible ?? true, $awSortOrder ?? 120];
} catch (\Exception $e) {
$this->logger->customLog("Error loading Aheadworks config: ".$e->getMessage());
}
return [true, 120];
}
}
/**
* ||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 Aheadworks\OneStepCheckout\Block\Checkout;
use Geissweb\Euvat\Helper\Configuration;
use Geissweb\Euvat\Logger\Logger;
use Magento\Framework\Serialize\SerializerInterface;
use Magento\Framework\Module\Manager;
use Magento\Framework\Stdlib\ArrayManager;
/**
* Checkout Layout Modifier for AW Checkout
*/
class AheadworksOsc
{
private Configuration $configHelper;
private Logger $logger;
private SerializerInterface $serializer;
private Manager $moduleManager;
private ArrayManager $arrayManager;
/**
* CheckoutLayout constructor.
*
* @param \Geissweb\Euvat\Helper\Configuration $config
* @param \Geissweb\Euvat\Logger\Logger $logger
* @param \Magento\Framework\Serialize\SerializerInterface $serializer
* @param \Magento\Framework\Module\Manager $moduleManager
* @param \Magento\Framework\Stdlib\ArrayManager $arrayManager
*/
public function __construct(
Configuration $config,
Logger $logger,
SerializerInterface $serializer,
Manager $moduleManager,
ArrayManager $arrayManager
) {
$this->configHelper = $config;
$this->logger = $logger;
$this->serializer = $serializer;
$this->moduleManager = $moduleManager;
$this->arrayManager = $arrayManager;
}
/**
* Add VAT fields to layout
*
* @param \Aheadworks\OneStepCheckout\Block\Checkout $subject
* @param string $originalJsLayout
*
* @return string|bool $jsLayout
*/
public function afterGetJsLayout(
Checkout $subject,
$originalJsLayout
) {
// Check if module is enabled
if (!$this->moduleManager->isEnabled('Aheadworks_OneStepCheckout')
|| !$this->configHelper->getConfig('aw_osc/general/enabled')
|| !$this->configHelper->isValidationEnabled()
) {
return $originalJsLayout;
}
$jsLayout = $this->serializer->unserialize($originalJsLayout);
//$this->logger->customLog("Aheadworks complete OriginalLayout: ".var_export($jsLayout, true));
$vatIdSections = $this->arrayManager->findPaths('vat_id', $jsLayout);
foreach ($vatIdSections as $vatIdSectionPath) {
$sectionData = $this->arrayManager->get($vatIdSectionPath, $jsLayout);
if (is_array($sectionData) && isset($sectionData['config'])) {
if (strpos($vatIdSectionPath, 'billing') !== false) {
[$awShippingIsVisible, $awShippingSortOrder] = $this->loadAheadworksVatIdConfig('billing');
$fieldLayout = [
'component' => 'Geissweb_Euvat/js/form/element/vat-number-aheadworks',
'config' => $this->configHelper->getVatFieldConfigAheadworks($sectionData['config'], 'billingAddress'),
'dataScope' => 'billingAddress.vat_id',
'visible' => $awShippingIsVisible,
'sortOrder' => $awShippingSortOrder,
'validation' => $this->configHelper->getFieldValidationAtCheckout()
];
} elseif (strpos($vatIdSectionPath, 'shipping') !== false) {
[$awShippingIsVisible, $awShippingSortOrder] = $this->loadAheadworksVatIdConfig('shipping');
$fieldLayout = [
'component' => 'Geissweb_Euvat/js/form/element/vat-number-aheadworks',
'config' => $this->configHelper->getVatFieldConfigAheadworks($sectionData['config'], 'shippingAddress'),
'dataScope' => 'shippingAddress.vat_id',
'visible' => $awShippingIsVisible,
'sortOrder' => $awShippingSortOrder,
'validation' => $this->configHelper->getFieldValidationAtCheckout()
];
}
if (isset($fieldLayout)) {
$sectionDataModded = array_merge($sectionData, $fieldLayout);
$jsLayout = $this->arrayManager->replace($vatIdSectionPath, $jsLayout, $sectionDataModded);
unset($fieldLayout);
}
}
}
$this->logger->customLog("Aheadworks MODDED layout: ".var_export($jsLayout, true));
return $this->serializer->serialize($jsLayout);
}
private function loadAheadworksVatIdConfig(string $addressType): array
{
try {
// load custom aheadworks config for shipping address vat_id
$awConfigByPath = $this->configHelper->getConfig(
'aw_osc/'.$addressType.'_customization/fields_customization'
);
if ($awConfigByPath) {
$awFieldConfig = $this->serializer->unserialize($awConfigByPath, ['allowed_classes' => false]);
if (isset($awFieldConfig['attributes']['vat_id']['visible'])) {
$awIsVisible = (bool)$awFieldConfig['attributes']['vat_id']['visible'];
}
if (isset($awFieldConfig['rows']['vat_id']['sort_order'])) {
$awSortOrder = (int)$awFieldConfig['rows']['vat_id']['sort_order'];
}
}
return [$awIsVisible ?? true, $awSortOrder ?? 120];
} catch (\Exception $e) {
$this->logger->customLog("Error loading Aheadworks config: ".$e->getMessage());
}
return [true, 120];
}
}