Skip to content

Commit 56cdfc8

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

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

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

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

99
use Magento\Customer\Api\CustomerRepositoryInterface;
10+
use Magento\Customer\Model\AddressRegistry;
1011
use Magento\Customer\Model\Config\Share;
1112
use Magento\Customer\Model\ResourceModel\Address\CollectionFactory;
1213
use Magento\Eav\Model\Config;
@@ -23,6 +24,7 @@
2324
* Dataprovider of customer addresses for customer address grid.
2425
*
2526
* @property \Magento\Customer\Model\ResourceModel\Address\Collection $collection
27+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2628
*/
2729
class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider
2830
{
@@ -75,10 +77,15 @@ class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider
7577
private $attributeMetadataResolver;
7678

7779
/**
78-
* @var Share|null
80+
* @var Share
7981
*/
8082
private $shareConfig;
8183

84+
/**
85+
* @var AddressRegistry
86+
*/
87+
private $addressRegistry;
88+
8289
/**
8390
* DataProvider constructor.
8491
* @param string $name
@@ -94,6 +101,7 @@ class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider
94101
* @param array $data
95102
* @param bool $allowToShowHiddenAttributes
96103
* @param Share|null $shareConfig
104+
* @param AddressRegistry|null $addressRegistry
97105
* @throws \Magento\Framework\Exception\LocalizedException
98106
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
99107
*/
@@ -110,7 +118,8 @@ public function __construct(
110118
array $meta = [],
111119
array $data = [],
112120
$allowToShowHiddenAttributes = true,
113-
?Share $shareConfig = null
121+
?Share $shareConfig = null,
122+
?AddressRegistry $addressRegistry = null
114123
) {
115124
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
116125
$this->collection = $addressCollectionFactory->create();
@@ -121,6 +130,7 @@ public function __construct(
121130
$this->fileUploaderDataResolver = $fileUploaderDataResolver;
122131
$this->attributeMetadataResolver = $attributeMetadataResolver;
123132
$this->shareConfig = $shareConfig ?? ObjectManager::getInstance()->get(Share::class);
133+
$this->addressRegistry = $addressRegistry ?? ObjectManager::getInstance()->get(AddressRegistry::class);
124134
$this->meta['general']['children'] = $this->getAttributesMeta(
125135
$eavConfig->getEntityType('customer_address')
126136
);
@@ -220,13 +230,19 @@ private function getDefaultData(): array
220230
private function getAttributesMeta(Type $entityType): array
221231
{
222232
$meta = [];
223-
$parentId = $this->context->getRequestParam('parent_id');
224-
$customer = $this->customerRepository->getById($parentId);
233+
$customerId = $this->context->getRequestParam('parent_id');
234+
$entityId = $this->context->getRequestParam('entity_id');
235+
if (!$customerId && $entityId) {
236+
$customerId = $this->addressRegistry->retrieve($entityId)->getParentId();
237+
}
225238
/** @var \Magento\Customer\Model\ResourceModel\Address\Attribute\Collection $sharedCollection */
226239
$sharedCollection = $entityType->getAttributeCollection();
227240
$collection = clone $sharedCollection;
228-
if (!$this->shareConfig->isGlobalScope()) {
229-
$collection->setWebsite($customer->getWebsiteId());
241+
if ($customerId) {
242+
$customer = $this->customerRepository->getById($customerId);
243+
if (!$this->shareConfig->isGlobalScope()) {
244+
$collection->setWebsite($customer->getWebsiteId());
245+
}
230246
}
231247

232248
/* @var AbstractAttribute $attribute */

0 commit comments

Comments
 (0)