Skip to content

Commit 616f082

Browse files
move to new method
1 parent b0b6dc9 commit 616f082

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ public function __construct(
196196
* @throws \Magento\Framework\Exception\LocalizedException
197197
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
198198
* @SuppressWarnings(PHPMD.NPathComplexity)
199-
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
200199
*/
201200
public function save(CustomerInterface $customer, $passwordHash = null)
202201
{
@@ -281,10 +280,7 @@ public function save(CustomerInterface $customer, $passwordHash = null)
281280
$savedAddressIds[] = $address->getId();
282281
}
283282
}
284-
$addressIdsToDelete = array_diff($existingAddressIds, $savedAddressIds);
285-
foreach ($addressIdsToDelete as $addressId) {
286-
$this->addressRepository->deleteById($addressId);
287-
}
283+
$this->deleteAddressesByIds(array_diff($existingAddressIds, $savedAddressIds));
288284
}
289285
$this->customerRegistry->remove($customerId);
290286
$savedCustomer = $this->get($customer->getEmail(), $customer->getWebsiteId());
@@ -299,6 +295,19 @@ public function save(CustomerInterface $customer, $passwordHash = null)
299295
return $savedCustomer;
300296
}
301297

298+
/**
299+
* Delete addresses by ids
300+
*
301+
* @param array $addressIds
302+
* @return void
303+
*/
304+
private function deleteAddressesByIds(array $addressIds): void
305+
{
306+
foreach ($addressIds as $id) {
307+
$this->addressRepository->deleteById($id);
308+
}
309+
}
310+
302311
/**
303312
* Validate customer group id if exist
304313
*

0 commit comments

Comments
 (0)