Skip to content

Commit 9d259d3

Browse files
committed
ACP2E-675: Telephone required on all websites when set to be optional on some
1 parent 56cdfc8 commit 9d259d3

File tree

5 files changed

+62
-40
lines changed

5 files changed

+62
-40
lines changed

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

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
namespace Magento\Customer\Controller\Adminhtml\Address;
88

99
use Magento\Backend\App\Action;
10-
use Magento\Customer\Api\CustomerRepositoryInterface;
11-
use Magento\Customer\Model\Config\Share;
1210
use Magento\Customer\Model\CustomerRegistry;
1311
use Magento\Framework\App\Action\HttpPostActionInterface;
1412
use Magento\Framework\App\ObjectManager;
@@ -67,11 +65,6 @@ class Save extends Action implements HttpPostActionInterface
6765
*/
6866
private $resultJsonFactory;
6967

70-
/**
71-
* @var Share
72-
*/
73-
private $shareConfig;
74-
7568
/**
7669
* @var StoreManagerInterface
7770
*/
@@ -91,7 +84,6 @@ class Save extends Action implements HttpPostActionInterface
9184
* @param \Magento\Customer\Api\Data\AddressInterfaceFactory $addressDataFactory
9285
* @param LoggerInterface $logger
9386
* @param JsonFactory $resultJsonFactory
94-
* @param Share|null $shareConfig
9587
* @param StoreManagerInterface|null $storeManager
9688
* @param CustomerRegistry|null $customerRegistry
9789
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
@@ -105,7 +97,6 @@ public function __construct(
10597
\Magento\Customer\Api\Data\AddressInterfaceFactory $addressDataFactory,
10698
LoggerInterface $logger,
10799
JsonFactory $resultJsonFactory,
108-
?Share $shareConfig = null,
109100
?StoreManagerInterface $storeManager = null,
110101
?CustomerRegistry $customerRegistry = null
111102
) {
@@ -117,8 +108,6 @@ public function __construct(
117108
$this->addressDataFactory = $addressDataFactory;
118109
$this->logger = $logger;
119110
$this->resultJsonFactory = $resultJsonFactory;
120-
$this->shareConfig = $shareConfig
121-
?? ObjectManager::getInstance()->get(Share::class);
122111
$this->storeManager = $storeManager
123112
?? ObjectManager::getInstance()->get(StoreManagerInterface::class);
124113
$this->customerRegistry = $customerRegistry
@@ -138,7 +127,7 @@ public function execute(): Json
138127
$error = false;
139128
try {
140129
$customerModel = $this->customerRegistry->retrieve($customerId);
141-
if (!$this->shareConfig->isGlobalScope() && $customerModel->getStoreId()) {
130+
if ($customerModel->getStoreId()) {
142131
$this->storeManager->setCurrentStore($customerModel->getStoreId());
143132
}
144133
/** @var \Magento\Customer\Api\Data\CustomerInterface $customer */

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

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
namespace Magento\Customer\Controller\Adminhtml\Address;
88

99
use Magento\Backend\App\Action;
10-
use Magento\Customer\Api\CustomerRepositoryInterface;
11-
use Magento\Customer\Model\Config\Share;
1210
use Magento\Customer\Model\CustomerRegistry;
1311
use Magento\Framework\App\Action\HttpGetActionInterface;
1412
use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
@@ -39,11 +37,6 @@ class Validate extends Action implements HttpPostActionInterface, HttpGetActionI
3937
*/
4038
private $formFactory;
4139

42-
/**
43-
* @var Share
44-
*/
45-
private $shareConfig;
46-
4740
/**
4841
* @var StoreManagerInterface
4942
*/
@@ -58,23 +51,19 @@ class Validate extends Action implements HttpPostActionInterface, HttpGetActionI
5851
* @param Action\Context $context
5952
* @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
6053
* @param \Magento\Customer\Model\Metadata\FormFactory $formFactory
61-
* @param Share|null $shareConfig
6254
* @param StoreManagerInterface|null $storeManager
6355
* @param CustomerRegistry|null $customerRegistry
6456
*/
6557
public function __construct(
6658
Action\Context $context,
6759
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory,
6860
\Magento\Customer\Model\Metadata\FormFactory $formFactory,
69-
?Share $shareConfig = null,
7061
?StoreManagerInterface $storeManager = null,
7162
?CustomerRegistry $customerRegistry = null
7263
) {
7364
parent::__construct($context);
7465
$this->resultJsonFactory = $resultJsonFactory;
7566
$this->formFactory = $formFactory;
76-
$this->shareConfig = $shareConfig
77-
?? ObjectManager::getInstance()->get(Share::class);
7867
$this->storeManager = $storeManager
7968
?? ObjectManager::getInstance()->get(StoreManagerInterface::class);
8069
$this->customerRegistry = $customerRegistry
@@ -91,7 +80,7 @@ public function execute(): Json
9180
$customerId = $this->getRequest()->getParam('parent_id');
9281
if ($customerId) {
9382
$customerModel = $this->customerRegistry->retrieve($customerId);
94-
if (!$this->shareConfig->isGlobalScope() && $customerModel->getStoreId()) {
83+
if ($customerModel->getStoreId()) {
9584
$this->storeManager->setCurrentStore($customerModel->getStoreId());
9685
}
9786
}

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

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
use Magento\Customer\Api\CustomerRepositoryInterface;
1010
use Magento\Customer\Model\AddressRegistry;
11-
use Magento\Customer\Model\Config\Share;
1211
use Magento\Customer\Model\ResourceModel\Address\CollectionFactory;
1312
use Magento\Eav\Model\Config;
1413
use Magento\Eav\Model\Entity\Type;
@@ -76,11 +75,6 @@ class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider
7675
*/
7776
private $attributeMetadataResolver;
7877

79-
/**
80-
* @var Share
81-
*/
82-
private $shareConfig;
83-
8478
/**
8579
* @var AddressRegistry
8680
*/
@@ -100,7 +94,6 @@ class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider
10094
* @param array $meta
10195
* @param array $data
10296
* @param bool $allowToShowHiddenAttributes
103-
* @param Share|null $shareConfig
10497
* @param AddressRegistry|null $addressRegistry
10598
* @throws \Magento\Framework\Exception\LocalizedException
10699
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
@@ -118,7 +111,6 @@ public function __construct(
118111
array $meta = [],
119112
array $data = [],
120113
$allowToShowHiddenAttributes = true,
121-
?Share $shareConfig = null,
122114
?AddressRegistry $addressRegistry = null
123115
) {
124116
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
@@ -129,7 +121,6 @@ public function __construct(
129121
$this->context = $context;
130122
$this->fileUploaderDataResolver = $fileUploaderDataResolver;
131123
$this->attributeMetadataResolver = $attributeMetadataResolver;
132-
$this->shareConfig = $shareConfig ?? ObjectManager::getInstance()->get(Share::class);
133124
$this->addressRegistry = $addressRegistry ?? ObjectManager::getInstance()->get(AddressRegistry::class);
134125
$this->meta['general']['children'] = $this->getAttributesMeta(
135126
$eavConfig->getEntityType('customer_address')
@@ -240,9 +231,7 @@ private function getAttributesMeta(Type $entityType): array
240231
$collection = clone $sharedCollection;
241232
if ($customerId) {
242233
$customer = $this->customerRepository->getById($customerId);
243-
if (!$this->shareConfig->isGlobalScope()) {
244-
$collection->setWebsite($customer->getWebsiteId());
245-
}
234+
$collection->setWebsite($customer->getWebsiteId());
246235
}
247236

248237
/* @var AbstractAttribute $attribute */

app/code/Magento/Customer/Test/Unit/Controller/Address/SaveTest.php

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,23 @@
1313
use Magento\Customer\Api\Data\AddressInterfaceFactory;
1414
use Magento\Customer\Api\Data\CustomerInterface;
1515
use Magento\Customer\Controller\Adminhtml\Address\Save;
16+
use Magento\Customer\Model\Customer;
17+
use Magento\Customer\Model\CustomerRegistry;
1618
use Magento\Customer\Model\Metadata\Form;
1719
use Magento\Customer\Model\Metadata\FormFactory;
1820
use Magento\Framework\Api\DataObjectHelper;
1921
use Magento\Framework\App\RequestInterface;
2022
use Magento\Framework\Controller\Result\Json;
2123
use Magento\Framework\Controller\Result\JsonFactory;
2224
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
25+
use Magento\Store\Model\StoreManagerInterface;
2326
use PHPUnit\Framework\MockObject\MockObject;
2427
use PHPUnit\Framework\TestCase;
2528
use Psr\Log\LoggerInterface;
2629

2730
/**
2831
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
32+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
2933
*/
3034
class SaveTest extends TestCase
3135
{
@@ -84,6 +88,16 @@ class SaveTest extends TestCase
8488
*/
8589
private $json;
8690

91+
/**
92+
* @var StoreManagerInterface|MockObject
93+
*/
94+
private $storeManager;
95+
96+
/**
97+
* @var CustomerRegistry|MockObject
98+
*/
99+
private $customerRegistry;
100+
87101
/**
88102
* @inheritdoc
89103
*/
@@ -106,6 +120,12 @@ protected function setUp(): void
106120
$this->json = $this->getMockBuilder(Json::class)
107121
->disableOriginalConstructor()
108122
->getMock();
123+
$this->storeManager = $this->getMockBuilder(StoreManagerInterface::class)
124+
->disableOriginalConstructor()
125+
->getMock();
126+
$this->customerRegistry = $this->getMockBuilder(CustomerRegistry::class)
127+
->disableOriginalConstructor()
128+
->getMock();
109129

110130
$objectManager = new ObjectManagerHelper($this);
111131

@@ -117,9 +137,11 @@ protected function setUp(): void
117137
'customerRepository' => $this->customerRepositoryMock,
118138
'dataObjectHelper' => $this->dataObjectHelperMock,
119139
'addressDataFactory' => $this->addressDataFactoryMock,
120-
'logger' => $this->loggerMock,
140+
'logger' => $this->loggerMock,
121141
'request' => $this->requestMock,
122-
'resultJsonFactory' => $this->resultJsonFactory
142+
'resultJsonFactory' => $this->resultJsonFactory,
143+
'storeManager' => $this->storeManager,
144+
'customerRegistry' => $this->customerRegistry,
123145
]
124146
);
125147
}
@@ -220,6 +242,21 @@ public function testExecute(): void
220242
]
221243
)->willReturnSelf();
222244

245+
$customerModel = $this->getMockBuilder(Customer::class)
246+
->disableOriginalConstructor()
247+
->addMethods(['getStoreId'])
248+
->getMock();
249+
$customerModel->method('getStoreId')
250+
->willReturn(2);
251+
$this->customerRegistry->expects($this->once())
252+
->method('retrieve')
253+
->with(22)
254+
->willReturn($customerModel);
255+
256+
$this->storeManager->expects($this->once())
257+
->method('setCurrentStore')
258+
->with(2);
259+
223260
$this->assertEquals($this->json, $this->model->execute());
224261
}
225262
}

app/code/Magento/Customer/Test/Unit/Model/Address/DataProviderTest.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
use Magento\Customer\Api\Data\CustomerInterface;
1313
use Magento\Customer\Model\Address as AddressModel;
1414
use Magento\Customer\Model\Address\DataProvider;
15+
use Magento\Customer\Model\AddressRegistry;
1516
use Magento\Customer\Model\AttributeMetadataResolver;
1617
use Magento\Customer\Model\FileUploaderDataResolver;
18+
use Magento\Customer\Model\ResourceModel\Address\Attribute\Collection;
1719
use Magento\Customer\Model\ResourceModel\Address\Collection as AddressCollection;
1820
use Magento\Customer\Model\ResourceModel\Address\CollectionFactory;
1921
use Magento\Eav\Model\Config;
@@ -83,6 +85,11 @@ class DataProviderTest extends TestCase
8385
*/
8486
private $model;
8587

88+
/**
89+
* @var AddressRegistry|MockObject
90+
*/
91+
private $addressRegistry;
92+
8693
/**
8794
* @inheritdoc
8895
*/
@@ -162,6 +169,8 @@ protected function setUp(): void
162169
]
163170
]
164171
);
172+
173+
$this->addressRegistry = $this->createMock(AddressRegistry::class);
165174
$this->model = $objectManagerHelper->getObject(
166175
DataProvider::class,
167176
[
@@ -176,7 +185,8 @@ protected function setUp(): void
176185
'attributeMetadataResolver' => $this->attributeMetadataResolver,
177186
[],
178187
[],
179-
true
188+
true,
189+
'addressRegistry' => $this->addressRegistry
180190
]
181191
);
182192
}
@@ -289,9 +299,17 @@ protected function getTypeAddressMock(array $customerAttributes = []): Type
289299
->willReturn($typeAddressMock);
290300
}
291301

302+
$attributesCollectionMock = $this->getMockBuilder(Collection::class)
303+
->disableOriginalConstructor()
304+
->onlyMethods(['getIterator'])
305+
->getMockForAbstractClass();
306+
307+
$attributesCollectionMock->method('getIterator')
308+
->willReturn(new \ArrayIterator($attributesCollection));
309+
292310
$typeAddressMock->expects($this->once())
293311
->method('getAttributeCollection')
294-
->willReturn($attributesCollection);
312+
->willReturn($attributesCollectionMock);
295313

296314
return $typeAddressMock;
297315
}

0 commit comments

Comments
 (0)