From 54d4091f63d628bdf973f92fc8d5dffa3fc2e4c7 Mon Sep 17 00:00:00 2001 From: Sergey Date: Wed, 24 Oct 2018 16:15:28 +0300 Subject: [PATCH] v2.2.5 --- CHANGELOG.md | 10 +- VERSION | 2 +- retailcrm/lib/RetailcrmHistory.php | 1 + retailcrm/retailcrm.php | 154 ++++++++++++++++------------- tests/phpunit/RetailcrmTest.php | 6 ++ 5 files changed, 99 insertions(+), 74 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f5bf55a..f6160c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,11 +13,13 @@ ## v2.2.6 * Добавлена активация модуля в маркетплейсе retailCRM -## v2.2.5 -* Добавлена передача страны при создании заказа для пользователя и заказа -* Добавлен метод сохранения сущностей с обработкой исключений +## v.2.2.5 +* Добавлена передача страны при создании заказа для заказа и покупателя +* Добавлен метод для загрузки сущностей с перехватом исключений +* Для версии 1.7 добавлена передача адреса при заполнении его на стороне сайта. +* Получение адреса и телефона вынесено в отдельные методы. -## v2.2.4 +## v.2.2.4 * Добавлена установка дефолтной валюты для оплаты при получении истории * Добавлено получение суммы оплаты из заказа в CMS, если она не передается по истории diff --git a/VERSION b/VERSION index a6333e4..72d132f 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.2.9 +2.2.9 \ No newline at end of file diff --git a/retailcrm/lib/RetailcrmHistory.php b/retailcrm/lib/RetailcrmHistory.php index aa53a7d..7339e03 100644 --- a/retailcrm/lib/RetailcrmHistory.php +++ b/retailcrm/lib/RetailcrmHistory.php @@ -53,6 +53,7 @@ class RetailcrmHistory if (self::loadInCMS($customer, 'update') === false) { continue; } + } else { $customer = new Customer(); diff --git a/retailcrm/retailcrm.php b/retailcrm/retailcrm.php index e401a84..8f22be4 100644 --- a/retailcrm/retailcrm.php +++ b/retailcrm/retailcrm.php @@ -3,7 +3,11 @@ * @author Retail Driver LCC * @copyright RetailCRM * @license GPL +<<<<<<< 4dfc7b8d1acbf9bdc33ac6484f0d7f4171e774d6 * @version 2.2.9 +======= + * @version 2.2.5 +>>>>>>> v2.2.5 * @link https://retailcrm.ru * */ @@ -76,7 +80,8 @@ class RetailCRM extends Module $this->registerHook('actionPaymentConfirmation') && $this->registerHook('actionCustomerAccountAdd') && $this->registerHook('actionOrderEdited') && - ($this->use_new_hooks ? $this->registerHook('actionCustomerAccountUpdate') : true) + ($this->use_new_hooks ? $this->registerHook('actionCustomerAccountUpdate') : true) && + ($this->use_new_hooks ? $this->registerHook('actionValidateCustomerAddressForm') : true) ); } @@ -418,11 +423,26 @@ class RetailCRM extends Module $customerSend = array_merge($customerSend, $address['customer']); } + if (isset($params['cart'])){ + $address = $this->addressParse($params['cart']); + } + + $customerSend = array_merge($customerSend, $address['customer']); + $this->api->customersEdit($customerSend); return $customerSend; } + // this hook added in 1.7 + public function hookActionValidateCustomerAddressForm($params) + { + $customer = new Customer($params['cart']->id_customer); + $customerAddress = array('customer' => $customer, 'cart' => $params['cart']); + + return $this->hookActionCustomerAccountUpdate($customerAddress); + } + public function hookNewOrder($params) { return $this->hookActionOrderStatusPostUpdate($params); @@ -490,6 +510,68 @@ class RetailCRM extends Module return $order; } + private function addressParse($address) + { + $addressCollection = $address->getAddressCollection(); + $address = array_shift($addressCollection); + + 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); + $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']); + } + + $phonesArray = array('customer' => $customer, 'order' => $order); + + return $phonesArray; + } + public function hookActionOrderStatusPostUpdate($params) { $delivery = json_decode(Configuration::get('RETAILCRM_API_DELIVERY'), true); @@ -521,9 +603,11 @@ class RetailCRM extends Module } $cart = $params['cart']; + $addressCollection = $cart->getAddressCollection(); $address = array_shift($addressCollection); $address = $this->addressParse($address); + $customer = array_merge($customer, $address['customer']); $order = array_merge($order, $address['order']); $comment = $params['order']->getFirstMessage(); @@ -754,74 +838,6 @@ 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 c3cabb0..d3fd4d6 100644 --- a/tests/phpunit/RetailcrmTest.php +++ b/tests/phpunit/RetailcrmTest.php @@ -48,6 +48,7 @@ class RetailCRMTest extends RetailcrmTestCase public function testHookActionCustomerAccountUpdate() { $customer = new Customer(1); + $params = array('customer' => $customer); $customer = $this->retailcrmModule->hookActionCustomerAccountUpdate($params); @@ -125,6 +126,11 @@ class RetailCRMTest extends RetailcrmTestCase $this->assertArrayHasKey('lastName', $result); $this->assertArrayHasKey('email', $result); $this->assertArrayHasKey('delivery', $result); + $this->assertArrayHasKey('address', $result['delivery']); + $this->assertArrayHasKey('city', $result['delivery']['address']); + $this->assertArrayHasKey('text', $result['delivery']['address']); + $this->assertArrayHasKey('index', $result['delivery']['address']); + $this->assertArrayHasKey('countryIso', $result); $this->assertArrayHasKey('items', $result); $this->assertArrayHasKey('customer', $result); $this->assertArrayHasKey('externalId', $result['customer']);