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 / Swissup / Taxvat / Plugin / Block / Checkout /
Filename/home/dev2.destoffenstraat.com/app/code/Swissup/Taxvat/Plugin/Block/Checkout/LayoutProcessor.php
Size3.78 kb
Permissionrwxrwxrwx
Ownerroot : root
Create time17-Aug-2025 10:26
Last modified13-Jan-2021 14:38
Last accessed23-Aug-2025 02:07
Actionsedit | rename | delete | download (gzip)
Viewtext | code | image
<?php
namespace Swissup\Taxvat\Plugin\Block\Checkout;

class LayoutProcessor
{
/**
* @var \Swissup\Taxvat\Helper\Data $helper
*/
protected $helper;

/**
* @var \Magento\Framework\App\ProductMetadataInterface $magentoMetadata
*/
protected $magentoMetadata;

/**
* @param \Swissup\Taxvat\Helper\Data $helper
* @param \Magento\Framework\App\ProductMetadataInterface $magentoMetadata
*/
public function __construct(
\Swissup\Taxvat\Helper\Data $helper,
\Magento\Framework\App\ProductMetadataInterface $magentoMetadata
) {
$this->helper = $helper;
$this->magentoMetadata = $magentoMetadata;
}

public function afterProcess(
\Magento\Checkout\Block\Checkout\LayoutProcessor $subject,
$jsLayout
) {
if (!$this->helper->canValidateVat()) {
return $jsLayout;
}

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

$this->addVatTooltip(
$jsLayout['components']['checkout']['children']['steps']
['children']['shipping-step']['children']['shippingAddress']
['children']['shipping-address-fieldset']['children']['vat_id']
);
}

// when DisplayBillingOnPaymentMethod is used
if (isset($jsLayout['components']['checkout']['children']['steps']
['children']['billing-step']['children']['payment']['children']
['payments-list']['children'])) {

$this->addVatTooltipToPaymentForms(
$jsLayout['components']['checkout']['children']['steps']
['children']['billing-step']['children']['payment']
['children']['payments-list']['children']
);
}

// when DisplayBillingOnPaymentPage is used
if (isset($jsLayout['components']['checkout']['children']['steps']
['children']['billing-step']['children']['payment']['children']
['afterMethods']['children']['billing-address-form']['children']
['form-fields']['children']['vat_id'])) {

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

return $jsLayout;
}

/**
* Add tooltip to VAT ID field
*
* @param array &$paymentForms
* @return void
*/
private function addVatTooltipToPaymentForms(array &$paymentForms)
{
foreach ($paymentForms as $key => $values) {
if (strpos($key, '-form') === false) {
continue;
}

if (!isset($paymentForms[$key]['children']['form-fields']['children']['vat_id'])) {
continue;
}

$this->addVatTooltip(
$paymentForms[$key]['children']['form-fields']['children']['vat_id']
);
}
}

/**
* Add tooltip to VAT ID field
*
* @param array &$vatField
* @return void
*/
private function addVatTooltip(array &$vatField)
{
if (version_compare($this->magentoMetadata->getVersion(), '2.3.0', '<')) {
$vatField['config']['tooltip']['description'] =
__('Please do not enter country code. For example, DE123456789 is wrong, while 123456789 is correct.');
}

if ($this->helper->isVatRequired()) {
$vatField['validation']['required-entry'] = true;
}
}
}