26
26
use Magento \Framework \Api \SearchCriteria \CollectionProcessorInterface ;
27
27
use Magento \Framework \Api \SearchCriteriaInterface ;
28
28
use Magento \Framework \App \ObjectManager ;
29
+ use Magento \Framework \EntityManager \HydratorInterface ;
29
30
use Magento \Framework \Event \ManagerInterface ;
30
31
use Magento \Store \Model \StoreManagerInterface ;
31
32
@@ -119,6 +120,11 @@ class CustomerRepository implements CustomerRepositoryInterface
119
120
*/
120
121
private $ delegatedStorage ;
121
122
123
+ /**
124
+ * @var HydratorInterface
125
+ */
126
+ private $ hydrator ;
127
+
122
128
/**
123
129
* @param CustomerFactory $customerFactory
124
130
* @param CustomerSecureFactory $customerSecureFactory
@@ -136,6 +142,7 @@ class CustomerRepository implements CustomerRepositoryInterface
136
142
* @param CollectionProcessorInterface $collectionProcessor
137
143
* @param NotificationStorage $notificationStorage
138
144
* @param DelegatedStorage|null $delegatedStorage
145
+ * @param HydratorInterface|null $hydrator
139
146
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
140
147
*/
141
148
public function __construct (
@@ -154,7 +161,8 @@ public function __construct(
154
161
JoinProcessorInterface $ extensionAttributesJoinProcessor ,
155
162
CollectionProcessorInterface $ collectionProcessor ,
156
163
NotificationStorage $ notificationStorage ,
157
- DelegatedStorage $ delegatedStorage = null
164
+ DelegatedStorage $ delegatedStorage = null ,
165
+ ?HydratorInterface $ hydrator = null
158
166
) {
159
167
$ this ->customerFactory = $ customerFactory ;
160
168
$ this ->customerSecureFactory = $ customerSecureFactory ;
@@ -172,6 +180,7 @@ public function __construct(
172
180
$ this ->collectionProcessor = $ collectionProcessor ;
173
181
$ this ->notificationStorage = $ notificationStorage ;
174
182
$ this ->delegatedStorage = $ delegatedStorage ?? ObjectManager::getInstance ()->get (DelegatedStorage::class);
183
+ $ this ->hydrator = $ hydrator ?: ObjectManager::getInstance ()->get (HydratorInterface::class);
175
184
}
176
185
177
186
/**
@@ -185,6 +194,7 @@ public function __construct(
185
194
* @throws \Magento\Framework\Exception\LocalizedException
186
195
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
187
196
* @SuppressWarnings(PHPMD.NPathComplexity)
197
+ * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
188
198
*/
189
199
public function save (CustomerInterface $ customer , $ passwordHash = null )
190
200
{
@@ -193,10 +203,11 @@ public function save(CustomerInterface $customer, $passwordHash = null)
193
203
$ prevCustomerData = $ prevCustomerDataArr = null ;
194
204
if ($ customer ->getId ()) {
195
205
$ prevCustomerData = $ this ->getById ($ customer ->getId ());
196
- $ prevCustomerDataArr = $ prevCustomerData ->__toArray ();
206
+ $ prevCustomerDataArr = $ this ->hydrator ->extract ($ prevCustomerData );
207
+ $ customer = $ this ->hydrator ->hydrate ($ prevCustomerData , $ customer ->__toArray ());
197
208
}
198
209
/** @var $customer \Magento\Customer\Model\Data\Customer */
199
- $ customerArr = $ customer -> __toArray ( );
210
+ $ customerArr = $ this -> hydrator -> extract ( $ customer );
200
211
$ customer = $ this ->imageProcessor ->save (
201
212
$ customer ,
202
213
CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER ,
0 commit comments