From 55b76fd9c7a1e760442b5b7eb8e69d7d97174915 Mon Sep 17 00:00:00 2001 From: Grisha Pomadchin Date: Thu, 18 Jul 2013 22:55:52 +0400 Subject: [PATCH] updated api class; small bugfixes. --- .../classes/general/ICrmOrderActions.php | 24 +++---- intaro.intarocrm/classes/general/RestApi.php | 71 ++++++------------- intaro.intarocrm/include.php | 3 +- intaro.intarocrm/install/export/crm_run.php | 3 +- intaro.intarocrm/install/export/crm_setup.php | 3 +- intaro.intarocrm/install/index.php | 9 ++- intaro.intarocrm/install/step1.php | 2 +- intaro.intarocrm/install/step2.php | 4 +- intaro.intarocrm/install/unstep1.php | 2 +- intaro.intarocrm/install/version.php | 3 +- intaro.intarocrm/lang/ru/export_crm.php | 5 +- .../lang/ru/export_setup_templ.php | 5 +- intaro.intarocrm/lang/ru/options.php | 3 +- intaro.intarocrm/options.php | 2 +- 14 files changed, 53 insertions(+), 86 deletions(-) mode change 100755 => 100644 intaro.intarocrm/classes/general/RestApi.php diff --git a/intaro.intarocrm/classes/general/ICrmOrderActions.php b/intaro.intarocrm/classes/general/ICrmOrderActions.php index 1182c98f..c2a737c8 100755 --- a/intaro.intarocrm/classes/general/ICrmOrderActions.php +++ b/intaro.intarocrm/classes/general/ICrmOrderActions.php @@ -82,7 +82,7 @@ class ICrmOrderActions $api = new IntaroCrm\RestApi($api_host, $api_key); $arParams = array( - 'optionsOrderTypes' => $optionsOrderTypes, + 'optionsOrderTypes' => $optionsOrderTypes, 'optionsDelivTypes' => $optionsDelivTypes, 'optionsPayTypes' => $optionsPayTypes, 'optionsPayStatuses' => $optionsPayStatuses, @@ -104,21 +104,23 @@ class ICrmOrderActions $resOrders[] = $order; } - $orders = $api->orderUpload($resOrders); - - // error pushing orders - if(!$orders) { - //handle err - self::eventLog('ICrmOrderActions::uploadOrders', 'IntaroCrm\RestApi::orderUpload', $api->getLastError()); - return true; + if(!empty($resOrders)) { + $orders = $api->orderUpload($resOrders); + + // error pushing orders + if (!$orders) { + //handle err + self::eventLog('ICrmOrderActions::uploadOrders', 'IntaroCrm\RestApi::orderUpload', $api->getLastError()); + return true; + } } if($lastUpOrderIdNew) COption::SetOptionString(self::$MODULE_ID, self::$CRM_ORDER_LAST_ID, $lastUpOrderIdNew); - + return true; //all ok! } - + /** * * w+ event in bitrix log @@ -318,5 +320,3 @@ class ICrmOrderActions } } -?> - diff --git a/intaro.intarocrm/classes/general/RestApi.php b/intaro.intarocrm/classes/general/RestApi.php old mode 100755 new mode 100644 index 9900cebe..3d5d1023 --- a/intaro.intarocrm/classes/general/RestApi.php +++ b/intaro.intarocrm/classes/general/RestApi.php @@ -3,31 +3,6 @@ namespace IntaroCrm; class RestApi { - protected static $jsonReplaceSource = array( - '\u0410','\u0430','\u0411','\u0431','\u0412','\u0432','\u0413','\u0433', - '\u0414','\u0434','\u0415','\u0435','\u0401','\u0451','\u0416','\u0436', - '\u0417','\u0437','\u0418','\u0438','\u0419','\u0439','\u041a','\u043a', - '\u041b','\u043b','\u041c','\u043c','\u041d','\u043d','\u041e','\u043e', - '\u041f','\u043f','\u0420','\u0440','\u0421','\u0441','\u0422','\u0442', - '\u0423','\u0443','\u0424','\u0444','\u0425','\u0445','\u0426','\u0446', - '\u0427','\u0447','\u0428','\u0448','\u0429','\u0449','\u042a','\u044a', - '\u042b','\u044b','\u042c','\u044c','\u042d','\u044d','\u042e','\u044e', - '\u042f','\u044f' - ); - - protected static $jsonReplaceTarget = array( - 'А', 'а', 'Б', 'б', 'В', 'в', 'Г', 'г', - 'Д', 'д', 'Е', 'е', 'Ё', 'ё', 'Ж', 'ж', - 'З', 'з', 'И', 'и', 'Й', 'й', 'К', 'к', - 'Л', 'л', 'М', 'м', 'Н', 'н', 'О', 'о', - 'П', 'п', 'Р', 'р', 'С', 'с', 'Т', 'т', - 'У', 'у', 'Ф', 'ф', 'Х', 'х', 'Ц', 'ц', - 'Ч', 'ч', 'Ш', 'ш', 'Щ', 'щ', 'Ъ', 'ъ', - 'Ы', 'ы', 'Ь', 'ь', 'Э', 'э', 'Ю', 'ю', - 'Я', 'я' - ); - - protected $apiUrl; protected $apiKey; protected $apiVersion = '1'; @@ -95,8 +70,6 @@ class RestApi public function orderCreate($order) { $dataJson = json_encode($order); - $dataJson = str_replace(self::$jsonReplaceSource, self::$jsonReplaceTarget, - $dataJson); $this->parameters['order'] = $dataJson; $url = $this->apiUrl.'orders/create'; @@ -113,8 +86,6 @@ class RestApi public function orderEdit($order) { $dataJson = json_encode($order); - $dataJson = str_replace(self::$jsonReplaceSource, self::$jsonReplaceTarget, - $dataJson); $this->parameters['order'] = $dataJson; $url = $this->apiUrl.'orders/'.$order['externalId'].'/edit'; @@ -131,8 +102,6 @@ class RestApi public function orderUpload($orders) { $dataJson = json_encode($orders); - $dataJson = str_replace(self::$jsonReplaceSource, self::$jsonReplaceTarget, - $dataJson); $this->parameters['orders'] = $dataJson; $url = $this->apiUrl.'orders/upload'; @@ -140,6 +109,22 @@ class RestApi return $result; } + /** + * Обновление externalId у заказов с переданными id + * + * @param array $orders- массив, содержащий id и externalId заказа + * @return array + */ + public function orderFixExternalIds($order) + { + $dataJson = json_encode($order); + $this->parameters['orders'] = $dataJson; + + $url = $this->apiUrl.'orders/fix-external-ids'; + $result = $this->curlRequest($url, 'POST'); + return $result; + } + /** * Удаление заказа * @@ -147,6 +132,7 @@ class RestApi * @param string $by - поиск заказа по id или externalId * @return array */ + /* public function orderDelete($id, $by = 'externalId') { $url = $this->apiUrl.'orders/'.$id.'/delete'; @@ -154,7 +140,7 @@ class RestApi $this->parameters['by'] = $by; $result = $this->curlRequest($url, 'POST'); return $result; - } + }*/ /** * Получение последних измененных заказов @@ -204,8 +190,6 @@ class RestApi public function customerCreate($customer) { $dataJson = json_encode($customer); - $dataJson = str_replace(self::$jsonReplaceSource, self::$jsonReplaceTarget, - $dataJson); $this->parameters['customer'] = $dataJson; $url = $this->apiUrl.'customers/create'; @@ -222,8 +206,6 @@ class RestApi public function customerEdit($customer) { $dataJson = json_encode($customer); - $dataJson = str_replace(self::$jsonReplaceSource, self::$jsonReplaceTarget, - $dataJson); $this->parameters['customer'] = $dataJson; $url = $this->apiUrl.'customers/'.$customer['externalId'].'/edit'; @@ -238,6 +220,7 @@ class RestApi * @param string $by - поиск заказа по id или externalId * @return array */ + /* public function customerDelete($id, $by = 'externalId') { $url = $this->apiUrl.'customers/'.$id.'/delete'; @@ -245,7 +228,7 @@ class RestApi $this->parameters['by'] = $by; $result = $this->curlRequest($url, 'POST'); return $result; - } + }*/ /** * Получение списка заказов клиента @@ -295,8 +278,6 @@ class RestApi public function deliveryTypeEdit($deliveryType) { $dataJson = json_encode($deliveryType); - $dataJson = str_replace(self::$jsonReplaceSource, self::$jsonReplaceTarget, - $dataJson); $this->parameters['deliveryType'] = $dataJson; $url = $this->apiUrl.'delivery-types/'.$deliveryType['code'].'/edit'; @@ -326,8 +307,6 @@ class RestApi public function paymentTypesEdit($paymentType) { $dataJson = json_encode($paymentType); - $dataJson = str_replace(self::$jsonReplaceSource, self::$jsonReplaceTarget, - $dataJson); $this->parameters['paymentType'] = $dataJson; $url = $this->apiUrl.'payment-types/'.$paymentType['code'].'/edit'; @@ -357,8 +336,6 @@ class RestApi public function paymentStatusesEdit($paymentStatus) { $dataJson = json_encode($paymentStatus); - $dataJson = str_replace(self::$jsonReplaceSource, self::$jsonReplaceTarget, - $dataJson); $this->parameters['paymentStatus'] = $dataJson; $url = $this->apiUrl.'payment-statuses/'.$paymentStatus['code'].'/edit'; @@ -388,8 +365,6 @@ class RestApi public function orderTypesEdit($orderType) { $dataJson = json_encode($orderType); - $dataJson = str_replace(self::$jsonReplaceSource, self::$jsonReplaceTarget, - $dataJson); $this->parameters['orderType'] = $dataJson; $url = $this->apiUrl.'order-types/'.$orderType['code'].'/edit'; @@ -418,8 +393,6 @@ class RestApi public function orderStatusEdit($status) { $dataJson = json_encode($status); - $dataJson = str_replace(self::$jsonReplaceSource, self::$jsonReplaceTarget, - $dataJson); $this->parameters['status'] = $dataJson; $url = $this->apiUrl.'statuses/'.$status['code'].'/edit'; @@ -487,6 +460,4 @@ class RestApi return true; return reset($result); } -} - -?> \ No newline at end of file +} \ No newline at end of file diff --git a/intaro.intarocrm/include.php b/intaro.intarocrm/include.php index 79e60b6a..6623ad4b 100755 --- a/intaro.intarocrm/include.php +++ b/intaro.intarocrm/include.php @@ -6,5 +6,4 @@ CModule::AddAutoloadClasses( 'ICrmOrderActions' => 'classes/general/ICrmOrderActions.php', 'ICrmOrderEvent' => 'classes/general/events/ICrmOrderEvent.php' ) -); -?> +); \ No newline at end of file diff --git a/intaro.intarocrm/install/export/crm_run.php b/intaro.intarocrm/install/export/crm_run.php index c8f515a4..38b4fc47 100755 --- a/intaro.intarocrm/install/export/crm_run.php +++ b/intaro.intarocrm/install/export/crm_run.php @@ -1826,5 +1826,4 @@ if ($bTmpUserCreated) $USER = $USER_TMP; unset($USER_TMP); } -} -?> \ No newline at end of file +} \ No newline at end of file diff --git a/intaro.intarocrm/install/export/crm_setup.php b/intaro.intarocrm/install/export/crm_setup.php index 89f9f09c..7a986141 100755 --- a/intaro.intarocrm/install/export/crm_setup.php +++ b/intaro.intarocrm/install/export/crm_setup.php @@ -411,5 +411,4 @@ elseif ($STEP==2) $_REQUEST['SETUP_SERVER_NAME'] = htmlspecialcharsbx($_REQUEST['SETUP_SERVER_NAME']); $FINITE = true; -} -?> \ No newline at end of file +} \ No newline at end of file diff --git a/intaro.intarocrm/install/index.php b/intaro.intarocrm/install/index.php index 5240d329..4b4a9286 100755 --- a/intaro.intarocrm/install/index.php +++ b/intaro.intarocrm/install/index.php @@ -98,7 +98,11 @@ class intaro_intarocrm extends CModule ); return; - } + } + + // form correct url + $api_host = parse_url($api_host); + $api_host = $api_host['scheme'] . '://' . $api_host['host']; COption::SetOptionString($this->MODULE_ID, $this->CRM_API_HOST_OPTION, $api_host); COption::SetOptionString($this->MODULE_ID, $this->CRM_API_KEY_OPTION, $api_key); @@ -358,5 +362,4 @@ class intaro_intarocrm extends CModule unlink($_SERVER['DOCUMENT_ROOT'] . '/bitrix/php_interface/include/catalog_export/crm_run.php'); unlink($_SERVER['DOCUMENT_ROOT'] . '/bitrix/php_interface/include/catalog_export/crm_setup.php'); } -} -?> \ No newline at end of file +} \ No newline at end of file diff --git a/intaro.intarocrm/install/step1.php b/intaro.intarocrm/install/step1.php index 3d953994..e3e88e6f 100755 --- a/intaro.intarocrm/install/step1.php +++ b/intaro.intarocrm/install/step1.php @@ -43,4 +43,4 @@ - + \ No newline at end of file diff --git a/intaro.intarocrm/install/step2.php b/intaro.intarocrm/install/step2.php index d400dbdf..77f99dd0 100755 --- a/intaro.intarocrm/install/step2.php +++ b/intaro.intarocrm/install/step2.php @@ -25,7 +25,7 @@ $defaultPayTypes = array ( $defaultPayStatuses = array ( 'N' => 'in-processing', - 'P' => 'in-processing', + 'P' => 'approval', 'F' => 'complete' ); @@ -169,4 +169,4 @@ $defaultPayment = array( - + \ No newline at end of file diff --git a/intaro.intarocrm/install/unstep1.php b/intaro.intarocrm/install/unstep1.php index 0c643a80..617f3988 100755 --- a/intaro.intarocrm/install/unstep1.php +++ b/intaro.intarocrm/install/unstep1.php @@ -5,4 +5,4 @@
"> -
+ \ No newline at end of file diff --git a/intaro.intarocrm/install/version.php b/intaro.intarocrm/install/version.php index 363065c5..9323a3bd 100755 --- a/intaro.intarocrm/install/version.php +++ b/intaro.intarocrm/install/version.php @@ -2,5 +2,4 @@ $arModuleVersion = array( 'VERSION' => '0.4.4', 'VERSION_DATE' => '2013-07-16 14:41:00', -); -?> +); \ No newline at end of file diff --git a/intaro.intarocrm/lang/ru/export_crm.php b/intaro.intarocrm/lang/ru/export_crm.php index 1f623b2f..1d7584ba 100644 --- a/intaro.intarocrm/lang/ru/export_crm.php +++ b/intaro.intarocrm/lang/ru/export_crm.php @@ -1,4 +1,4 @@ - \ No newline at end of file +$MESS["CES_ERROR_BAD_EXPORT_FILENAME"] = "Имя файла экспорта содержит запрещенные символы"; \ No newline at end of file diff --git a/intaro.intarocrm/lang/ru/export_setup_templ.php b/intaro.intarocrm/lang/ru/export_setup_templ.php index dae1fd5e..91f43fbc 100644 --- a/intaro.intarocrm/lang/ru/export_setup_templ.php +++ b/intaro.intarocrm/lang/ru/export_setup_templ.php @@ -1,4 +1,4 @@ - \ No newline at end of file +$MESS["CATI_FI_PRICE_CURRENCY"] = "в валюте #CURRENCY#"; \ No newline at end of file diff --git a/intaro.intarocrm/lang/ru/options.php b/intaro.intarocrm/lang/ru/options.php index 9c639de5..fa64e193 100755 --- a/intaro.intarocrm/lang/ru/options.php +++ b/intaro.intarocrm/lang/ru/options.php @@ -20,5 +20,4 @@ $MESS ['ICRM_OPTIONS_SUBMIT_VALUE'] = 'Сохранить'; $MESS ['ERR_404'] = 'Возможно не верно введен адрес CRM.'; $MESS ['ERR_403'] = 'Не верный apiKey.'; $MESS ['ERR_0'] = 'Превышено время ожидания ответа от сервера.'; -$MESS ['ICRM_OPTIONS_OK'] = 'Изменения успешно сохранены.'; -?> +$MESS ['ICRM_OPTIONS_OK'] = 'Изменения успешно сохранены.'; \ No newline at end of file diff --git a/intaro.intarocrm/options.php b/intaro.intarocrm/options.php index b5da9cd8..965260cf 100755 --- a/intaro.intarocrm/options.php +++ b/intaro.intarocrm/options.php @@ -383,4 +383,4 @@ if (isset($_POST['Update']) && $_POST['Update']=='Y') { End(); ?> - + \ No newline at end of file