7
7
namespace Magento \Customer \Model \Address ;
8
8
9
9
use Magento \Customer \Api \CustomerRepositoryInterface ;
10
+ use Magento \Customer \Model \AddressRegistry ;
10
11
use Magento \Customer \Model \Config \Share ;
11
12
use Magento \Customer \Model \ResourceModel \Address \CollectionFactory ;
12
13
use Magento \Eav \Model \Config ;
23
24
* Dataprovider of customer addresses for customer address grid.
24
25
*
25
26
* @property \Magento\Customer\Model\ResourceModel\Address\Collection $collection
27
+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
26
28
*/
27
29
class DataProvider extends \Magento \Ui \DataProvider \AbstractDataProvider
28
30
{
@@ -75,10 +77,15 @@ class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider
75
77
private $ attributeMetadataResolver ;
76
78
77
79
/**
78
- * @var Share|null
80
+ * @var Share
79
81
*/
80
82
private $ shareConfig ;
81
83
84
+ /**
85
+ * @var AddressRegistry
86
+ */
87
+ private $ addressRegistry ;
88
+
82
89
/**
83
90
* DataProvider constructor.
84
91
* @param string $name
@@ -94,6 +101,7 @@ class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider
94
101
* @param array $data
95
102
* @param bool $allowToShowHiddenAttributes
96
103
* @param Share|null $shareConfig
104
+ * @param AddressRegistry|null $addressRegistry
97
105
* @throws \Magento\Framework\Exception\LocalizedException
98
106
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
99
107
*/
@@ -110,7 +118,8 @@ public function __construct(
110
118
array $ meta = [],
111
119
array $ data = [],
112
120
$ allowToShowHiddenAttributes = true ,
113
- ?Share $ shareConfig = null
121
+ ?Share $ shareConfig = null ,
122
+ ?AddressRegistry $ addressRegistry = null
114
123
) {
115
124
parent ::__construct ($ name , $ primaryFieldName , $ requestFieldName , $ meta , $ data );
116
125
$ this ->collection = $ addressCollectionFactory ->create ();
@@ -121,6 +130,7 @@ public function __construct(
121
130
$ this ->fileUploaderDataResolver = $ fileUploaderDataResolver ;
122
131
$ this ->attributeMetadataResolver = $ attributeMetadataResolver ;
123
132
$ this ->shareConfig = $ shareConfig ?? ObjectManager::getInstance ()->get (Share::class);
133
+ $ this ->addressRegistry = $ addressRegistry ?? ObjectManager::getInstance ()->get (AddressRegistry::class);
124
134
$ this ->meta ['general ' ]['children ' ] = $ this ->getAttributesMeta (
125
135
$ eavConfig ->getEntityType ('customer_address ' )
126
136
);
@@ -220,13 +230,19 @@ private function getDefaultData(): array
220
230
private function getAttributesMeta (Type $ entityType ): array
221
231
{
222
232
$ 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
+ }
225
238
/** @var \Magento\Customer\Model\ResourceModel\Address\Attribute\Collection $sharedCollection */
226
239
$ sharedCollection = $ entityType ->getAttributeCollection ();
227
240
$ 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
+ }
230
246
}
231
247
232
248
/* @var AbstractAttribute $attribute */
0 commit comments