@@ -143,9 +143,9 @@ class Create extends \Magento\Framework\Object implements \Magento\Checkout\Mode
143
143
protected $ addressRepository ;
144
144
145
145
/**
146
- * @var \Magento\Customer\Api\Data\AddressDataBuilder
146
+ * @var \Magento\Customer\Api\Data\AddressInterfaceFactory
147
147
*/
148
- protected $ addressBuilder ;
148
+ protected $ addressFactory ;
149
149
150
150
/**
151
151
* @var \Magento\Customer\Model\Metadata\FormFactory
@@ -188,9 +188,9 @@ class Create extends \Magento\Framework\Object implements \Magento\Checkout\Mode
188
188
protected $ accountManagement ;
189
189
190
190
/**
191
- * @var \Magento\Customer\Api\Data\CustomerDataBuilder
191
+ * @var \Magento\Customer\Api\Data\CustomerInterfaceFactory
192
192
*/
193
- protected $ customerBuilder ;
193
+ protected $ customerFactory ;
194
194
195
195
/**
196
196
* Constructor
@@ -209,6 +209,11 @@ class Create extends \Magento\Framework\Object implements \Magento\Checkout\Mode
209
209
*/
210
210
protected $ quoteManagement ;
211
211
212
+ /**
213
+ * @var \Magento\Framework\Api\DataObjectHelper
214
+ */
215
+ protected $ dataObjectHelper ;
216
+
212
217
/**
213
218
* @param \Magento\Framework\ObjectManagerInterface $objectManager
214
219
* @param \Magento\Framework\Event\ManagerInterface $eventManager
@@ -221,7 +226,7 @@ class Create extends \Magento\Framework\Object implements \Magento\Checkout\Mode
221
226
* @param Product\Quote\Initializer $quoteInitializer
222
227
* @param \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository
223
228
* @param \Magento\Customer\Api\AddressRepositoryInterface $addressRepository
224
- * @param \Magento\Customer\Api\Data\AddressDataBuilder $addressBuilder
229
+ * @param \Magento\Customer\Api\Data\AddressInterfaceFactory $addressFactory
225
230
* @param \Magento\Customer\Model\Metadata\FormFactory $metadataFormFactory
226
231
* @param \Magento\Customer\Api\GroupRepositoryInterface $groupRepository
227
232
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
@@ -231,9 +236,10 @@ class Create extends \Magento\Framework\Object implements \Magento\Checkout\Mode
231
236
* @param \Magento\Framework\Object\Factory $objectFactory
232
237
* @param \Magento\Quote\Model\QuoteRepository $quoteRepository
233
238
* @param \Magento\Customer\Api\AccountManagementInterface $accountManagement
234
- * @param \Magento\Customer\Api\Data\CustomerDataBuilder $customerBuilder
239
+ * @param \Magento\Customer\Api\Data\CustomerInterfaceFactory $customerFactory
235
240
* @param \Magento\Customer\Model\Customer\Mapper $customerMapper
236
241
* @param \Magento\Quote\Model\QuoteManagement $quoteManagement
242
+ * @param \Magento\Framework\Api\DataObjectHelper $dataObjectHelper
237
243
* @param array $data
238
244
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
239
245
*/
@@ -249,7 +255,7 @@ public function __construct(
249
255
Product \Quote \Initializer $ quoteInitializer ,
250
256
\Magento \Customer \Api \CustomerRepositoryInterface $ customerRepository ,
251
257
\Magento \Customer \Api \AddressRepositoryInterface $ addressRepository ,
252
- \Magento \Customer \Api \Data \AddressDataBuilder $ addressBuilder ,
258
+ \Magento \Customer \Api \Data \AddressInterfaceFactory $ addressFactory ,
253
259
\Magento \Customer \Model \Metadata \FormFactory $ metadataFormFactory ,
254
260
\Magento \Customer \Api \GroupRepositoryInterface $ groupRepository ,
255
261
\Magento \Framework \App \Config \ScopeConfigInterface $ scopeConfig ,
@@ -259,9 +265,10 @@ public function __construct(
259
265
\Magento \Framework \Object \Factory $ objectFactory ,
260
266
\Magento \Quote \Model \QuoteRepository $ quoteRepository ,
261
267
\Magento \Customer \Api \AccountManagementInterface $ accountManagement ,
262
- \Magento \Customer \Api \Data \CustomerDataBuilder $ customerBuilder ,
268
+ \Magento \Customer \Api \Data \CustomerInterfaceFactory $ customerFactory ,
263
269
\Magento \Customer \Model \Customer \Mapper $ customerMapper ,
264
270
\Magento \Quote \Model \QuoteManagement $ quoteManagement ,
271
+ \Magento \Framework \Api \DataObjectHelper $ dataObjectHelper ,
265
272
array $ data = []
266
273
) {
267
274
$ this ->_objectManager = $ objectManager ;
@@ -275,9 +282,9 @@ public function __construct(
275
282
$ this ->messageManager = $ messageManager ;
276
283
$ this ->customerRepository = $ customerRepository ;
277
284
$ this ->addressRepository = $ addressRepository ;
278
- $ this ->addressBuilder = $ addressBuilder ;
285
+ $ this ->addressFactory = $ addressFactory ;
279
286
$ this ->_metadataFormFactory = $ metadataFormFactory ;
280
- $ this ->customerBuilder = $ customerBuilder ;
287
+ $ this ->customerFactory = $ customerFactory ;
281
288
$ this ->groupRepository = $ groupRepository ;
282
289
$ this ->_scopeConfig = $ scopeConfig ;
283
290
$ this ->emailSender = $ emailSender ;
@@ -288,6 +295,7 @@ public function __construct(
288
295
$ this ->accountManagement = $ accountManagement ;
289
296
$ this ->customerMapper = $ customerMapper ;
290
297
$ this ->quoteManagement = $ quoteManagement ;
298
+ $ this ->dataObjectHelper = $ dataObjectHelper ;
291
299
parent ::__construct ($ data );
292
300
}
293
301
@@ -1539,8 +1547,8 @@ public function setAccountData($accountData)
1539
1547
$ request = $ form ->prepareRequest ($ accountData );
1540
1548
$ data = $ form ->extractData ($ request );
1541
1549
$ data = $ form ->restoreData ($ data );
1542
- $ customer = $ this ->customerBuilder -> mergeDataObjectWithArray ( $ customer , $ data )
1543
- -> create ( );
1550
+ $ customer = $ this ->customerFactory -> create ();
1551
+ $ this -> dataObjectHelper -> populateWithArray ( $ customer , $ data );
1544
1552
$ this ->getQuote ()->updateCustomerData ($ customer );
1545
1553
$ data = [];
1546
1554
@@ -1658,8 +1666,8 @@ protected function _validateCustomerData(\Magento\Customer\Api\Data\CustomerInte
1658
1666
}
1659
1667
}
1660
1668
1661
- return $ this ->customerBuilder -> mergeDataObjectWithArray ($ customer , $ data )
1662
- -> create () ;
1669
+ $ this ->dataObjectHelper -> populateWithArray ($ customer , $ data );
1670
+ return $ customer ;
1663
1671
}
1664
1672
1665
1673
/**
@@ -1683,24 +1691,21 @@ public function _prepareCustomer()
1683
1691
if ($ customer ->getId () && !$ this ->_customerIsInStore ($ store )) {
1684
1692
/** Create a new customer record if it is not available in the specified store */
1685
1693
/** Unset customer ID to ensure that new customer will be created */
1686
- $ customer = $ this ->customerBuilder ->populate ($ customer )
1687
- ->setId (null )
1694
+ $ customer ->setId (null )
1688
1695
->setStoreId ($ store ->getId ())
1689
1696
->setWebsiteId ($ store ->getWebsiteId ())
1690
- ->setCreatedAt (null )-> create () ;
1697
+ ->setCreatedAt (null );
1691
1698
$ customer = $ this ->_validateCustomerData ($ customer );
1692
1699
} else if (!$ customer ->getId ()) {
1693
1700
/** Create new customer */
1694
1701
$ customerBillingAddressDataObject = $ this ->getBillingAddress ()->exportCustomerAddress ();
1695
- $ customer = $ this ->customerBuilder ->populate ($ customer )
1696
- ->setSuffix ($ customerBillingAddressDataObject ->getSuffix ())
1702
+ $ customer ->setSuffix ($ customerBillingAddressDataObject ->getSuffix ())
1697
1703
->setFirstname ($ customerBillingAddressDataObject ->getFirstname ())
1698
1704
->setLastname ($ customerBillingAddressDataObject ->getLastname ())
1699
1705
->setMiddlename ($ customerBillingAddressDataObject ->getMiddlename ())
1700
1706
->setPrefix ($ customerBillingAddressDataObject ->getPrefix ())
1701
1707
->setStoreId ($ store ->getId ())
1702
- ->setEmail ($ this ->_getNewCustomerEmail ())
1703
- ->create ();
1708
+ ->setEmail ($ this ->_getNewCustomerEmail ());
1704
1709
$ customer = $ this ->_validateCustomerData ($ customer );
1705
1710
}
1706
1711
$ this ->getQuote ()->setCustomer ($ customer );
@@ -1713,10 +1718,12 @@ public function _prepareCustomer()
1713
1718
}
1714
1719
$ this ->getQuote ()->updateCustomerData ($ this ->getQuote ()->getCustomer ());
1715
1720
1716
- $ customerData = $ this ->customerMapper ->toFlatArray (
1717
- $ this ->customerBuilder ->populate ($ this ->getQuote ()->getCustomer ())->setAddresses ([])->create ()
1718
- );
1719
- foreach ($ this ->_createCustomerForm ($ this ->getQuote ()->getCustomer ())->getUserAttributes () as $ attribute ) {
1721
+ $ customer = $ this ->getQuote ()->getCustomer ();
1722
+ $ origAddresses = $ customer ->getAddresses (); // save original addresses
1723
+ $ customer ->setAddresses ([]);
1724
+ $ customerData = $ this ->customerMapper ->toFlatArray ($ customer );
1725
+ $ customer ->setAddresses ($ origAddresses ); // restore original addresses
1726
+ foreach ($ this ->_createCustomerForm ($ customer )->getUserAttributes () as $ attribute ) {
1720
1727
if (isset ($ customerData [$ attribute ->getAttributeCode ()])) {
1721
1728
$ quoteCode = sprintf ('customer_%s ' , $ attribute ->getAttributeCode ());
1722
1729
$ this ->getQuote ()->setData ($ quoteCode , $ customerData [$ attribute ->getAttributeCode ()]);
@@ -1746,36 +1753,35 @@ protected function _prepareCustomerAddress($customer, $quoteCustomerAddress)
1746
1753
/** Update existing address */
1747
1754
$ existingAddressDataObject = $ this ->addressRepository ->getById ($ quoteAddressId );
1748
1755
/** Update customer address data */
1749
- $ customerAddress = $ this ->addressBuilder ->mergeDataObjects ($ existingAddressDataObject , $ customerAddress )
1750
- ->create ();
1756
+ $ this ->dataObjectHelper ->mergeDataObjects (
1757
+ get_class ($ existingAddressDataObject ),
1758
+ $ existingAddressDataObject ,
1759
+ $ customerAddress
1760
+ );
1761
+ $ customerAddress = $ existingAddressDataObject ;
1751
1762
} elseif ($ addressType == \Magento \Quote \Model \Quote \Address::ADDRESS_TYPE_SHIPPING ) {
1752
1763
try {
1753
- $ billingAddressDataObject = $ customer ->getDefaultBilling ( );
1764
+ $ billingAddressDataObject = $ this -> accountManagement -> getDefaultBillingAddress ( $ customer ->getId () );
1754
1765
} catch (\Exception $ e ) {
1755
1766
/** Billing address does not exist. */
1756
1767
}
1757
1768
$ isShippingAsBilling = $ quoteCustomerAddress ->getSameAsBilling ();
1758
1769
if (isset ($ billingAddressDataObject ) && $ isShippingAsBilling ) {
1759
1770
/** Set existing billing address as default shipping */
1760
- $ customerAddress = $ this ->addressBuilder ->populate ($ billingAddressDataObject )
1761
- ->setDefaultShipping (true )
1762
- ->create ();
1771
+ $ customerAddress = $ billingAddressDataObject ;
1772
+ $ customerAddress ->setDefaultShipping (true );
1763
1773
}
1764
1774
}
1765
1775
1766
1776
switch ($ addressType ) {
1767
1777
case \Magento \Quote \Model \Quote \Address::ADDRESS_TYPE_BILLING :
1768
1778
if (is_null ($ customer ->getDefaultBilling ())) {
1769
- $ customerAddress = $ this ->addressBuilder ->populate ($ customerAddress )
1770
- ->setDefaultBilling (true )
1771
- ->create ();
1779
+ $ customerAddress ->setDefaultBilling (true );
1772
1780
}
1773
1781
break ;
1774
1782
case \Magento \Quote \Model \Quote \Address::ADDRESS_TYPE_SHIPPING :
1775
1783
if (is_null ($ customer ->getDefaultShipping ())) {
1776
- $ customerAddress = $ this ->addressBuilder ->populate ($ customerAddress )
1777
- ->setDefaultShipping (true )
1778
- ->create ();
1784
+ $ customerAddress ->setDefaultShipping (true );
1779
1785
}
1780
1786
break ;
1781
1787
default :
0 commit comments