diff --git a/app/code/Magento/Customer/Block/Form/Register.php b/app/code/Magento/Customer/Block/Form/Register.php index d6d0d9c494c11..1a8efa9a872ae 100644 --- a/app/code/Magento/Customer/Block/Form/Register.php +++ b/app/code/Magento/Customer/Block/Form/Register.php @@ -7,6 +7,7 @@ use Magento\Customer\Helper\Address; use Magento\Customer\Model\AccountManagement; +use Magento\Directory\Block\Data; use Magento\Framework\App\ObjectManager; use Magento\Newsletter\Model\Config; @@ -17,8 +18,10 @@ * @SuppressWarnings(PHPMD.CouplingBetweenObjects) * @since 100.0.2 */ -class Register extends \Magento\Directory\Block\Data +class Register extends Data { + private const XML_PATH_SHOW_ADDRESS_FIELDS = 'customer/address/show_address_fields'; + /** * @var \Magento\Customer\Model\Session */ @@ -228,4 +231,19 @@ public function getRequiredCharacterClassesNumber() { return $this->_scopeConfig->getValue(AccountManagement::XML_PATH_REQUIRED_CHARACTER_CLASSES_NUMBER); } + + /** + * Returns whether to show address fields or not + * + * @return bool + */ + public function isShowAddressFields(): bool + { + $result = false; + if ($this->getShowAddressFields() || $this->getConfig(self::XML_PATH_SHOW_ADDRESS_FIELDS)) { + $result = true; + } + + return $result; + } } diff --git a/app/code/Magento/Customer/Test/Mftf/ActionGroup/StorefrontCustomerCreateAccountWithAdditionalInformationActionGroup.xml b/app/code/Magento/Customer/Test/Mftf/ActionGroup/StorefrontCustomerCreateAccountWithAdditionalInformationActionGroup.xml new file mode 100644 index 0000000000000..048174b951465 --- /dev/null +++ b/app/code/Magento/Customer/Test/Mftf/ActionGroup/StorefrontCustomerCreateAccountWithAdditionalInformationActionGroup.xml @@ -0,0 +1,32 @@ + + + + + + + EXTENDS: SignUpNewUserFromStorefrontActionGroup. Fills prefix, suffix, DOB, VAT number, gender, company, telephone, fax, address fields. + + + + + + + + + + + + + + + + + + + + diff --git a/app/code/Magento/Customer/Test/Mftf/Section/AdminCustomerConfigSection.xml b/app/code/Magento/Customer/Test/Mftf/Section/AdminCustomerConfigSection.xml index f8a441e40a792..d9ea04c9f702b 100644 --- a/app/code/Magento/Customer/Test/Mftf/Section/AdminCustomerConfigSection.xml +++ b/app/code/Magento/Customer/Test/Mftf/Section/AdminCustomerConfigSection.xml @@ -13,5 +13,6 @@ + diff --git a/app/code/Magento/Customer/Test/Mftf/Section/StorefrontCustomerCreateFormSection/StorefrontCustomerCreateFormSection.xml b/app/code/Magento/Customer/Test/Mftf/Section/StorefrontCustomerCreateFormSection/StorefrontCustomerCreateFormSection.xml index 6b65ef861472c..c063177438870 100644 --- a/app/code/Magento/Customer/Test/Mftf/Section/StorefrontCustomerCreateFormSection/StorefrontCustomerCreateFormSection.xml +++ b/app/code/Magento/Customer/Test/Mftf/Section/StorefrontCustomerCreateFormSection/StorefrontCustomerCreateFormSection.xml @@ -8,10 +8,22 @@
+ + + + + + + + + + + + diff --git a/app/code/Magento/Customer/Test/Mftf/Test/StorefrontCreateCustomerWithAdditionalInformationTest.xml b/app/code/Magento/Customer/Test/Mftf/Test/StorefrontCreateCustomerWithAdditionalInformationTest.xml new file mode 100644 index 0000000000000..6b8f936448be0 --- /dev/null +++ b/app/code/Magento/Customer/Test/Mftf/Test/StorefrontCreateCustomerWithAdditionalInformationTest.xml @@ -0,0 +1,56 @@ + + + + + + + + + + <description value="Customer should be able to create an account with additional information such like Company, VAT number, Phone via the storefront"/> + <severity value="MAJOR"/> + <testCaseId value="MC-36076"/> + <group value="customer"/> + <group value="create"/> + </annotations> + <before> + <magentoCLI command="config:set customer/address/show_address_fields 1" stepKey="setShowAddressInformation"/> + <magentoCLI command="config:set customer/address/prefix_show opt" stepKey="setShowPrefix"/> + <magentoCLI command="config:set customer/address/middlename_show opt" stepKey="setShowMiddleName"/> + <magentoCLI command="config:set customer/address/suffix_show opt" stepKey="setShowSuffix"/> + <magentoCLI command="config:set customer/address/dob_show opt" stepKey="setShowDOB"/> + <magentoCLI command="config:set customer/address/taxvat_show opt" stepKey="setShowTaxNumber"/> + <magentoCLI command="config:set customer/address/gender_show opt" stepKey="setShowGender"/> + <magentoCLI command="config:set customer/address/telephone_show opt" stepKey="setShowTelephone"/> + </before> + <after> + <magentoCLI command="config:set customer/address/show_address_fields 0" stepKey="setShowAddressInformation"/> + <magentoCLI command="config:set customer/address/prefix_show ''" stepKey="setShowPrefix"/> + <magentoCLI command="config:set customer/address/middlename_show ''" stepKey="setShowMiddleName"/> + <magentoCLI command="config:set customer/address/suffix_show ''" stepKey="setShowSuffix"/> + <magentoCLI command="config:set customer/address/dob_show ''" stepKey="setShowDOB"/> + <magentoCLI command="config:set customer/address/taxvat_show ''" stepKey="setShowTaxNumber"/> + <magentoCLI command="config:set customer/address/gender_show ''" stepKey="setShowGender"/> + <magentoCLI command="config:set customer/address/telephone_show req" stepKey="setShowTelephone"/> + <magentoCLI command="indexer:reindex" stepKey="reindex"/> + + <actionGroup ref="AdminLoginActionGroup" stepKey="login"/> + <actionGroup ref="DeleteCustomerByEmailActionGroup" stepKey="deleteNewUser"> + <argument name="email" value="{{CustomerEntityOne.email}}"/> + </actionGroup> + <actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/> + </after> + + <actionGroup ref="StorefrontCustomerCreateAccountWithAdditionalInformationActionGroup" stepKey="SignUpNewUser"> + <argument name="Customer" value="CustomerEntityOne"/> + <argument name="dob" value="{{EN_US_DATE.short4DigitYear}}"/> + <argument name="address" value="CustomerAddressSimple"/> + </actionGroup> + </test> +</tests> diff --git a/app/code/Magento/Customer/etc/adminhtml/system.xml b/app/code/Magento/Customer/etc/adminhtml/system.xml index 569f9d09c2087..c06a55a61ad37 100644 --- a/app/code/Magento/Customer/etc/adminhtml/system.xml +++ b/app/code/Magento/Customer/etc/adminhtml/system.xml @@ -247,6 +247,13 @@ <source_model>Magento\Config\Model\Config\Source\Nooptreq</source_model> <backend_model>Magento\Customer\Model\Config\Backend\Show\Customer</backend_model> </field> + <field id="show_address_fields" translate="label comment" type="select" sortOrder="95" showInDefault="1" showInWebsite="1" showInStore="0"> + <label>Show Address Information</label> + <source_model>Magento\Config\Model\Config\Source\Yesno</source_model> + <comment> + Enables address information fields on the registration form. + </comment> + </field> <field id="telephone_show" translate="label" type="select" sortOrder="100" showInDefault="1" showInWebsite="1" canRestore="1"> <label>Show Telephone</label> <source_model>Magento\Config\Model\Config\Source\Nooptreq</source_model> diff --git a/app/code/Magento/Customer/etc/config.xml b/app/code/Magento/Customer/etc/config.xml index ab2020580a2eb..34e04a883e86c 100644 --- a/app/code/Magento/Customer/etc/config.xml +++ b/app/code/Magento/Customer/etc/config.xml @@ -55,6 +55,7 @@ <dob_show /> <taxvat_show /> <gender_show /> + <show_address_fields>0</show_address_fields> <telephone_show>req</telephone_show> <company_show>opt</company_show> <fax_show/> diff --git a/app/code/Magento/Customer/i18n/en_US.csv b/app/code/Magento/Customer/i18n/en_US.csv index 0a81e70964b4c..8450c61dca931 100644 --- a/app/code/Magento/Customer/i18n/en_US.csv +++ b/app/code/Magento/Customer/i18n/en_US.csv @@ -543,3 +543,5 @@ Addresses,Addresses "The Store View selected for sending Welcome email from is not related to the customer's associated website.","The Store View selected for sending Welcome email from is not related to the customer's associated website." "Add/Update Address","Add/Update Address" "The specified customer group id does not exist.","The specified customer group id does not exist." +"Show Address Information","Show Address Information" +"Enables address information fields on the registration form.","Enables address information fields on the registration form." 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 5e58f94683ec1..c354591dab1e2 100644 --- a/app/code/Magento/Customer/view/frontend/templates/form/register.phtml +++ b/app/code/Magento/Customer/view/frontend/templates/form/register.phtml @@ -69,7 +69,7 @@ $formData = $block->getFormData(); <?php endif ?> <?= $block->getChildHtml('fieldset_create_info_additional') ?> </fieldset> - <?php if ($block->getShowAddressFields()): ?> + <?php if ($block->isShowAddressFields()): ?> <?php $cityValidationClass = $addressHelper->getAttributeValidationClass('city'); ?> <?php $postcodeValidationClass = $addressHelper->getAttributeValidationClass('postcode'); ?> <?php $regionValidationClass = $addressHelper->getAttributeValidationClass('region'); ?> @@ -320,11 +320,11 @@ $scriptString .= <<<script script; ?> <?= /* @noEscape */ $secureRenderer->renderTag('script', [], $scriptString, false) ?> -<?php if ($block->getShowAddressFields()): ?> +<?php if ($block->isShowAddressFields()): ?> <?php - $regionJson = /* @noEscape */ $directoryHelper->getRegionJson(); - $regionId = (int) $formData->getRegionId(); - $countriesWithOptionalZip = /* @noEscape */ $directoryHelper->getCountriesWithOptionalZip(true); + $regionJson = $directoryHelper->getRegionJson(); + $regionId = (int) $formData->getRegionId(); + $countriesWithOptionalZip = $directoryHelper->getCountriesWithOptionalZip(true); ?> <script type="text/x-magento-init"> { @@ -335,9 +335,9 @@ script; "regionInputId": "#region", "postcodeId": "#zip", "form": "#form-validate", - "regionJson": {$regionJson}, - "defaultRegion": "{$regionId}", - "countriesWithOptionalZip": {$countriesWithOptionalZip} + "regionJson": <?= /* @noEscape */ $regionJson ?>, + "defaultRegion": "<?= /* @noEscape */ $regionId ?>", + "countriesWithOptionalZip": <?= /* @noEscape */ $countriesWithOptionalZip ?> } } }