Skip to content

Commit cd80024

Browse files
committed
Merge remote-tracking branch 'l3/ACP2E-675' into PR_L3_05_04_2022
2 parents b9c57c8 + a4ebe74 commit cd80024

14 files changed

+371
-18
lines changed

app/code/Magento/Customer/Controller/Adminhtml/Address/Save.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@
77
namespace Magento\Customer\Controller\Adminhtml\Address;
88

99
use Magento\Backend\App\Action;
10+
use Magento\Customer\Model\CustomerRegistry;
1011
use Magento\Framework\App\Action\HttpPostActionInterface;
12+
use Magento\Framework\App\ObjectManager;
1113
use Magento\Framework\Controller\Result\Json;
1214
use Magento\Framework\Controller\Result\JsonFactory;
1315
use Magento\Framework\Exception\LocalizedException;
1416
use Magento\Framework\Exception\NoSuchEntityException;
17+
use Magento\Store\Model\StoreManagerInterface;
1518
use Psr\Log\LoggerInterface;
1619

1720
/**
@@ -62,6 +65,16 @@ class Save extends Action implements HttpPostActionInterface
6265
*/
6366
private $resultJsonFactory;
6467

68+
/**
69+
* @var StoreManagerInterface
70+
*/
71+
private $storeManager;
72+
73+
/**
74+
* @var CustomerRegistry
75+
*/
76+
private $customerRegistry;
77+
6578
/**
6679
* @param Action\Context $context
6780
* @param \Magento\Customer\Api\AddressRepositoryInterface $addressRepository
@@ -71,6 +84,9 @@ class Save extends Action implements HttpPostActionInterface
7184
* @param \Magento\Customer\Api\Data\AddressInterfaceFactory $addressDataFactory
7285
* @param LoggerInterface $logger
7386
* @param JsonFactory $resultJsonFactory
87+
* @param StoreManagerInterface|null $storeManager
88+
* @param CustomerRegistry|null $customerRegistry
89+
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
7490
*/
7591
public function __construct(
7692
Action\Context $context,
@@ -80,7 +96,9 @@ public function __construct(
8096
\Magento\Framework\Api\DataObjectHelper $dataObjectHelper,
8197
\Magento\Customer\Api\Data\AddressInterfaceFactory $addressDataFactory,
8298
LoggerInterface $logger,
83-
JsonFactory $resultJsonFactory
99+
JsonFactory $resultJsonFactory,
100+
?StoreManagerInterface $storeManager = null,
101+
?CustomerRegistry $customerRegistry = null
84102
) {
85103
parent::__construct($context);
86104
$this->addressRepository = $addressRepository;
@@ -90,6 +108,10 @@ public function __construct(
90108
$this->addressDataFactory = $addressDataFactory;
91109
$this->logger = $logger;
92110
$this->resultJsonFactory = $resultJsonFactory;
111+
$this->storeManager = $storeManager
112+
?? ObjectManager::getInstance()->get(StoreManagerInterface::class);
113+
$this->customerRegistry = $customerRegistry
114+
?? ObjectManager::getInstance()->get(CustomerRegistry::class);
93115
}
94116

95117
/**
@@ -104,6 +126,10 @@ public function execute(): Json
104126

105127
$error = false;
106128
try {
129+
$customerModel = $this->customerRegistry->retrieve($customerId);
130+
if ($customerModel->getStoreId()) {
131+
$this->storeManager->setCurrentStore($customerModel->getStoreId());
132+
}
107133
/** @var \Magento\Customer\Api\Data\CustomerInterface $customer */
108134
$customer = $this->customerRepository->getById($customerId);
109135

app/code/Magento/Customer/Controller/Adminhtml/Address/Validate.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@
77
namespace Magento\Customer\Controller\Adminhtml\Address;
88

99
use Magento\Backend\App\Action;
10+
use Magento\Customer\Model\CustomerRegistry;
1011
use Magento\Framework\App\Action\HttpGetActionInterface;
1112
use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
13+
use Magento\Framework\App\ObjectManager;
1214
use Magento\Framework\Controller\Result\Json;
1315
use Magento\Framework\DataObject;
16+
use Magento\Store\Model\StoreManagerInterface;
1417

1518
/**
1619
* Class for validation of customer address form on admin.
@@ -34,19 +37,37 @@ class Validate extends Action implements HttpPostActionInterface, HttpGetActionI
3437
*/
3538
private $formFactory;
3639

40+
/**
41+
* @var StoreManagerInterface
42+
*/
43+
private $storeManager;
44+
45+
/**
46+
* @var CustomerRegistry
47+
*/
48+
private $customerRegistry;
49+
3750
/**
3851
* @param Action\Context $context
3952
* @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
4053
* @param \Magento\Customer\Model\Metadata\FormFactory $formFactory
54+
* @param StoreManagerInterface|null $storeManager
55+
* @param CustomerRegistry|null $customerRegistry
4156
*/
4257
public function __construct(
4358
Action\Context $context,
4459
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory,
45-
\Magento\Customer\Model\Metadata\FormFactory $formFactory
60+
\Magento\Customer\Model\Metadata\FormFactory $formFactory,
61+
?StoreManagerInterface $storeManager = null,
62+
?CustomerRegistry $customerRegistry = null
4663
) {
4764
parent::__construct($context);
4865
$this->resultJsonFactory = $resultJsonFactory;
4966
$this->formFactory = $formFactory;
67+
$this->storeManager = $storeManager
68+
?? ObjectManager::getInstance()->get(StoreManagerInterface::class);
69+
$this->customerRegistry = $customerRegistry
70+
?? ObjectManager::getInstance()->get(CustomerRegistry::class);
5071
}
5172

5273
/**
@@ -56,6 +77,13 @@ public function __construct(
5677
*/
5778
public function execute(): Json
5879
{
80+
$customerId = $this->getRequest()->getParam('parent_id');
81+
if ($customerId) {
82+
$customerModel = $this->customerRegistry->retrieve($customerId);
83+
if ($customerModel->getStoreId()) {
84+
$this->storeManager->setCurrentStore($customerModel->getStoreId());
85+
}
86+
}
5987
/** @var \Magento\Framework\DataObject $response */
6088
$response = new \Magento\Framework\DataObject();
6189
$response->setError(false);

app/code/Magento/Customer/Model/Address/DataProvider.php

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@
77
namespace Magento\Customer\Model\Address;
88

99
use Magento\Customer\Api\CustomerRepositoryInterface;
10+
use Magento\Customer\Model\AddressRegistry;
11+
use Magento\Customer\Model\ResourceModel\Address\Attribute\Collection as AddressAttributeCollection;
1012
use Magento\Customer\Model\ResourceModel\Address\CollectionFactory;
1113
use Magento\Eav\Model\Config;
1214
use Magento\Eav\Model\Entity\Type;
1315
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
16+
use Magento\Framework\App\ObjectManager;
1417
use Magento\Framework\View\Element\UiComponent\ContextInterface;
1518
use Magento\Customer\Model\Address;
1619
use Magento\Customer\Model\FileUploaderDataResolver;
@@ -21,6 +24,7 @@
2124
* Dataprovider of customer addresses for customer address grid.
2225
*
2326
* @property \Magento\Customer\Model\ResourceModel\Address\Collection $collection
27+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2428
*/
2529
class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider
2630
{
@@ -41,7 +45,7 @@ class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider
4145
*/
4246
private $allowToShowHiddenAttributes;
4347

44-
/*
48+
/**
4549
* @var ContextInterface
4650
*/
4751
private $context;
@@ -72,6 +76,11 @@ class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider
7276
*/
7377
private $attributeMetadataResolver;
7478

79+
/**
80+
* @var AddressRegistry
81+
*/
82+
private $addressRegistry;
83+
7584
/**
7685
* DataProvider constructor.
7786
* @param string $name
@@ -86,6 +95,7 @@ class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider
8695
* @param array $meta
8796
* @param array $data
8897
* @param bool $allowToShowHiddenAttributes
98+
* @param AddressRegistry|null $addressRegistry
8999
* @throws \Magento\Framework\Exception\LocalizedException
90100
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
91101
*/
@@ -101,7 +111,8 @@ public function __construct(
101111
AttributeMetadataResolver $attributeMetadataResolver,
102112
array $meta = [],
103113
array $data = [],
104-
$allowToShowHiddenAttributes = true
114+
$allowToShowHiddenAttributes = true,
115+
?AddressRegistry $addressRegistry = null
105116
) {
106117
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
107118
$this->collection = $addressCollectionFactory->create();
@@ -111,6 +122,7 @@ public function __construct(
111122
$this->context = $context;
112123
$this->fileUploaderDataResolver = $fileUploaderDataResolver;
113124
$this->attributeMetadataResolver = $attributeMetadataResolver;
125+
$this->addressRegistry = $addressRegistry ?? ObjectManager::getInstance()->get(AddressRegistry::class);
114126
$this->meta['general']['children'] = $this->getAttributesMeta(
115127
$eavConfig->getEntityType('customer_address')
116128
);
@@ -210,7 +222,20 @@ private function getDefaultData(): array
210222
private function getAttributesMeta(Type $entityType): array
211223
{
212224
$meta = [];
225+
/** @var AddressAttributeCollection $attributes */
213226
$attributes = $entityType->getAttributeCollection();
227+
$customerId = $this->context->getRequestParam('parent_id');
228+
$entityId = $this->context->getRequestParam('entity_id');
229+
230+
if (!$customerId && $entityId) {
231+
$customerId = $this->addressRegistry->retrieve($entityId)->getParentId();
232+
}
233+
234+
if ($customerId) {
235+
$customer = $this->customerRepository->getById($customerId);
236+
$attributes->setWebsite($customer->getWebsiteId());
237+
}
238+
214239
/* @var AbstractAttribute $attribute */
215240
foreach ($attributes as $attribute) {
216241
if (\in_array($attribute->getFrontendInput(), $this->bannedInputTypes, true)) {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<actionGroup name="AdminCustomerShowTelephoneActionGroup">
12+
<annotations>
13+
<description>Goes to the customer configuration. Set "Show Telephone" with provided value.</description>
14+
</annotations>
15+
<arguments>
16+
<argument name="value" type="string" defaultValue="{{ShowTelephone.optional}}"/>
17+
</arguments>
18+
<scrollTo selector="{{AdminCustomerConfigSection.showTelephone}}" x="0" y="-100" stepKey="scrollToShowTelephone"/>
19+
<uncheckOption selector="{{AdminCustomerConfigSection.showTelephoneInherit}}" stepKey="uncheckUseSystem"/>
20+
<selectOption selector="{{AdminCustomerConfigSection.showTelephone}}" userInput="{{value}}" stepKey="fillShowTelephone"/>
21+
<click selector="{{AdminMainActionsSection.save}}" stepKey="clickSave"/>
22+
<seeElement selector="{{AdminMessagesSection.success}}" stepKey="seeSuccessMessage"/>
23+
</actionGroup>
24+
</actionGroups>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<actionGroup name="AdminCustomerShowTelephoneUseDefaultActionGroup">
12+
<annotations>
13+
<description>Goes to the customer configuration. Check "Use system value" or "Use Default".</description>
14+
</annotations>
15+
<scrollTo selector="{{AdminCustomerConfigSection.showTelephone}}" x="0" y="-100" stepKey="scrollToShowTelephone"/>
16+
<checkOption selector="{{AdminCustomerConfigSection.showTelephoneInherit}}" stepKey="uncheckUseSystem"/>
17+
<click selector="{{AdminMainActionsSection.save}}" stepKey="clickSave"/>
18+
<seeElement selector="{{AdminMessagesSection.success}}" stepKey="seeSuccessMessage"/>
19+
</actionGroup>
20+
</actionGroups>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<actionGroup name="AdminNavigateToCustomerConfigurationActionGroup">
12+
<annotations>
13+
<description>Navigate to customer configuration.</description>
14+
</annotations>
15+
<amOnPage url="{{AdminCustomerConfigPage.url('')}}" stepKey="openCustomerConfigPage"/>
16+
<waitForPageLoad stepKey="waitCustomerConfigPage"/>
17+
</actionGroup>
18+
</actionGroups>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<actionGroup name="AssertAdminCustomerAddressInAddressGridActionGroup">
12+
<annotations>
13+
<description>Assert customer address is in addresses grid</description>
14+
</annotations>
15+
<arguments>
16+
<argument name="text" type="string"/>
17+
</arguments>
18+
<see selector="{{AdminCustomerAddressesGridSection.customerAddressGrid}}" userInput="{{text}}" stepKey="seeText"/>
19+
</actionGroup>
20+
</actionGroups>

app/code/Magento/Customer/Test/Mftf/Data/AddressData.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@
6767
<data key="telephone">512-345-6789</data>
6868
<requiredEntity type="region">RegionTX</requiredEntity>
6969
</entity>
70+
<entity name="US_Address_TX_Without_Default_And_Telephone" extends="US_Address_TX_Without_Default">
71+
<data key="telephone"></data>
72+
</entity>
7073
<entity name="US_Address_TX_Default_Billing" type="address">
7174
<data key="firstname">John</data>
7275
<data key="lastname">Doe</data>

app/code/Magento/Customer/Test/Mftf/Data/AdminCustomerConfigData.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,14 @@
1313
<data key="optional">Optional</data>
1414
<data key="required">Required</data>
1515
</entity>
16+
<entity name="ShowTelephone">
17+
<data key="no">No</data>
18+
<data key="optional">Optional</data>
19+
<data key="required">Required</data>
20+
</entity>
21+
<entity name="CustomerConfigurationSectionNameAndAddressOptions">
22+
<data key="id">customer_address-head</data>
23+
<data key="title">Name and Address Options</data>
24+
<data key="link">#customer_address-link</data>
25+
</entity>
1626
</entities>

app/code/Magento/Customer/Test/Mftf/Section/AdminCustomerConfigSection.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@
1313
<element name="shareCustomerAccount" type="select" selector="#customer_account_share_scope"/>
1414
<element name="showDateOfBirth" type="select" selector="#customer_address_dob_show"/>
1515
<element name="showDateOfBirthInherit" type="select" selector="#customer_address_dob_show_inherit"/>
16+
<element name="showTelephone" type="select" selector="#customer_address_telephone_show"/>
17+
<element name="showTelephoneInherit" type="checkbox" selector="#customer_address_telephone_show_inherit"/>
1618
</section>
1719
</sections>

0 commit comments

Comments
 (0)