Skip to content

Fixed issue #22841 Telephone, Company & Fax fields does not display on Customer Registration Page #27608

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 29 commits into
base: 2.4-develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
2197d00
Added configuration for showing address fields
gaurav-473 Apr 5, 2020
34d04a2
Update register.phtml
gaurav-473 Apr 5, 2020
2a76acd
Update config.xml
gaurav-473 Apr 5, 2020
f963bc7
fixed static test
gaurav-473 Apr 5, 2020
50388ce
Merge branch '2.4-develop' into 2.4-develop-22841
engcom-Kilo Jun 18, 2020
5c358b2
MFTF test
engcom-Kilo Jun 19, 2020
76a3463
Merge branch '2.4-develop' into 2.4-develop-22841
engcom-Kilo Jun 19, 2020
4eb5022
Merge branch '2.4-develop' into 2.4-develop-22841
engcom-Kilo Jul 10, 2020
aed35f9
Fix static test
engcom-Kilo Jul 10, 2020
9b0ae83
Correction MFTF test.
engcom-Kilo Jul 13, 2020
64bb6ea
Correct typo.
engcom-Kilo Jul 13, 2020
995e62b
Updated i18n.
engcom-Kilo Jul 15, 2020
cb4390c
Merge branch '2.4-develop' into 2.4-develop-22841
engcom-Kilo Jul 16, 2020
853df84
Added testCaseId fot MFTF test.
engcom-Kilo Jul 22, 2020
0f5a1c2
Merge branch '2.4-develop' into 2.4-develop-22841
engcom-Kilo Jul 22, 2020
0caa710
Merge branch '2.4-develop' into 2.4-develop-22841
engcom-Charlie Sep 2, 2020
89df850
improve
engcom-Charlie Sep 2, 2020
7cf1e50
Merge branch '2.4-develop' into 2.4-develop-22841
engcom-Charlie Sep 2, 2020
a82390f
Merge branch '2.4-develop' into 2.4-develop-22841
engcom-Charlie Sep 7, 2020
40187f5
Merge branch '2.4-develop' into 2.4-develop-22841
Sep 8, 2020
4a2516e
Merge branch '2.4-develop' into 2.4-develop-22841
engcom-Charlie Sep 14, 2020
98488fa
Merge branch '2.4-develop' into 2.4-develop-22841
engcom-Charlie Sep 18, 2020
083cb2e
fix broken region selector
engcom-Charlie Sep 18, 2020
a02fca3
Merge branch '2.4-develop' into 2.4-develop-22841
engcom-Charlie Sep 18, 2020
78c9c43
fix mftf
engcom-Charlie Sep 21, 2020
be93ce9
Merge branch '2.4-develop' into 2.4-develop-22841
engcom-Charlie Sep 21, 2020
78a7b57
Merge branch '2.4-develop' into 2.4-develop-22841
engcom-Charlie Oct 6, 2020
8072400
Merge branch '2.4-develop' into 2.4-develop-22841
engcom-Charlie Oct 15, 2020
c78bfb6
Merge branch '2.4-develop' into 2.4-develop-22841
Nov 16, 2020
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
20 changes: 19 additions & 1 deletion app/code/Magento/Customer/Block/Form/Register.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
*/
Expand Down Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you move this method to the separate viewmodel class? It will prevent SVC failures.

More info there https://devdocs.magento.com/guides/v2.4/extension-dev-guide/view-models.html

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. No, it won't help to resolve SVC failure as it also added a new configuration field.

{
$result = false;
if ($this->getShowAddressFields() || $this->getConfig(self::XML_PATH_SHOW_ADDRESS_FIELDS)) {
$result = true;
}

return $result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<actionGroup name="StorefrontCustomerCreateAccountWithAdditionalInformationActionGroup" extends="SignUpNewUserFromStorefrontActionGroup">
<annotations>
<description>EXTENDS: SignUpNewUserFromStorefrontActionGroup. Fills prefix, suffix, DOB, VAT number, gender, company, telephone, fax, address fields.</description>
</annotations>
<arguments>
<argument name="dob" defaultValue="{{EN_US_DATE.short4DigitYear}}" type="string"/>
<argument name="address" type="entity"/>
<argument name="customerGender" defaultValue="{{Gender.male}}" type="string"/>
</arguments>
<fillField selector="{{StorefrontCustomerCreateFormSection.prefixField}}" userInput="{{Customer.prefix}}" after="fillLastName" stepKey="fillPrefixName"/>
<fillField selector="{{StorefrontCustomerCreateFormSection.suffixField}}" userInput="{{Customer.suffix}}" after="fillPrefixName" stepKey="fillSuffixName"/>
<fillField selector="{{StorefrontCustomerCreateFormSection.dobField}}" userInput="{{dob}}" after="fillSuffixName" stepKey="fillDob"/>
<fillField selector="{{StorefrontCustomerCreateFormSection.taxvatField}}" userInput="{{Customer.taxvat}}" after="fillDob" stepKey="fillTaxvat"/>
<selectOption selector="{{StorefrontCustomerCreateFormSection.genderField}}" userInput="{{customerGender}}" after="fillTaxvat" stepKey="fillGender"/>
<fillField selector="{{StorefrontCustomerCreateFormSection.companyField}}" userInput="{{address.company}}" after="fillGender" stepKey="fillCompany"/>
<fillField selector="{{StorefrontCustomerCreateFormSection.telephoneField}}" userInput="{{address.telephone}}" after="fillCompany" stepKey="fillPhoneNumber"/>
<fillField selector="{{StorefrontCustomerCreateFormSection.streetField}}" userInput="{{address.street[0]}}" after="fillPhoneNumber" stepKey="fillStreetAddress"/>
<selectOption selector="{{StorefrontCustomerCreateFormSection.countryField}}" userInput="{{address.country_id}}" after="fillStreetAddress" stepKey="selectCounty"/>
<selectOption selector="{{StorefrontCustomerCreateFormSection.regionField}}" userInput="{{address.state}}" after="selectCounty" stepKey="selectRegion" />
<fillField selector="{{StorefrontCustomerCreateFormSection.cityField}}" userInput="{{address.city}}" after="selectRegion" stepKey="fillCityName"/>
<fillField selector="{{StorefrontCustomerCreateFormSection.postcodeField}}" userInput="{{address.postcode}}" after="fillCityName" stepKey="fillZip"/>
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
<element name="shareCustomerAccount" type="select" selector="#customer_account_share_scope"/>
<element name="showDateOfBirth" type="select" selector="#customer_address_dob_show"/>
<element name="showDateOfBirthInherit" type="select" selector="#customer_address_dob_show_inherit"/>
<element name="showAddressInformationInherit" type="select" selector="#customer_address_show_address_fields_inherit"/>
</section>
</sections>
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,22 @@
<sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd">
<section name="StorefrontCustomerCreateFormSection">
<element name="prefixField" type="input" selector="#prefix"/>
<element name="suffixField" type="input" selector="#suffix"/>
<element name="firstnameField" type="input" selector="#firstname"/>
<element name="lastnameField" type="input" selector="#lastname"/>
<element name="lastnameLabel" type="text" selector="//label[@for='lastname']"/>
<element name="dobField" type="input" selector="#dob"/>
<element name="taxvatField" type="input" selector="#taxvat"/>
<element name="genderField" type="select" selector="#gender"/>
<element name="telephoneField" type="input" selector="#telephone"/>
<element name="faxField" type="input" selector="#fax"/>
<element name="companyField" type="input" selector="#company"/>
<element name="streetField" type="input" selector="#street_1"/>
<element name="cityField" type="input" selector="#city"/>
<element name="regionField" type="select" selector="#region_id"/>
<element name="countryField" type="select" selector="#country"/>
<element name="postcodeField" type="input" selector="#zip"/>
<element name="signUpForNewsletter" type="checkbox" selector="//div/input[@name='is_subscribed']"/>
<element name="emailField" type="input" selector="#email_address"/>
<element name="passwordField" type="input" selector="#password"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
<test name="StorefrontCreateCustomerWithAdditionalInformationTest">
<annotations>
<features value="Customer"/>
<stories value="Create a Customer via the Storefront with Additional Information"/>
<title value="Customer should be able to create an account with additional information via the storefront"/>
<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>
7 changes: 7 additions & 0 deletions app/code/Magento/Customer/etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/Customer/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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/>
Expand Down
2 changes: 2 additions & 0 deletions app/code/Magento/Customer/i18n/en_US.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Original file line number Diff line number Diff line change
Expand Up @@ -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'); ?>
Expand Down Expand Up @@ -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">
{
Expand All @@ -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 ?>
}
}
}
Expand Down