From 75fc11c6f9613fbb9d69fece31b24b50997aa9be Mon Sep 17 00:00:00 2001 From: Yura Date: Wed, 25 Nov 2020 10:54:38 +0300 Subject: [PATCH] Closes #200 - Address fix --- .../admin/model/extension/retailcrm/history.php | 15 +++++++++++---- .../library/retailcrm/lib/history/Customer.php | 4 +++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/upload/admin/model/extension/retailcrm/history.php b/src/upload/admin/model/extension/retailcrm/history.php index a6bb026..f1a3083 100644 --- a/src/upload/admin/model/extension/retailcrm/history.php +++ b/src/upload/admin/model/extension/retailcrm/history.php @@ -315,10 +315,17 @@ class ModelExtensionRetailcrmHistory extends Model { $this->customers_history->handleCustomer($customer_data, $customer); $this->customers_history->handleCustomFields($customer_data, $customer); - $updateAddress = $this->customers_history->handleAddress($customer, array(), $customer_data['address_id']); - $addresses = $this->model_customer_customer->getAddresses($customer_id); - $addresses[$customer_data['address_id']] = $updateAddress; - $customer_data['address'] = $addresses; + if (empty($customer_data['address_id'])) { + $address = $this->customers_history->handleAddress($customer, array()); + $addresses = $this->model_customer_customer->getAddresses($customer_id); + $addresses[] = $address; + $customer_data['address'] = $addresses; + } else { + $updateAddress = $this->customers_history->handleAddress($customer, array(), $customer_data['address_id']); + $addresses = $this->model_customer_customer->getAddresses($customer_id); + $addresses[$customer_data['address_id']] = $updateAddress; + $customer_data['address'] = $addresses; + } $this->model_customer_customer->editCustomer($customer_id, $customer_data); } diff --git a/src/upload/system/library/retailcrm/lib/history/Customer.php b/src/upload/system/library/retailcrm/lib/history/Customer.php index 676e0ec..c6c786f 100644 --- a/src/upload/system/library/retailcrm/lib/history/Customer.php +++ b/src/upload/system/library/retailcrm/lib/history/Customer.php @@ -53,7 +53,9 @@ class Customer { if ($address_id) { $customer_address = $this->customer_repository->getAddress($address_id); } else { - $customer_address = array(); + $customer_address = array( + 'address_id' => '' + ); } if (isset($customer['address']['countryIso'])) {