Skip to content

Commit 9f568fb

Browse files
MAGETWO-96007: Customer address issue when creating or updating via API
1 parent ec5fcb5 commit 9f568fb

File tree

1 file changed

+53
-46
lines changed

1 file changed

+53
-46
lines changed

app/code/Magento/Customer/Model/ResourceModel/CustomerRepository.php

Lines changed: 53 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -8,69 +8,80 @@
88

99
use Magento\Customer\Api\CustomerMetadataInterface;
1010
use Magento\Customer\Api\Data\CustomerInterface;
11-
use Magento\Customer\Model\Delegation\Data\NewOperation;
11+
use Magento\Customer\Api\Data\CustomerSearchResultsInterfaceFactory;
12+
use Magento\Framework\Api\ExtensibleDataObjectConverter;
13+
use Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface;
14+
use Magento\Customer\Model\CustomerFactory;
15+
use Magento\Customer\Model\CustomerRegistry;
16+
use Magento\Customer\Model\Data\CustomerSecureFactory;
1217
use Magento\Customer\Model\Customer\NotificationStorage;
18+
use Magento\Customer\Model\Delegation\Data\NewOperation;
19+
use Magento\Customer\Api\CustomerRepositoryInterface;
1320
use Magento\Framework\Api\DataObjectHelper;
1421
use Magento\Framework\Api\ImageProcessorInterface;
1522
use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface;
1623
use Magento\Framework\Api\SearchCriteriaInterface;
24+
use Magento\Framework\Api\Search\FilterGroup;
25+
use Magento\Framework\Event\ManagerInterface;
1726
use Magento\Customer\Model\Delegation\Storage as DelegatedStorage;
1827
use Magento\Framework\App\ObjectManager;
28+
use Magento\Store\Model\StoreManagerInterface;
1929

2030
/**
2131
* Customer repository.
32+
*
2233
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2334
* @SuppressWarnings(PHPMD.TooManyFields)
2435
*/
25-
class CustomerRepository implements \Magento\Customer\Api\CustomerRepositoryInterface
36+
class CustomerRepository implements CustomerRepositoryInterface
2637
{
2738
/**
28-
* @var \Magento\Customer\Model\CustomerFactory
39+
* @var CustomerFactory
2940
*/
3041
protected $customerFactory;
3142

3243
/**
33-
* @var \Magento\Customer\Model\Data\CustomerSecureFactory
44+
* @var CustomerSecureFactory
3445
*/
3546
protected $customerSecureFactory;
3647

3748
/**
38-
* @var \Magento\Customer\Model\CustomerRegistry
49+
* @var CustomerRegistry
3950
*/
4051
protected $customerRegistry;
4152

4253
/**
43-
* @var \Magento\Customer\Model\ResourceModel\AddressRepository
54+
* @var AddressRepository
4455
*/
4556
protected $addressRepository;
4657

4758
/**
48-
* @var \Magento\Customer\Model\ResourceModel\Customer
59+
* @var Customer
4960
*/
5061
protected $customerResourceModel;
5162

5263
/**
53-
* @var \Magento\Customer\Api\CustomerMetadataInterface
64+
* @var CustomerMetadataInterface
5465
*/
5566
protected $customerMetadata;
5667

5768
/**
58-
* @var \Magento\Customer\Api\Data\CustomerSearchResultsInterfaceFactory
69+
* @var CustomerSearchResultsInterfaceFactory
5970
*/
6071
protected $searchResultsFactory;
6172

6273
/**
63-
* @var \Magento\Framework\Event\ManagerInterface
74+
* @var ManagerInterface
6475
*/
6576
protected $eventManager;
6677

6778
/**
68-
* @var \Magento\Store\Model\StoreManagerInterface
79+
* @var StoreManagerInterface
6980
*/
7081
protected $storeManager;
7182

7283
/**
73-
* @var \Magento\Framework\Api\ExtensibleDataObjectConverter
84+
* @var ExtensibleDataObjectConverter
7485
*/
7586
protected $extensibleDataObjectConverter;
7687

@@ -85,7 +96,7 @@ class CustomerRepository implements \Magento\Customer\Api\CustomerRepositoryInte
8596
protected $imageProcessor;
8697

8798
/**
88-
* @var \Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface
99+
* @var JoinProcessorInterface
89100
*/
90101
protected $extensionAttributesJoinProcessor;
91102

@@ -105,38 +116,38 @@ class CustomerRepository implements \Magento\Customer\Api\CustomerRepositoryInte
105116
private $delegatedStorage;
106117

107118
/**
108-
* @param \Magento\Customer\Model\CustomerFactory $customerFactory
109-
* @param \Magento\Customer\Model\Data\CustomerSecureFactory $customerSecureFactory
110-
* @param \Magento\Customer\Model\CustomerRegistry $customerRegistry
111-
* @param \Magento\Customer\Model\ResourceModel\AddressRepository $addressRepository
112-
* @param \Magento\Customer\Model\ResourceModel\Customer $customerResourceModel
113-
* @param \Magento\Customer\Api\CustomerMetadataInterface $customerMetadata
114-
* @param \Magento\Customer\Api\Data\CustomerSearchResultsInterfaceFactory $searchResultsFactory
115-
* @param \Magento\Framework\Event\ManagerInterface $eventManager
116-
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
117-
* @param \Magento\Framework\Api\ExtensibleDataObjectConverter $extensibleDataObjectConverter
119+
* @param CustomerFactory $customerFactory
120+
* @param CustomerSecureFactory $customerSecureFactory
121+
* @param CustomerRegistry $customerRegistry
122+
* @param AddressRepository $addressRepository
123+
* @param Customer $customerResourceModel
124+
* @param CustomerMetadataInterface $customerMetadata
125+
* @param CustomerSearchResultsInterfaceFactory $searchResultsFactory
126+
* @param ManagerInterface $eventManager
127+
* @param StoreManagerInterface $storeManager
128+
* @param ExtensibleDataObjectConverter $extensibleDataObjectConverter
118129
* @param DataObjectHelper $dataObjectHelper
119130
* @param ImageProcessorInterface $imageProcessor
120-
* @param \Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface $extensionAttributesJoinProcessor
131+
* @param JoinProcessorInterface $extensionAttributesJoinProcessor
121132
* @param CollectionProcessorInterface $collectionProcessor
122133
* @param NotificationStorage $notificationStorage
123134
* @param DelegatedStorage|null $delegatedStorage
124135
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
125136
*/
126137
public function __construct(
127-
\Magento\Customer\Model\CustomerFactory $customerFactory,
128-
\Magento\Customer\Model\Data\CustomerSecureFactory $customerSecureFactory,
129-
\Magento\Customer\Model\CustomerRegistry $customerRegistry,
130-
\Magento\Customer\Model\ResourceModel\AddressRepository $addressRepository,
131-
\Magento\Customer\Model\ResourceModel\Customer $customerResourceModel,
132-
\Magento\Customer\Api\CustomerMetadataInterface $customerMetadata,
133-
\Magento\Customer\Api\Data\CustomerSearchResultsInterfaceFactory $searchResultsFactory,
134-
\Magento\Framework\Event\ManagerInterface $eventManager,
135-
\Magento\Store\Model\StoreManagerInterface $storeManager,
136-
\Magento\Framework\Api\ExtensibleDataObjectConverter $extensibleDataObjectConverter,
138+
CustomerFactory $customerFactory,
139+
CustomerSecureFactory $customerSecureFactory,
140+
CustomerRegistry $customerRegistry,
141+
AddressRepository $addressRepository,
142+
Customer $customerResourceModel,
143+
CustomerMetadataInterface $customerMetadata,
144+
CustomerSearchResultsInterfaceFactory $searchResultsFactory,
145+
ManagerInterface $eventManager,
146+
StoreManagerInterface $storeManager,
147+
ExtensibleDataObjectConverter $extensibleDataObjectConverter,
137148
DataObjectHelper $dataObjectHelper,
138149
ImageProcessorInterface $imageProcessor,
139-
\Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface $extensionAttributesJoinProcessor,
150+
JoinProcessorInterface $extensionAttributesJoinProcessor,
140151
CollectionProcessorInterface $collectionProcessor,
141152
NotificationStorage $notificationStorage,
142153
DelegatedStorage $delegatedStorage = null
@@ -156,8 +167,7 @@ public function __construct(
156167
$this->extensionAttributesJoinProcessor = $extensionAttributesJoinProcessor;
157168
$this->collectionProcessor = $collectionProcessor;
158169
$this->notificationStorage = $notificationStorage;
159-
$this->delegatedStorage = $delegatedStorage
160-
?? ObjectManager::getInstance()->get(DelegatedStorage::class);
170+
$this->delegatedStorage = $delegatedStorage ?? ObjectManager::getInstance()->get(DelegatedStorage::class);
161171
}
162172

163173
/**
@@ -200,13 +210,13 @@ public function save(CustomerInterface $customer, $passwordHash = null)
200210
$customerModel->setRpToken(null);
201211
$customerModel->setRpTokenCreatedAt(null);
202212
}
203-
if (!array_key_exists('default_billing', $customerArr)
213+
if (!array_key_exists('addresses', $customerArr)
204214
&& null !== $prevCustomerDataArr
205215
&& array_key_exists('default_billing', $prevCustomerDataArr)
206216
) {
207217
$customerModel->setDefaultBilling($prevCustomerDataArr['default_billing']);
208218
}
209-
if (!array_key_exists('default_shipping', $customerArr)
219+
if (!array_key_exists('addresses', $customerArr)
210220
&& null !== $prevCustomerDataArr
211221
&& array_key_exists('default_shipping', $prevCustomerDataArr)
212222
) {
@@ -371,15 +381,12 @@ public function deleteById($customerId)
371381
* Helper function that adds a FilterGroup to the collection.
372382
*
373383
* @deprecated 100.2.0
374-
* @param \Magento\Framework\Api\Search\FilterGroup $filterGroup
375-
* @param \Magento\Customer\Model\ResourceModel\Customer\Collection $collection
384+
* @param FilterGroup $filterGroup
385+
* @param Collection $collection
376386
* @return void
377-
* @throws \Magento\Framework\Exception\InputException
378387
*/
379-
protected function addFilterGroupToCollection(
380-
\Magento\Framework\Api\Search\FilterGroup $filterGroup,
381-
\Magento\Customer\Model\ResourceModel\Customer\Collection $collection
382-
) {
388+
protected function addFilterGroupToCollection(FilterGroup $filterGroup, Collection $collection)
389+
{
383390
$fields = [];
384391
foreach ($filterGroup->getFilters() as $filter) {
385392
$condition = $filter->getConditionType() ? $filter->getConditionType() : 'eq';

0 commit comments

Comments
 (0)