/** * {@inheritdoc} */ public function updateCustomer(Data\CustomerDetails $customerDetails) { $customer = $customerDetails->getCustomer(); // Making this call first will ensure the customer already exists. $this->customerRegistry->retrieve($customer->getId()); $this->saveCustomer($customer, $this->converter->getCustomerModel($customer->getId())->getPasswordHash()); $addresses = $customerDetails->getAddresses(); // If $address is null, no changes must made to the list of addresses // be careful $addresses != null would be true of $addresses is an empty array if ($addresses !== null) { $existingAddresses = $this->customerAddressService->getAddresses($customer->getId()); /** @var Data\Address[] $deletedAddresses */ $deletedAddresses = array_udiff($existingAddresses, $addresses, function (Data\Address $existing, Data\Address $replacement) { return $existing->getId() - $replacement->getId(); }); // If $addresses is an empty array, all addresses are removed. // array_udiff would return the entire $existing array foreach ($deletedAddresses as $address) { $this->customerAddressService->deleteAddress($address->getId()); } $this->customerAddressService->saveAddresses($customer->getId(), $addresses); } return true; }