diff --git a/CHANGELOG.md b/CHANGELOG.md index 978528e..2a83da2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## v.2.2.7 +* Добавлена отправка адреса клиента при обновлении покупателя на стороне сайта +* Добавлены методы получения адреса и телефона + ## v.2.2.6 * Добавлена активация модуля в маркетплейсе retailCRM diff --git a/VERSION b/VERSION index bda8fbe..5bc1cc4 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.2.6 +2.2.7 diff --git a/retailcrm/retailcrm.php b/retailcrm/retailcrm.php index 076a3bd..f8b45d3 100644 --- a/retailcrm/retailcrm.php +++ b/retailcrm/retailcrm.php @@ -394,6 +394,7 @@ class RetailCRM extends Module public function hookActionCustomerAccountUpdate($params) { $customer = $params['customer']; + $customerSend = array( 'externalId' => $customer->id, 'firstName' => $customer->firstname, @@ -402,6 +403,21 @@ class RetailCRM extends Module 'birthday' => $customer->birthday ); + $addreses = $customer->getAddresses($this->default_lang); + $address = array_shift($addreses); + + if (!empty($address)){ + + if (is_object($address)) { + $address = $this->addressParse($address); + } else { + $address = new Address($address['id_address']); + $address = $this->addressParse($address); + } + + $customerSend = array_merge($customerSend, $address['customer']); + } + $this->api->customersEdit($customerSend); return $customerSend; @@ -507,53 +523,9 @@ class RetailCRM extends Module $cart = $params['cart']; $addressCollection = $cart->getAddressCollection(); $address = array_shift($addressCollection); - - if ($address instanceof Address) { - $additionalPhone = !empty($address->phone) ? $address->phone : ''; - $phone = !empty($address->phone_mobile) ? $address->phone_mobile : ''; - $postcode = $address->postcode; - $city = $address->city; - $addres_line = sprintf("%s %s", $address->address1, $address->address2); - $countryIso = CountryCore::getIsoById($address->id_country); - } - - if (!empty($postcode)) { - $customer['address']['index'] = $postcode; - $order['delivery']['address']['index'] = $postcode; - } - - if (!empty($city)) { - $customer['address']['city'] = $city; - $order['delivery']['address']['city'] = $city; - } - - if (!empty($addres_line)) { - $customer['address']['text'] = $addres_line; - $order['delivery']['address']['text'] = $addres_line; - } - - if (!empty($countryIso)) { - $order['countryIso'] = $countryIso; - $customer['address']['countryIso'] = $countryIso; - } - - if (!empty($phone) && !empty($additionalPhone)) { - $customer['phones'] = array( - array( - 'number' => $phone - ), - array( - 'number' => $additionalPhone - ) - ); - - $order['phone'] = $phone; - $order['additionalPhone'] = $additionalPhone; - } else { - $order['phone'] = !empty($phone) ? $phone : $additionalPhone; - $customer['phones'][] = array('number' => $order['phone']); - } - + $address = $this->addressParse($address); + $customer = array_merge($customer, $address['customer']); + $order = array_merge($order, $address['order']); $comment = $params['order']->getFirstMessage(); if ($comment !== false) { @@ -782,6 +754,74 @@ class RetailCRM extends Module return $output; } + private function addressParse($address) + { + + if ($address instanceof Address) { + $postcode = $address->postcode; + $city = $address->city; + $addres_line = sprintf("%s %s", $address->address1, $address->address2); + $countryIso = CountryCore::getIsoById($address->id_country); + } + + if (!empty($postcode)) { + $customer['address']['index'] = $postcode; + $order['delivery']['address']['index'] = $postcode; + } + + if (!empty($city)) { + $customer['address']['city'] = $city; + $order['delivery']['address']['city'] = $city; + } + + if (!empty($addres_line)) { + $customer['address']['text'] = $addres_line; + $order['delivery']['address']['text'] = $addres_line; + } + + if (!empty($countryIso)) { + $order['countryIso'] = $countryIso; + $customer['address']['countryIso'] = $countryIso; + } + + $phones = $this->getPhone($address); + + if ($phones !== false) { + $order = array_merge($order, $phones['order']); + $customer = array_merge($customer, $phones['customer']); + } + + $addressArray = array('order' => $order, 'customer' => $customer); + + return $addressArray; + } + + private function getPhone($address) + { + if (!empty($address->phone_mobile)){ + $order['phone'] = $address->phone_mobile; + $customer['phones'][] = array('number'=> $address->phone_mobile); + } + + if (!empty($address->phone)){ + $order['additionalPhone'] = $address->phone; + $customer['phones'][] = array('number'=> $address->phone); + } + + if (!isset($order['phone']) && !empty($order['additionalPhone'])){ + $order['phone'] = $order['additionalPhone']; + unset($order['additionalPhone']); + } + if (!empty($customer) && !empty($order)) { + $phonesArray = array('customer' => $customer, 'order' => $order); + + return $phonesArray; + } else { + + return false; + } + } + /** * Activate/deactivate module in marketplace retailCRM * diff --git a/tests/phpunit/RetailcrmTest.php b/tests/phpunit/RetailcrmTest.php index 9b83f86..c3cabb0 100644 --- a/tests/phpunit/RetailcrmTest.php +++ b/tests/phpunit/RetailcrmTest.php @@ -57,6 +57,11 @@ class RetailCRMTest extends RetailcrmTestCase $this->assertArrayHasKey('lastName', $customer); $this->assertArrayHasKey('email', $customer); $this->assertArrayHasKey('birthday', $customer); + $this->assertArrayHasKey('address', $customer); + $this->assertArrayHasKey('index', $customer['address']); + $this->assertArrayHasKey('city', $customer['address']); + $this->assertArrayHasKey('text', $customer['address']); + $this->assertArrayHasKey('countryIso', $customer['address']); } public function testHookActionOrderEdited()