From ccdc1d0ed8a6453387d9a7f36f08fc3c62bd4195 Mon Sep 17 00:00:00 2001 From: Ioan Ulecan Date: Mon, 28 Mar 2022 15:02:13 +0300 Subject: [PATCH 1/4] Add missing taxvat field visibility check in customer registration form --- .../Customer/view/frontend/templates/form/register.phtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Customer/view/frontend/templates/form/register.phtml b/app/code/Magento/Customer/view/frontend/templates/form/register.phtml index e1343e9abcca9..58899d5182a55 100644 --- a/app/code/Magento/Customer/view/frontend/templates/form/register.phtml +++ b/app/code/Magento/Customer/view/frontend/templates/form/register.phtml @@ -63,7 +63,7 @@ $createAccountButtonViewModel = $block->getData('create_account_button_view_mode getLayout()->createBlock(\Magento\Customer\Block\Widget\Taxvat::class) ?> - isEnabled()): ?> + isEnabled() && $addressHelper->isVatAttributeVisible()): ?> setTaxvat($formData->getTaxvat())->toHtml() ?> From 0eb1e74490aee4c25174b8feecdc58a23ac68f9e Mon Sep 17 00:00:00 2001 From: Ioan Ulecan Date: Fri, 1 Apr 2022 10:05:15 +0300 Subject: [PATCH 2/4] add taxvat verification in customer createPost extractAddress --- app/code/Magento/Customer/Controller/Account/CreatePost.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/code/Magento/Customer/Controller/Account/CreatePost.php b/app/code/Magento/Customer/Controller/Account/CreatePost.php index 9171511f5ba2e..85dff5fa5b3e5 100644 --- a/app/code/Magento/Customer/Controller/Account/CreatePost.php +++ b/app/code/Magento/Customer/Controller/Account/CreatePost.php @@ -290,6 +290,11 @@ protected function extractAddress() case 'region': $regionDataObject->setRegion($value); break; + case 'taxvat': + if ($this->addressHelper->isVatAttributeVisible()) { + $addressData[$attributeCode] = $value; + } + break; default: $addressData[$attributeCode] = $value; } From 1ce8888afb76d90827a3412524c7f71d75ad491d Mon Sep 17 00:00:00 2001 From: Ioan Ulecan Date: Fri, 1 Apr 2022 14:01:59 +0300 Subject: [PATCH 3/4] make address vat_id dependant of address options configuration --- .../Magento/Customer/Block/Widget/Taxvat.php | 10 ++++++ .../Controller/Account/CreatePost.php | 5 --- app/code/Magento/Customer/Helper/Address.php | 34 +++++++++++++++++-- .../frontend/templates/form/register.phtml | 2 +- .../frontend/templates/widget/taxvat.phtml | 4 +++ 5 files changed, 46 insertions(+), 9 deletions(-) diff --git a/app/code/Magento/Customer/Block/Widget/Taxvat.php b/app/code/Magento/Customer/Block/Widget/Taxvat.php index e35f04f592a43..d117ee7e1b6dd 100644 --- a/app/code/Magento/Customer/Block/Widget/Taxvat.php +++ b/app/code/Magento/Customer/Block/Widget/Taxvat.php @@ -76,4 +76,14 @@ public function getStoreLabel($attributeCode) $attribute = $this->_getAttribute($attributeCode); return $attribute ? __($attribute->getStoreLabel()) : ''; } + + /** + * Get is taxvat visible in register form + * + * @retrun bool + */ + public function isVatVisible(): bool + { + return $this->_addressHelper->isVatAttributeVisible(true); + } } diff --git a/app/code/Magento/Customer/Controller/Account/CreatePost.php b/app/code/Magento/Customer/Controller/Account/CreatePost.php index 85dff5fa5b3e5..9171511f5ba2e 100644 --- a/app/code/Magento/Customer/Controller/Account/CreatePost.php +++ b/app/code/Magento/Customer/Controller/Account/CreatePost.php @@ -290,11 +290,6 @@ protected function extractAddress() case 'region': $regionDataObject->setRegion($value); break; - case 'taxvat': - if ($this->addressHelper->isVatAttributeVisible()) { - $addressData[$attributeCode] = $value; - } - break; default: $addressData[$attributeCode] = $value; } diff --git a/app/code/Magento/Customer/Helper/Address.php b/app/code/Magento/Customer/Helper/Address.php index 74eee759b4abd..93f4290c6a198 100644 --- a/app/code/Magento/Customer/Helper/Address.php +++ b/app/code/Magento/Customer/Helper/Address.php @@ -33,7 +33,9 @@ class Address extends \Magento\Framework\App\Helper\AbstractHelper const XML_PATH_VIV_TAX_CALCULATION_ADDRESS_TYPE = 'customer/create_account/tax_calculation_address_type'; - const XML_PATH_VAT_FRONTEND_VISIBILITY = 'customer/create_account/vat_frontend_visibility'; + const XML_PATH_VAT_FRONTEND_VISIBILITY = 'customer/address/taxvat_show'; + + const XML_PATH_VAT_REGISTER_FORM_VISIBILITY = 'customer/create_account/vat_frontend_visibility'; /** * Possible customer address types @@ -387,12 +389,20 @@ public function getTaxCalculationAddressType($store = null) } /** - * Check if VAT ID address attribute has to be shown on frontend (on Customer Address management forms) + * Check if VAT ID address attribute has to be shown on frontend + * (on Customer Address management forms or Customer register form) * + * @param bool $registerFom * @return boolean */ - public function isVatAttributeVisible() + public function isVatAttributeVisible(bool $registerFom = false): bool { + if ($registerFom) { + return $this->scopeConfig->isSetFlag( + self::XML_PATH_VAT_REGISTER_FORM_VISIBILITY, + ScopeInterface::SCOPE_STORE + ); + } return $this->scopeConfig->isSetFlag( self::XML_PATH_VAT_FRONTEND_VISIBILITY, ScopeInterface::SCOPE_STORE @@ -417,4 +427,22 @@ public function isAttributeVisible($code) } return false; } + + /** + * Check if attribute is required + * + * @param string $code + * + * @return bool + * @throws NoSuchEntityException + * @throws \Magento\Framework\Exception\LocalizedException + */ + public function isAttributeRequired($code): bool + { + $attributeMetadata = $this->_addressMetadataService->getAttributeMetadata($code); + if ($attributeMetadata) { + return $attributeMetadata->isRequired(); + } + return false; + } } diff --git a/app/code/Magento/Customer/view/frontend/templates/form/register.phtml b/app/code/Magento/Customer/view/frontend/templates/form/register.phtml index 58899d5182a55..e1343e9abcca9 100644 --- a/app/code/Magento/Customer/view/frontend/templates/form/register.phtml +++ b/app/code/Magento/Customer/view/frontend/templates/form/register.phtml @@ -63,7 +63,7 @@ $createAccountButtonViewModel = $block->getData('create_account_button_view_mode getLayout()->createBlock(\Magento\Customer\Block\Widget\Taxvat::class) ?> - isEnabled() && $addressHelper->isVatAttributeVisible()): ?> + isEnabled()): ?> setTaxvat($formData->getTaxvat())->toHtml() ?> diff --git a/app/code/Magento/Customer/view/frontend/templates/widget/taxvat.phtml b/app/code/Magento/Customer/view/frontend/templates/widget/taxvat.phtml index 1551ea9609449..61c288cfba608 100644 --- a/app/code/Magento/Customer/view/frontend/templates/widget/taxvat.phtml +++ b/app/code/Magento/Customer/view/frontend/templates/widget/taxvat.phtml @@ -6,9 +6,13 @@ /** @var \Magento\Customer\Block\Widget\Taxvat $block */ ?> +isVatVisible()): ?>
isRequired() ? ' data-validate="{required:true}"' : '' ?>>
+ + + From cba6e0068e0efbcd565a5bc3d2152111f24c9d34 Mon Sep 17 00:00:00 2001 From: Ioan Ulecan Date: Fri, 1 Apr 2022 14:13:47 +0300 Subject: [PATCH 4/4] helper cleanup --- app/code/Magento/Customer/Helper/Address.php | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/app/code/Magento/Customer/Helper/Address.php b/app/code/Magento/Customer/Helper/Address.php index 93f4290c6a198..74167a8c0eabb 100644 --- a/app/code/Magento/Customer/Helper/Address.php +++ b/app/code/Magento/Customer/Helper/Address.php @@ -427,22 +427,4 @@ public function isAttributeVisible($code) } return false; } - - /** - * Check if attribute is required - * - * @param string $code - * - * @return bool - * @throws NoSuchEntityException - * @throws \Magento\Framework\Exception\LocalizedException - */ - public function isAttributeRequired($code): bool - { - $attributeMetadata = $this->_addressMetadataService->getAttributeMetadata($code); - if ($attributeMetadata) { - return $attributeMetadata->isRequired(); - } - return false; - } }