diff --git a/app/code/Magento/Checkout/Block/Checkout/LayoutProcessor.php b/app/code/Magento/Checkout/Block/Checkout/LayoutProcessor.php index 557f143352446..00cc06ea0ff47 100644 --- a/app/code/Magento/Checkout/Block/Checkout/LayoutProcessor.php +++ b/app/code/Magento/Checkout/Block/Checkout/LayoutProcessor.php @@ -3,24 +3,30 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Checkout\Block\Checkout; use Magento\Checkout\Helper\Data; -use Magento\Framework\App\ObjectManager; +use Magento\Customer\Model\AttributeMetadataDataProvider; +use Magento\Customer\Model\Options; +use Magento\Eav\Api\Data\AttributeInterface; +use Magento\Shipping\Model\Config; use Magento\Store\Model\StoreManagerInterface; +use Magento\Ui\Component\Form\AttributeMapper; /** - * Class LayoutProcessor + * Checkout Layout Processor */ -class LayoutProcessor implements \Magento\Checkout\Block\Checkout\LayoutProcessorInterface +class LayoutProcessor implements LayoutProcessorInterface { /** - * @var \Magento\Customer\Model\AttributeMetadataDataProvider + * @var AttributeMetadataDataProvider */ private $attributeMetadataDataProvider; /** - * @var \Magento\Ui\Component\Form\AttributeMapper + * @var AttributeMapper */ protected $attributeMapper; @@ -30,7 +36,7 @@ class LayoutProcessor implements \Magento\Checkout\Block\Checkout\LayoutProcesso protected $merger; /** - * @var \Magento\Customer\Model\Options + * @var Options */ private $options; @@ -45,39 +51,35 @@ class LayoutProcessor implements \Magento\Checkout\Block\Checkout\LayoutProcesso private $storeManager; /** - * @var \Magento\Shipping\Model\Config + * @var Config */ private $shippingConfig; /** - * @param \Magento\Customer\Model\AttributeMetadataDataProvider $attributeMetadataDataProvider - * @param \Magento\Ui\Component\Form\AttributeMapper $attributeMapper + * @param AttributeMetadataDataProvider $attributeMetadataDataProvider + * @param AttributeMapper $attributeMapper * @param AttributeMerger $merger - * @param \Magento\Customer\Model\Options|null $options - * @param Data|null $checkoutDataHelper - * @param \Magento\Shipping\Model\Config|null $shippingConfig - * @param StoreManagerInterface|null $storeManager + * @param Options $options + * @param Data $checkoutDataHelper + * @param Config $shippingConfig + * @param StoreManagerInterface $storeManager */ public function __construct( - \Magento\Customer\Model\AttributeMetadataDataProvider $attributeMetadataDataProvider, - \Magento\Ui\Component\Form\AttributeMapper $attributeMapper, + AttributeMetadataDataProvider $attributeMetadataDataProvider, + AttributeMapper $attributeMapper, AttributeMerger $merger, - \Magento\Customer\Model\Options $options = null, - Data $checkoutDataHelper = null, - \Magento\Shipping\Model\Config $shippingConfig = null, - StoreManagerInterface $storeManager = null + Options $options, + Data $checkoutDataHelper, + Config $shippingConfig, + StoreManagerInterface $storeManager ) { $this->attributeMetadataDataProvider = $attributeMetadataDataProvider; $this->attributeMapper = $attributeMapper; $this->merger = $merger; - $this->options = $options ?: \Magento\Framework\App\ObjectManager::getInstance() - ->get(\Magento\Customer\Model\Options::class); - $this->checkoutDataHelper = $checkoutDataHelper ?: \Magento\Framework\App\ObjectManager::getInstance() - ->get(Data::class); - $this->shippingConfig = $shippingConfig ?: \Magento\Framework\App\ObjectManager::getInstance() - ->get(\Magento\Shipping\Model\Config::class); - $this->storeManager = $storeManager ?: \Magento\Framework\App\ObjectManager::getInstance() - ->get(StoreManagerInterface::class); + $this->options = $options; + $this->checkoutDataHelper = $checkoutDataHelper; + $this->shippingConfig = $shippingConfig; + $this->storeManager = $storeManager; } /** @@ -87,7 +89,7 @@ public function __construct( */ private function getAddressAttributes() { - /** @var \Magento\Eav\Api\Data\AttributeInterface[] $attributes */ + /** @var AttributeInterface[] $attributes */ $attributes = $this->attributeMetadataDataProvider->loadAttributesCollection( 'customer_address', 'customer_register_address' @@ -157,8 +159,10 @@ public function process($jsLayout) $elements = $this->getAddressAttributes(); $elements = $this->convertElementsToSelect($elements, $attributesToConvert); // The following code is a workaround for custom address attributes - if (isset($jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children'] - ['payment']['children'])) { + if (isset( + $jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']['payment'] + ['children'] + )) { $jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children'] ['payment']['children'] = $this->processPaymentChildrenComponents( $jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children'] @@ -166,8 +170,11 @@ public function process($jsLayout) $elements ); } - if (isset($jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children'] - ['step-config']['children']['shipping-rates-validation']['children'])) { + + if (isset( + $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children'] + ['step-config']['children']['shipping-rates-validation']['children'] + )) { $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children'] ['step-config']['children']['shipping-rates-validation']['children'] = $this->processShippingChildrenComponents( @@ -176,8 +183,10 @@ public function process($jsLayout) ); } - if (isset($jsLayout['components']['checkout']['children']['steps']['children']['shipping-step'] - ['children']['shippingAddress']['children']['shipping-address-fieldset']['children'])) { + if (isset( + $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children'] + ['shippingAddress']['children']['shipping-address-fieldset']['children'] + )) { $fields = $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step'] ['children']['shippingAddress']['children']['shipping-address-fieldset']['children']; $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step'] @@ -188,6 +197,7 @@ public function process($jsLayout) $fields ); } + return $jsLayout; } @@ -304,9 +314,6 @@ private function getBillingAddressComponent($paymentCode, $elements) 'checkoutProvider', 'billingAddress' . $paymentCode, [ - 'country_id' => [ - 'sortOrder' => 115, - ], 'region' => [ 'visible' => false, ], diff --git a/app/code/Magento/Checkout/Test/Unit/Block/Checkout/LayoutProcessorTest.php b/app/code/Magento/Checkout/Test/Unit/Block/Checkout/LayoutProcessorTest.php index 31ca2a2033012..9fff4b622e596 100644 --- a/app/code/Magento/Checkout/Test/Unit/Block/Checkout/LayoutProcessorTest.php +++ b/app/code/Magento/Checkout/Test/Unit/Block/Checkout/LayoutProcessorTest.php @@ -10,14 +10,16 @@ use Magento\Checkout\Helper\Data; use Magento\Customer\Model\AttributeMetadataDataProvider; use Magento\Customer\Model\Options; - +use Magento\Shipping\Model\Config; +use Magento\Store\Model\StoreManagerInterface; use Magento\Ui\Component\Form\AttributeMapper; -use PHPUnit_Framework_MockObject_MockObject as MockObject; +use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\TestCase; /** * LayoutProcessorTest covers a list of variations for checkout layout processor */ -class LayoutProcessorTest extends \PHPUnit\Framework\TestCase +class LayoutProcessorTest extends TestCase { /** * @var AttributeMetadataDataProvider|MockObject @@ -45,7 +47,7 @@ class LayoutProcessorTest extends \PHPUnit\Framework\TestCase private $layoutProcessor; /** - * @var MockObject + * @var StoreManagerInterface|MockObject */ private $storeManager; @@ -75,11 +77,11 @@ protected function setUp() ->disableOriginalConstructor() ->getMock(); - $shippingConfig = $this->getMockBuilder(\Magento\Shipping\Model\Config::class) + $shippingConfig = $this->getMockBuilder(Config::class) ->disableOriginalConstructor() ->getMock(); - $this->storeManager = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class); + $this->storeManager = $this->createMock(StoreManagerInterface::class); $this->layoutProcessor = new LayoutProcessor( $this->attributeDataProvider, @@ -109,10 +111,12 @@ public function testProcess() $this->attributeMerger->expects(static::exactly(2)) ->method('merge') - ->willReturnMap([ - ['payment1_1' => $this->getBillingComponent('payment1_1')], - ['payment2_1' => $this->getBillingComponent('payment2_1')], - ]); + ->willReturnMap( + [ + ['payment1_1' => $this->getBillingComponent('payment1_1')], + ['payment2_1' => $this->getBillingComponent('payment2_1')], + ] + ); $actual = $this->layoutProcessor->process($jsLayout); @@ -236,9 +240,6 @@ private function getLayoutData() private function getBillingComponent($paymentCode) { return [ - 'country_id' => [ - 'sortOrder' => 115, - ], 'region' => [ 'visible' => false, ], diff --git a/app/code/Magento/Checkout/view/frontend/layout/checkout_index_index.xml b/app/code/Magento/Checkout/view/frontend/layout/checkout_index_index.xml index fed0c951eff9f..c33b784fcd20c 100644 --- a/app/code/Magento/Checkout/view/frontend/layout/checkout_index_index.xml +++ b/app/code/Magento/Checkout/view/frontend/layout/checkout_index_index.xml @@ -222,9 +222,6 @@ 0 - - 115 - diff --git a/app/code/Magento/Customer/Setup/Patch/Data/UpdateCustomerAddressAttributesSortOrder.php b/app/code/Magento/Customer/Setup/Patch/Data/UpdateCustomerAddressAttributesSortOrder.php new file mode 100644 index 0000000000000..b35a21751ebea --- /dev/null +++ b/app/code/Magento/Customer/Setup/Patch/Data/UpdateCustomerAddressAttributesSortOrder.php @@ -0,0 +1,106 @@ +moduleDataSetup = $moduleDataSetup; + $this->customerSetupFactory = $customerSetupFactory; + } + + /** + * @inheritDoc + */ + public function apply() + { + /** @var CustomerSetup $customerSetup */ + $customerSetup = $this->customerSetupFactory->create(['setup' => $this->moduleDataSetup]); + $this->updateCustomerAddressAttributesSortOrder($customerSetup); + + return $this; + } + + /** + * @inheritDoc + */ + public function getAliases() + { + return []; + } + + /** + * @inheritDoc + */ + public static function getDependencies() + { + return [ + DefaultCustomerGroupsAndAttributes::class, + ]; + } + + /** + * Update customer address attributes sort order + * + * @param CustomerSetup $customerSetup + * + * @return void + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + */ + private function updateCustomerAddressAttributesSortOrder($customerSetup) + { + $entityAttributes = [ + 'customer_address' => [ + 'country_id' => [ + 'sort_order' => 80, + 'position' => 80 + ], + 'region' => [ + 'sort_order' => 90, + 'position' => 90 + ], + 'region_id' => [ + 'sort_order' => 90, + 'position' => 90 + ], + 'city' => [ + 'sort_order' => 100, + 'position' => 100 + ], + ], + ]; + + $customerSetup->upgradeAttributes($entityAttributes); + } +} diff --git a/app/code/Magento/Customer/view/adminhtml/ui_component/customer_address_form.xml b/app/code/Magento/Customer/view/adminhtml/ui_component/customer_address_form.xml index 3af0172b3fca8..517d8151b5f10 100644 --- a/app/code/Magento/Customer/view/adminhtml/ui_component/customer_address_form.xml +++ b/app/code/Magento/Customer/view/adminhtml/ui_component/customer_address_form.xml @@ -174,17 +174,7 @@ - - - text - - true - - true - - - - + true @@ -212,6 +202,16 @@ + + + text + + true + + true + + + text diff --git a/app/code/Magento/Customer/view/frontend/templates/address/edit.phtml b/app/code/Magento/Customer/view/frontend/templates/address/edit.phtml index 1d940296f334a..e7519c7c3320b 100644 --- a/app/code/Magento/Customer/view/frontend/templates/address/edit.phtml +++ b/app/code/Magento/Customer/view/frontend/templates/address/edit.phtml @@ -6,6 +6,7 @@ /** @var \Magento\Customer\Block\Address\Edit $block */ /** @var \Magento\Customer\ViewModel\Address $viewModel */ +/** @var \Magento\Framework\Escaper $escaper */ $viewModel = $block->getViewModel(); ?> getLayout()->createBlock(\Magento\Customer\Block\Widget\Company::class) ?> @@ -26,16 +27,16 @@ $viewModel = $block->getViewModel(); addressGetAttributeValidationClass('region'); ?>
+ data-hasrequired="escapeHtmlAttr(__('* Required Fields')) ?>">
- escapeHtml(__('Contact Information')) ?>
+ escapeHtml(__('Contact Information')) ?>
getBlockHtml('formkey') ?> - - + + getNameBlockHtml() ?> isEnabled()): ?> @@ -52,29 +53,29 @@ $viewModel = $block->getViewModel();
- escapeHtml(__('Address')) ?>
+ escapeHtml(__('Address')) ?>
+ class="input-text escapeHtmlAttr($_streetValidationClass) ?>"/>
addressGetStreetLines(); $_i < $_n; $_i++): ?>
+ escapeHtmlAttr($_streetValidationClassNotRequired) ?>">
@@ -90,22 +91,19 @@ $viewModel = $block->getViewModel();
-
- +
+
- + getCountryHtmlSelect() ?>
@@ -117,18 +115,31 @@ $viewModel = $block->getViewModel(); title="" class="validate-select region_id" > - + escapeHtmlAttr($_regionValidationClass) ?>" />
+
+ +
+ +
+
-
- -
- getCountryHtmlSelect() ?> -
-
isDefaultBilling()): ?>
- escapeHtml(__("It's a default billing address.")) ?> + escapeHtml(__("It's a default billing address.")) ?>
canSetAsDefaultBilling()): ?>
@@ -170,13 +175,13 @@ $viewModel = $block->getViewModel(); isDefaultShipping()): ?>
- escapeHtml(__("It's a default shipping address.")) ?> + escapeHtml(__("It's a default shipping address.")) ?>
canSetAsDefaultShipping()): ?>
@@ -188,13 +193,13 @@ $viewModel = $block->getViewModel();
@@ -203,7 +208,7 @@ $viewModel = $block->getViewModel(); { "#form-validate": { "addressValidation": { - "postCodes": getPostCodeConfig()->getSerializedPostCodes(); ?> + "postCodes": getPostCodeConfig()->getSerializedPostCodes() ?> } }, "#country": { 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 da0bb6e4cbc8b..6a267c9996908 100644 --- a/app/code/Magento/Customer/view/frontend/templates/form/register.phtml +++ b/app/code/Magento/Customer/view/frontend/templates/form/register.phtml @@ -3,78 +3,123 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +// phpcs:disable Magento2.Templates.ThisInTemplate.FoundHelper +// phpcs:disable Magento2.Templates.ThisInTemplate.FoundThis + +use Magento\Customer\Helper\Address; /** @var \Magento\Customer\Block\Form\Register $block */ +/** @var \Magento\Framework\Escaper $escaper */ +$formData = $block->getFormData(); ?> +getConfig('general/region/display_all'); ?> getChildHtml('form_fields_before') ?> getChildHtml('customer.form.register.extra') ?> - - getBlockHtml('formkey'); ?> + + getBlockHtml('formkey') ?>
- escapeHtml(__('Personal Information')) ?>
- - - getLayout()->createBlock(\Magento\Customer\Block\Widget\Name::class)->setObject($block->getFormData())->setForceUseCustomerAttributes(true)->toHtml() ?> - isNewsletterEnabled()) : ?> + escapeHtml(__('Personal Information')) ?>
+ + + getLayout() + ->createBlock(\Magento\Customer\Block\Widget\Name::class) + ->setObject($formData) + ->setForceUseCustomerAttributes(true) + ->toHtml() ?> + isNewsletterEnabled()): ?> getChildHtml('customer.form.register.newsletter') ?> getLayout()->createBlock(\Magento\Customer\Block\Widget\Dob::class) ?> - isEnabled()) : ?> - setDate($block->getFormData()->getDob())->toHtml() ?> + isEnabled()): ?> + setDate($formData->getDob())->toHtml() ?> getLayout()->createBlock(\Magento\Customer\Block\Widget\Taxvat::class) ?> - isEnabled()) : ?> - setTaxvat($block->getFormData()->getTaxvat())->toHtml() ?> + isEnabled()): ?> + setTaxvat($formData->getTaxvat())->toHtml() ?> getLayout()->createBlock(\Magento\Customer\Block\Widget\Gender::class) ?> - isEnabled()) : ?> - setGender($block->getFormData()->getGender())->toHtml() ?> + isEnabled()): ?> + setGender($formData->getGender())->toHtml() ?>
- getShowAddressFields()) : ?> + getShowAddressFields()): ?> + helper(Address::class)->getAttributeValidationClass('city'); ?> + helper(Address::class)->getAttributeValidationClass('postcode'); ?> + helper(Address::class)->getAttributeValidationClass('region'); ?>
- escapeHtml(__('Address Information')) ?>
+ escapeHtml(__('Address Information')) ?>
getLayout()->createBlock(\Magento\Customer\Block\Widget\Company::class) ?> - isEnabled()) : ?> - setCompany($block->getFormData()->getCompany())->toHtml() ?> + isEnabled()): ?> + setCompany($formData->getCompany())->toHtml() ?> getLayout()->createBlock(\Magento\Customer\Block\Widget\Telephone::class) ?> - isEnabled()) : ?> - setTelephone($block->getFormData()->getTelephone())->toHtml() ?> + isEnabled()): ?> + setTelephone($formData->getTelephone())->toHtml() ?> getLayout()->createBlock(\Magento\Customer\Block\Widget\Fax::class) ?> - isEnabled()) : ?> - setFax($block->getFormData()->getFax())->toHtml() ?> + isEnabled()): ?> + setFax($formData->getFax())->toHtml() ?> - helper(\Magento\Customer\Helper\Address::class)->getAttributeValidationClass('street'); ?> + helper(Address::class) + ->getAttributeValidationClass('street'); + ?>
- +
- +
- - helper(\Magento\Customer\Helper\Address::class)->getStreetLines(); $_i <= $_n; $_i++) : ?> + helper(Address::class)->getStreetLines(); + ?> +
- +
@@ -82,38 +127,70 @@
-
- +
+
- + getCountryHtmlSelect() ?>
- +
- + - +
-
- +
+
- +
-
- +
+
- getCountryHtmlSelect() ?> +
+ getChildBlock('customer_form_address_user_attributes');?> - + setEntityType('customer_address'); ?> setFieldIdFormat('address:%1$s')->setFieldNameFormat('address[%1$s]');?> restoreSessionData($addressAttributes->getMetadataForm(), 'address');?> @@ -124,29 +201,40 @@
-