diff --git a/CHANGELOG.md b/CHANGELOG.md index 35b27a3b..07671937 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +## 2016-10-31 v.2.1.0 +* Добавлена передача адреса из карточки клиента в retailCRM +* Добавлено больше информации в журнале битрикса и дополнительное логирование +* Небольшие исправления + +## 2016-10-25 v.2.0.9 +* Исправлена ошибка с неверной кодировкой ФИО +* Исправлена ошибка с отсутствием местоположения + ## 2016-10-20 v.2.0.8 * Исправлена ошибка с отсутствием LID * Изменены методы для совместимости с ранними версиями sale 16 версии diff --git a/intaro.retailcrm/classes/general/RCrmActions.php b/intaro.retailcrm/classes/general/RCrmActions.php index c7bf2895..ac44d056 100644 --- a/intaro.retailcrm/classes/general/RCrmActions.php +++ b/intaro.retailcrm/classes/general/RCrmActions.php @@ -236,6 +236,12 @@ class RCrmActions case 'customersEdit': try { $result = $api->$methodApi($params, 'externalId', $site); + if (isset($result['errorMsg'])) { + self::eventLog(__CLASS__.'::'.$method, 'RetailCrm\ApiClient::'.$methodApi, $result['errorMsg']); + + $log = new Logger(); + $log->write(array($methodApi, $result['errorMsg'], $result['errors'], $params), 'apiErrors'); + } } catch (\RetailCrm\Exception\CurlException $e) { self::eventLog( __CLASS__.'::'.$method, 'RetailCrm\ApiClient::'.$methodApi.'::CurlException', @@ -256,6 +262,13 @@ class RCrmActions default: try { $result = $api->$methodApi($params, $site); + if (isset($result['errorMsg'])) { + if ($methodApi != 'customersUpload') { + self::eventLog(__CLASS__.'::'.$method, 'RetailCrm\ApiClient::'.$methodApi, $result['errorMsg']); + } + $log = new Logger(); + $log->write(array($methodApi, $result['errorMsg'], $result['errors'], $params), 'apiErrors'); + } } catch (\RetailCrm\Exception\CurlException $e) { self::eventLog( __CLASS__.'::'.$method, 'RetailCrm\ApiClient::'.$methodApi.'::CurlException', diff --git a/intaro.retailcrm/classes/general/RestNormalizer.php b/intaro.retailcrm/classes/general/RestNormalizer.php index 9444d779..0e751894 100644 --- a/intaro.retailcrm/classes/general/RestNormalizer.php +++ b/intaro.retailcrm/classes/general/RestNormalizer.php @@ -64,7 +64,7 @@ class RestNormalizer if (is_null($file) || is_file($file) === false || json_decode(file_get_contents($file)) === null || $this->parseConfig($file) === false) { - ICrmOrderActions::eventLog('RestNormalizer', 'intaro.retailcrm', 'Incorrect file normalize.'); + RCrmActions::eventLog('RestNormalizer', 'intaro.retailcrm', 'Incorrect file normalize.'); return false; } @@ -79,7 +79,7 @@ class RestNormalizer } if (!is_array($data) || count($data) < 1) { - ICrmOrderActions::eventLog('RestNormalizer', 'intaro.retailcrm', 'Incorrect data array.'); + RCrmActions::eventLog('RestNormalizer', 'intaro.retailcrm', 'Incorrect data array.'); return false; } @@ -123,7 +123,7 @@ class RestNormalizer if ($skip === false) { foreach ($this->validation as $code => $valid) { if (isset($valid['required']) && $valid['required'] === true && isset($formatted[ $code ]) === false) { - ICrmOrderActions::eventLog('RestNormalizer', 'intaro.retailcrm', "NOT VALID: $code"); + RCrmActions::eventLog('RestNormalizer', 'intaro.retailcrm', "NOT VALID: $code"); } } diff --git a/intaro.retailcrm/classes/general/history/RetailCrmHistory.php b/intaro.retailcrm/classes/general/history/RetailCrmHistory.php index 69908a07..f33c0dff 100644 --- a/intaro.retailcrm/classes/general/history/RetailCrmHistory.php +++ b/intaro.retailcrm/classes/general/history/RetailCrmHistory.php @@ -202,6 +202,12 @@ class RetailCrmHistory } } } + if (array_key_exists('index', $customer['address'])) { + $arUser["PERSONAL_ZIP"] = $customer['address']['index'] ? RCrmActions::fromJSON($customer['address']['index']) : ''; + } + if (array_key_exists('city', $customer['address'])) { + $arUser["PERSONAL_CITY"] = $customer['address']['city'] ? RCrmActions::fromJSON($customer['address']['city']) : ''; + } $u = $newUser->Update($customer['externalId'], $arUser); if (!$u) { @@ -539,10 +545,23 @@ class RetailCrmHistory foreach ($optionsOrderProps[$personType] as $key => $orderProp) { if (array_key_exists($key, $order)) { $somePropValue = $propertyCollection->getItemByOrderPropertyId($propsKey[$orderProp]['ID']); - self::setProp($somePropValue, RCrmActions::fromJSON($order[$key])); + if ($key == 'fio') { + self::setProp($somePropValue, $order[$key]); + } else { + self::setProp($somePropValue, RCrmActions::fromJSON($order[$key])); + } } elseif (array_key_exists($key, $order['delivery']['address'])) { - if ($propsKey[$key]['TYPE'] == 'LOCATION') { - $parameters['filter']['NAME'] = RCrmActions::fromJSON($order['delivery']['address'][$key]); + if ($propsKey[$orderProp]['TYPE'] == 'LOCATION') { + $parameters = array(); + $loc = explode('.', $order['delivery']['address'][$key]); + if (count($loc) == 1) { + $parameters['filter']['NAME'] = RCrmActions::fromJSON(trim($loc[0])); + } elseif (count($loc) == 2) { + $parameters['filter']['NAME'] = RCrmActions::fromJSON(trim($loc[1])); + } else{ + RCrmActions::eventLog('RetailCrmHistory::orderHistory', 'RetailCrmHistory::setProp', 'Error location ' . $order['delivery']['address'][$key] . ' not found add in order id=' . $order['externalId']); + continue; + } $parameters['filter']['LANGUAGE_ID'] = 'ru'; $location = \Bitrix\Sale\Location\LocationTable::getListFast($parameters)->fetch(); $somePropValue = $propertyCollection->getItemByOrderPropertyId($propsKey[$orderProp]['ID']); diff --git a/intaro.retailcrm/classes/general/order/RetailCrmOrder.php b/intaro.retailcrm/classes/general/order/RetailCrmOrder.php index ea239215..1fc441d7 100644 --- a/intaro.retailcrm/classes/general/order/RetailCrmOrder.php +++ b/intaro.retailcrm/classes/general/order/RetailCrmOrder.php @@ -297,7 +297,7 @@ class RetailCrmOrder 'PERSON_TYPE_ID' => $obOrder->getPersonTypeId(), 'CURRENCY' => $obOrder->getCurrency(), 'PAYMENTS' => $obOrder->getPaymentSystemId(), - 'PAYED' => $obOrder->isPaid(), + 'PAYED' => $obOrder->isPaid() ? 'Y' : 'N', 'DELIVERYS' => array(), 'PRICE_DELIVERY' => $obOrder->getDeliveryPrice(), 'PROPS' => $obOrder->getPropertyCollection()->getArray(), diff --git a/intaro.retailcrm/classes/general/user/RetailCrmUser.php b/intaro.retailcrm/classes/general/user/RetailCrmUser.php index 8b44479b..edf45290 100644 --- a/intaro.retailcrm/classes/general/user/RetailCrmUser.php +++ b/intaro.retailcrm/classes/general/user/RetailCrmUser.php @@ -8,7 +8,7 @@ class RetailCrmUser return false; } if (empty($arFields)) { - RCrmActions::eventLog('ICrmOrderActions::orderCreate', 'empty($arFields)', 'incorrect customer'); + RCrmActions::eventLog('RetailCrmUser::customerSend', 'empty($arFields)', 'incorrect customer'); return false; } @@ -17,6 +17,8 @@ class RetailCrmUser 'firstName' => $arFields['NAME'], 'lastName' => $arFields['LAST_NAME'], 'patronymic' => $arFields['SECOND_NAME'], + 'email' => $arFields['EMAIL'], + 'address' => array('city' => $arFields['PERSONAL_CITY'], 'text' => $arFields['PERSONAL_STREET'], 'index' => $arFields['PERSONAL_ZIP']), 'createdAt' => new \DateTime($arFields['DATE_REGISTER']), 'contragentType' => $contragentType ); @@ -54,7 +56,7 @@ class RetailCrmUser public static function customerEdit($arFields, $api, $optionsSitesList = array()){ if (empty($arFields)) { - RCrmActions::eventLog('RetailCrmUser::orderEdit', 'empty($arFields)', 'incorrect customer'); + RCrmActions::eventLog('RetailCrmUser::customerEdit', 'empty($arFields)', 'incorrect customer'); return false; } @@ -63,7 +65,8 @@ class RetailCrmUser 'firstName' => $arFields['NAME'], 'lastName' => $arFields['LAST_NAME'], 'patronymic' => $arFields['SECOND_NAME'], - 'email' => $arFields['EMAIL'] + 'email' => $arFields['EMAIL'], + 'address' => array('city' => $arFields['PERSONAL_CITY'], 'text' => $arFields['PERSONAL_STREET'], 'index' => $arFields['PERSONAL_ZIP']), ); if (isset($arFields['PERSONAL_PHONE'])) { $customer['phones'][]['number'] = $arFields['PERSONAL_PHONE']; diff --git a/intaro.retailcrm/description.ru b/intaro.retailcrm/description.ru index a7220437..9912f7c4 100644 --- a/intaro.retailcrm/description.ru +++ b/intaro.retailcrm/description.ru @@ -1,2 +1,3 @@ -- Исправлена ошибка с отсутствием LID -- Изменены методы для совместимости с ранними версиями sale 16 версии \ No newline at end of file +- Добавлена передача адреса из карточки клиента в retailCRM +- Добавлено больше информации в журнале битрикса и дополнительное логирование +- Небольшие исправления \ No newline at end of file diff --git a/intaro.retailcrm/install/index.php b/intaro.retailcrm/install/index.php index 8450c134..b4098a88 100644 --- a/intaro.retailcrm/install/index.php +++ b/intaro.retailcrm/install/index.php @@ -613,6 +613,13 @@ class intaro_retailcrm extends CModule $e->getCode() . ': ' . $e->getMessage() ); } + $delivTypes = array(); + foreach ($arResult['deliveryTypesList'] as $delivType) { + if ($delivType['active'] === true) { + $delivTypes[$delivType['code']] = $delivType; + } + } + $arResult['deliveryTypesList'] = $delivTypes; //bitrix personTypes $arResult['bitrixOrderTypesList'] = RCrmActions::OrderTypesList($arResult['arSites']); diff --git a/intaro.retailcrm/install/version.php b/intaro.retailcrm/install/version.php index b107c8e6..d2bdf6ef 100644 --- a/intaro.retailcrm/install/version.php +++ b/intaro.retailcrm/install/version.php @@ -1,6 +1,6 @@ "2.0.8", - "VERSION_DATE" => "2016-10-20 19:00:00" + "VERSION" => "2.1.0", + "VERSION_DATE" => "2016-10-31 17:00:00" ); diff --git a/intaro.retailcrm/lang/ru/install/step2.php b/intaro.retailcrm/lang/ru/install/step2.php index 7de0b50d..4bf61b19 100644 --- a/intaro.retailcrm/lang/ru/install/step2.php +++ b/intaro.retailcrm/lang/ru/install/step2.php @@ -13,7 +13,7 @@ $MESS ['CANCELED'] = 'Является флагом «Отменен»'; $MESS ['INFO_1'] = 'Задайте соответствие между справочниками 1C-Битрикс и справочниками retailCRM.'; $MESS ['INFO_2'] = 'В случае, если вы не нашли подходящих значений в справочниках retailCRM, вы можете внести их в разделе'; $MESS ['URL_1'] = 'Администрирование'; -$MESS ['INFO_3'] = 'После этого подгрузите новые значения, нажав кнопку «Обновить справочники»'; +$MESS ['INFO_3'] = 'После этого подгрузите новые значения обновив страницу';//, нажав кнопку «Обновить справочники»'; $MESS ['UPDATE_CATS'] = 'Обновить справочники'; $MESS ['MESS_5'] = 'Произошла ошибка сервера, обратитесь в Интаро Софт.'; $MESS ['DELIV_TYPES_EXPORT'] = 'Выгрузить список доставок из 1С-Битрикс'; diff --git a/intaro.retailcrm/options.php b/intaro.retailcrm/options.php index 2d344ef1..200f03ab 100644 --- a/intaro.retailcrm/options.php +++ b/intaro.retailcrm/options.php @@ -249,15 +249,15 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) { $orderDischarge = (int) htmlspecialchars(trim($_POST['order-discharge'])); if (($orderDischarge != $previousDischarge) && ($orderDischarge == 0)) { // remove depenedencies - UnRegisterModuleDependences("sale", "OnOrderNewSendEmail", $mid, "ICrmOrderEvent", "onSendOrderMail"); - UnRegisterModuleDependences("sale", "OnOrderUpdate", $mid, "ICrmOrderEvent", "onUpdateOrder"); - UnRegisterModuleDependences("sale", "OnBeforeOrderAdd", $mid, "ICrmOrderEvent", "onBeforeOrderAdd"); + UnRegisterModuleDependences("sale", "OnSaleOrderEntitySaved", $mid, "RetailCrmEvent", "orderSave"); + UnRegisterModuleDependences("sale", "OnOrderUpdate", $mid, "RetailCrmEvent", "onUpdateOrder"); + UnRegisterModuleDependences("sale", "OnSaleOrderEntityDelete", $mid, "RetailCrmEvent", "orderDelete"); } elseif (($orderDischarge != $previousDischarge) && ($orderDischarge == 1)) { // event dependencies - RegisterModuleDependences("sale", "OnOrderNewSendEmail", $mid, "ICrmOrderEvent", "onSendOrderMail"); - RegisterModuleDependences("sale", "OnOrderUpdate", $mid, "ICrmOrderEvent", "onUpdateOrder"); - RegisterModuleDependences("sale", "OnBeforeOrderAdd", $mid, "ICrmOrderEvent", "onBeforeOrderAdd"); + RegisterModuleDependences("sale", "OnSaleOrderEntitySaved", $mid, "RetailCrmEvent", "orderSave"); + RegisterModuleDependences("sale", "OnOrderUpdate", $mid, "RetailCrmEvent", "onUpdateOrder"); + RegisterModuleDependences("sale", "OnSaleOrderEntityDelete", $mid, "RetailCrmEvent", "orderDelete"); } $orderPropsArr = array(); @@ -343,6 +343,13 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) { $badKey = true; echo CAdminMessage::ShowMessage(GetMessage('ERR_403')); } + $delivTypes = array(); + foreach ($arResult['deliveryTypesList'] as $delivType) { + if ($delivType['active'] === true) { + $delivTypes[$delivType['code']] = $delivType; + } + } + $arResult['deliveryTypesList'] = $delivTypes; //bitrix orderTypesList -- personTypes $arResult['bitrixOrderTypesList'] = RCrmActions::OrderTypesList($arResult['arSites']);