This commit is contained in:
Sergey 2018-10-24 17:15:55 +03:00
parent fc76adb944
commit a8cbda785e
4 changed files with 48 additions and 13 deletions

View File

@ -1,3 +1,7 @@
## v.2.2.5
* Добавлена передача страны при создании заказа для пользователя и заказа
* Добавлен метод сохранения сущностей с обработкой исключений
## v.2.2.4
* Добавлена установка дефолтной валюты для оплаты при получении истории
* Добавлено получение суммы оплаты из заказа в CMS, если она не передается по истории

View File

@ -1 +1 @@
2.2.4
2.2.5

View File

@ -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;
}
}

View File

@ -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(