Skip to content

Add missing taxvat field visibility check in customer registration form #35240

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: 2.4-develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions app/code/Magento/Customer/Block/Widget/Taxvat.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
16 changes: 13 additions & 3 deletions app/code/Magento/Customer/Helper/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@

/** @var \Magento\Customer\Block\Widget\Taxvat $block */
?>
<?php if($block->isVatVisible()): ?>
<div class="field taxvat<?= $block->isRequired() ? ' required' : ''; ?>">
<label class="label" for="<?= $block->escapeHtmlAttr($block->getFieldId('taxvat')) ?>"><span><?= $block->escapeHtml($block->getStoreLabel('taxvat')) ?></span></label>
<div class="control">
<input type="text" id="<?= $block->escapeHtmlAttr($block->getFieldId('taxvat')) ?>" name="<?= $block->escapeHtmlAttr($block->getFieldName('taxvat')) ?>" value="<?= $block->escapeHtmlAttr($block->getTaxvat()) ?>" title="<?= $block->escapeHtmlAttr($block->getStoreLabel('taxvat')) ?>" class="input-text <?= $block->escapeHtmlAttr($this->helper(\Magento\Customer\Helper\Address::class)->getAttributeValidationClass('taxvat')) ?>" <?= $block->isRequired() ? ' data-validate="{required:true}"' : '' ?>>
</div>
</div>
<?php else: ?>
<input type="hidden" id="<?= $block->escapeHtmlAttr($block->getFieldId('taxvat')) ?>" name="<?= $block->escapeHtmlAttr($block->getFieldName('taxvat')) ?>" value="0" />
<?php endif; ?>