From a8cbda785e6f0f731aab7fd4a14312b8205cbfb0 Mon Sep 17 00:00:00 2001 From: Sergey Date: Wed, 24 Oct 2018 17:15:55 +0300 Subject: [PATCH] v2.2.5 --- CHANGELOG.md | 4 +++ VERSION | 2 +- retailcrm/lib/RetailcrmHistory.php | 49 ++++++++++++++++++++++-------- retailcrm/retailcrm.php | 6 ++++ 4 files changed, 48 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8cfc42f..9105c58 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## v.2.2.5 +* Добавлена передача страны при создании заказа для пользователя и заказа +* Добавлен метод сохранения сущностей с обработкой исключений + ## v.2.2.4 * Добавлена установка дефолтной валюты для оплаты при получении истории * Добавлено получение суммы оплаты из заказа в CMS, если она не передается по истории diff --git a/VERSION b/VERSION index 0476155..21bb5e1 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.2.4 \ No newline at end of file +2.2.5 diff --git a/retailcrm/lib/RetailcrmHistory.php b/retailcrm/lib/RetailcrmHistory.php index 39605d2..60b327c 100644 --- a/retailcrm/lib/RetailcrmHistory.php +++ b/retailcrm/lib/RetailcrmHistory.php @@ -50,17 +50,10 @@ class RetailcrmHistory $customer->email = $customerHistory['email']; } - try { - $customer->update(); - } catch (PrestaShopException $e) { - error_log( - '[' . date('Y-m-d H:i:s') . '] customerHistory: ' . $e->getMessage() . ' customer externalId '. $customerHistory['externalId'] . "\n", - 3, - _PS_ROOT_DIR_ . '/retailcrm.log' - ); - + if (self::loadInCMS($customer, 'update') === false){ continue; } + } else { $customer = new Customer(); @@ -84,7 +77,9 @@ class RetailcrmHistory $customer->passwd = Tools::substr(str_shuffle(Tools::strtolower(sha1(rand() . time()))), 0, 5); - $customer->add(); + if (self::loadInCMS($customer, 'add') === false) { + continue; + } if (isset($customerHistory['address'])) { $customerAddress = new Address(); @@ -114,7 +109,10 @@ class RetailcrmHistory $customerAddress->postcode = $customerHistory['address']['index']; } - $customerAddress->add(); + if (self::loadInCMS($customerAddress, 'add') === false) { + continue; + } + } $customerFix[] = array( @@ -281,7 +279,9 @@ class RetailcrmHistory md5($order['customer']['firstName']) . '@retailcrm.ru'; $customer->passwd = Tools::substr(str_shuffle(Tools::strtolower(sha1(rand() . time()))), 0, 5); - $customer->add(); + if (self::loadInCMS($customer, 'add') === false) { + continue; + } array_push( $customerFix, @@ -809,4 +809,29 @@ class RetailcrmHistory AND product_attribute_id = ' . $product_attribute_id ); } + + /** + * load and catch exception + * + * @param $object + * @param $action + * + * @return boolean + */ + private static function loadInCMS($object, $action) + { + try { + $object->$action(); + } catch (PrestaShopException $e) { + error_log( + '[' . date('Y-m-d H:i:s') . '] History:loadInCMS ' . $e->getMessage() . "\n", + 3, + _PS_ROOT_DIR_ . '/retailcrm.log' + ); + + return false; + } + + return true; + } } diff --git a/retailcrm/retailcrm.php b/retailcrm/retailcrm.php index 3779cdf..6a6761a 100644 --- a/retailcrm/retailcrm.php +++ b/retailcrm/retailcrm.php @@ -502,6 +502,7 @@ class RetailCRM extends Module $postcode = $address->postcode; $city = $address->city; $addres_line = sprintf("%s %s", $address->address1, $address->address2); + $countryIso = CountryCore::getIsoById($address->id_country); } if (!empty($postcode)) { @@ -519,6 +520,11 @@ class RetailCRM extends Module $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(