1
0
mirror of synced 2024-11-22 05:16:09 +03:00

updated api class; small bugfixes.

This commit is contained in:
Grisha Pomadchin 2013-07-18 22:55:52 +04:00
parent 3d5a00ca6a
commit 55b76fd9c7
14 changed files with 53 additions and 86 deletions

View File

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

71
intaro.intarocrm/classes/general/RestApi.php Executable file → Normal file
View File

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

View File

@ -6,5 +6,4 @@ CModule::AddAutoloadClasses(
'ICrmOrderActions' => 'classes/general/ICrmOrderActions.php',
'ICrmOrderEvent' => 'classes/general/events/ICrmOrderEvent.php'
)
);
?>
);

View File

@ -1826,5 +1826,4 @@ if ($bTmpUserCreated)
$USER = $USER_TMP;
unset($USER_TMP);
}
}
?>
}

View File

@ -411,5 +411,4 @@ elseif ($STEP==2)
$_REQUEST['SETUP_SERVER_NAME'] = htmlspecialcharsbx($_REQUEST['SETUP_SERVER_NAME']);
$FINITE = true;
}
?>
}

View File

@ -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');
}
}
?>
}

View File

@ -43,4 +43,4 @@
</div>
</div>
</form>
</div>
</div>

View File

@ -25,7 +25,7 @@ $defaultPayTypes = array (
$defaultPayStatuses = array (
'N' => 'in-processing',
'P' => 'in-processing',
'P' => 'approval',
'F' => 'complete'
);
@ -169,4 +169,4 @@ $defaultPayment = array(
</div>
</div>
</form>
</div>
</div>

View File

@ -5,4 +5,4 @@
<form action="<?echo $APPLICATION->GetCurPage()?>">
<input type="hidden" name="lang" value="<?echo LANG?>">
<input type="submit" name="" value="<?echo GetMessage("MOD_BACK")?>">
</form>
</form>

View File

@ -2,5 +2,4 @@
$arModuleVersion = array(
'VERSION' => '0.4.4',
'VERSION_DATE' => '2013-07-16 14:41:00',
);
?>
);

View File

@ -1,4 +1,4 @@
<?
<?php
$MESS["YANDEX_DETAIL_TITLE"] = "Настройка дополнительных параметров";
$MESS["YANDEX_ERR_NO_ACCESS_EXPORT"] = "Нет доступа к управлению экспортом";
$MESS["YANDEX_ERR_NO_IBLOCK_CHOSEN"] = "Не выбран инфоблок";
@ -106,5 +106,4 @@ $MESS["YANDEX_ERR_BAD_OFFERS_IBLOCK_ID"] = "Неверный ID инфоблок
$MESS["YANDEX_ERR_SKU_SETTINGS_ABSENT"] = "Отсутствуют настройки экспорта торговых предложений";
$MESS["YANDEX_ROOT_DIRECTORY"] = "Основной раздел каталога";
$MESS["CET_ERROR_IBLOCK_PERM"] = "Недостаточно прав для работы с инфоблоком ##IBLOCK_ID#";
$MESS["CES_ERROR_BAD_EXPORT_FILENAME"] = "Имя файла экспорта содержит запрещенные символы";
?>
$MESS["CES_ERROR_BAD_EXPORT_FILENAME"] = "Имя файла экспорта содержит запрещенные символы";

View File

@ -1,4 +1,4 @@
<?
<?php
$MESS["CET_ERROR_NO_NAME"] = "Введите название профиля выгрузки.";
$MESS["CET_STEP1"] = "Шаг";
$MESS["CET_STEP2"] = "из";
@ -121,5 +121,4 @@ $MESS["CAT_ADM_CSV_EXP_DESCR_SECT_PROP"] = "Пользовательское с
$MESS["CAT_ADM_CSV_EXP_SECTION_LEVEL"] = "Раздел уровня #LEVEL#";
$MESS["CATI_FI_PRICE_TYPE2"] = "Цена типа \"#TYPE#\"";
$MESS["CATI_FI_PRICE_TYPE3"] = "Цена типа \"#NAME#\" (#TYPE#)";
$MESS["CATI_FI_PRICE_CURRENCY"] = "в валюте #CURRENCY#";
?>
$MESS["CATI_FI_PRICE_CURRENCY"] = "в валюте #CURRENCY#";

View File

@ -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'] = 'Изменения успешно сохранены.';

View File

@ -383,4 +383,4 @@ if (isset($_POST['Update']) && $_POST['Update']=='Y') {
<?php $tabControl->End(); ?>
</form>
<?php } ?>
<?php } ?>