1
0
mirror of synced 2024-11-25 06:46:08 +03:00

Changed api class, added opt fields, gen fixes.

This commit is contained in:
Grisha Pomadchin 2013-07-08 15:08:14 +04:00
parent ef13d4a277
commit 212d922ab3
8 changed files with 696 additions and 169 deletions

View File

@ -0,0 +1,441 @@
<?php
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';
protected $lastError;
protected $statusCode;
/**
* @param string $crmUrl - адрес CRM
* @param string $apiKey - ключ для работы с api
*/
public function __construct($crmUrl, $apiKey)
{
$this->apiUrl = $crmUrl.'/api/v'.$this->apiVersion.'/';
$this->apiKey = $apiKey;
}
public function getStatusCode()
{
return $this->statusCode;
}
/* Получение кода статуса и сообщения об ошибке */
public function getLastError()
{
if (!is_null($this->lastError))
return $this->statusCode . ' ' . $this->lastError;
else
return null;
}
/* Псообщения об ошибке */
public function getLastErrorMessage()
{
return $this->lastError;
}
/* Методы для работы с заказами */
/**
* Получение заказа по id
*
* @param string $id - идентификатор заказа
* @return array - информация о заказе
*/
public function orderGet($id)
{
$url = $this->apiUrl.'orders/'.$id;
$result = $this->curlRequest($url);
return $result;
}
/**
* Создание заказа
*
* @param array $order- информация о заказе
* @return array
*/
public function orderCreate($order)
{
$dataJson = json_encode($order);
$dataJson = str_replace(self::$jsonReplaceSource, self::$jsonReplaceTarget,
$dataJson);
$parameters = array();
$parameters['order'] = $dataJson;
$url = $this->apiUrl.'orders/create';
$result = $this->curlRequest($url, $parameters, 'POST');
return $result;
}
/**
* Изменение заказа
*
* @param array $order- информация о заказе
* @return array
*/
public function orderEdit($order)
{
$dataJson = json_encode($order);
$dataJson = str_replace(self::$jsonReplaceSource, self::$jsonReplaceTarget,
$dataJson);
$parameters = array();
$parameters['order'] = $dataJson;
$url = $this->apiUrl.'orders/'.$order['id'].'/edit';
$result = $this->curlRequest($url, $parameters, 'POST');
return $result;
}
/**
* Загрузка нескольких заказов
*
* @param array $orders - массив заказов
* @return array
*/
public function orderUpload($orders)
{
$dataJson = json_encode($orders);
$dataJson = str_replace(self::$jsonReplaceSource, self::$jsonReplaceTarget,
$dataJson);
$parameters = array();
$parameters['orders'] = $dataJson;
$url = $this->apiUrl.'orders/upload';
$result = $this->curlRequest($url, $parameters, 'POST');
return $result;
}
/**
* Удаление заказа
*
* @param string $id - идентификатор заказа
* @return array
*/
public function orderDelete($id)
{
$url = $this->apiUrl.'orders/'.$id.'/delete';
$result = $this->curlRequest($url, array(), 'POST');
return $result;
}
/**
* Получение последних измененных заказов
*
* @param DateTime $startDate - начальная дата выборки
* @param DateTime $endDate - конечная дата
* @param int $limit - ограничение на размер выборки
* @param int $offset - сдвиг
* @return array - массив заказов
*/
public function orderHistory($startDate = null, $endDate = null, $limit = 100, $offset = 0)
{
$url = $this->apiUrl.'orders/history';
$parameters = array();
$parameters['startDate'] = $startDate;
$parameters['endDate'] = $endDate;
$parameters['limit'] = $limit;
$parameters['offset'] = $offset;
$result = $this->curlRequest($url, $parameters);
return $result;
}
/* Методы для работы с клиентами */
/**
* Получение клиента по id
*
* @param string $id - идентификатор
* @return array - информация о клиенте
*/
public function customerGet($id)
{
$url = $this->apiUrl.'customers/'.$id;
$result = $this->curlRequest($url);
return $result;
}
/**
* Создание клиента
*
* @param array $customer - информация о клиенте
* @return array
*/
public function customerCreate($customer)
{
$dataJson = json_encode($customer);
$dataJson = str_replace(self::$jsonReplaceSource, self::$jsonReplaceTarget,
$dataJson);
$parameters = array();
$parameters['customer'] = $dataJson;
$url = $this->apiUrl.'customers/create';
$result = $this->curlRequest($url, $parameters, 'POST');
return $result;
}
/**
* Редактирование клиента
*
* @param array $customer - информация о клиенте
* @return array
*/
public function customerEdit($customer)
{
$dataJson = json_encode($customer);
$dataJson = str_replace(self::$jsonReplaceSource, self::$jsonReplaceTarget,
$dataJson);
$parameters = array();
$parameters['customer'] = $dataJson;
$url = $this->apiUrl.'customers/'.$customer['id'].'/edit';
$result = $this->curlRequest($url, $parameters, 'POST');
return $result;
}
/**
* Удаление клиента
*
* @param string $id - идентификатор
* @return array
*/
public function customerDelete($id)
{
$url = $this->apiUrl.'customers/'.$id.'/delete';
$result = $this->curlRequest($url, array(), 'POST');
return $result;
}
/**
* Получение списка заказов клиента
*
* @param string $id - идентификатор клиента
* @param DateTime $startDate - начальная дата выборки
* @param DateTime $endDate - конечная дата
* @param int $limit - ограничение на размер выборки
* @param int $offset - сдвиг
* @return array - массив заказов
*/
public function customerOrdersList($id, $startDate = null, $endDate = null,
$limit = 100, $offset = 0)
{
$url = $this->apiUrl.'customers/'.$id.'/orders';
$parameters = array();
$parameters['startDate'] = $startDate;
$parameters['endDate'] = $endDate;
$parameters['limit'] = $limit;
$parameters['offset'] = $offset;
$result = $this->curlRequest($url, $parameters);
return $result;
}
/* Методы для работы со справочниками */
/**
* Получение списка типов доставки
*
* @return array - массив типов доставки
*/
public function deliveryTypesList()
{
$url = $this->apiUrl.'reference/delivery-types';
$result = $this->curlRequest($url);
return $result;
}
/**
* Редактирование типа доставки
*
* @param array $deliveryType - информация о типе доставки
* @return array
*/
public function deliveryTypeEdit($deliveryType)
{
$dataJson = json_encode($deliveryType);
$dataJson = str_replace(self::$jsonReplaceSource, self::$jsonReplaceTarget,
$dataJson);
$parameters = array();
$parameters['deliveryType'] = $dataJson;
$url = $this->apiUrl.'delivery-types/'.$deliveryType['code'].'/edit';
$result = $this->curlRequest($url, $parameters, 'POST');
return $result;
}
/**
* Получение списка типов оплаты
*
* @return array - массив типов оплаты
*/
public function paymentTypesList()
{
$url = $this->apiUrl.'reference/payment-types';
$result = $this->curlRequest($url);
return $result;
}
/**
* Редактирование типа оплаты
*
* @param array $paymentType - информация о типе оплаты
* @return array
*/
public function paymentTypesEdit($paymentType)
{
$dataJson = json_encode($paymentType);
$dataJson = str_replace(self::$jsonReplaceSource, self::$jsonReplaceTarget,
$dataJson);
$parameters = array();
$parameters['paymentType'] = $dataJson;
$url = $this->apiUrl.'payment-types/'.$paymentType['code'].'/edit';
$result = $this->curlRequest($url, $parameters, 'POST');
return $result;
}
/**
* Получение списка статусов оплаты
*
* @return array - массив статусов оплаты
*/
public function paymentStatusesList()
{
$url = $this->apiUrl.'reference/payment-statuses';
$result = $this->curlRequest($url);
return $result;
}
/**
* Редактирование статуса оплаты
*
* @param array $paymentStatus - информация о статусе оплаты
* @return array
*/
public function paymentStatusesEdit($paymentStatus)
{
$dataJson = json_encode($paymentStatus);
$dataJson = str_replace(self::$jsonReplaceSource, self::$jsonReplaceTarget,
$dataJson);
$parameters = array();
$parameters['paymentStatus'] = $dataJson;
$url = $this->apiUrl.'payment-statuses/'.$paymentStatus['code'].'/edit';
$result = $this->curlRequest($url, $parameters, 'POST');
return $result;
}
/**
* Получение списка типов заказа
*
* @return array - массив типов заказа
*/
public function orderTypesList()
{
$url = $this->apiUrl.'reference/order-types';
$result = $this->curlRequest($url);
return $result;
}
/**
* Редактирование типа заказа
*
* @param array $paymentType - информация о типе заказа
* @return array
*/
public function orderTypesEdit($orderType)
{
$dataJson = json_encode($orderType);
$dataJson = str_replace(self::$jsonReplaceSource, self::$jsonReplaceTarget,
$dataJson);
$parameters = array();
$parameters['orderType'] = $dataJson;
$url = $this->apiUrl.'order-types/'.$paymentType['code'].'/edit';
$result = $this->curlRequest($url, $parameters, 'POST');
return $result;
}
protected function curlRequest($url, $parameters = null, $method = 'GET', $format = 'json')
{
$parameters['apiKey'] = $this->apiKey;
if ($method == 'GET' && !is_null($parameters))
$url .= '?'.http_build_query($parameters);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FAILONERROR, FALSE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // return into a variable
curl_setopt($ch, CURLOPT_TIMEOUT, 3); // times out after 3s
if ($method == 'POST')
{
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $parameters);
}
$response = curl_exec($ch);
$this->statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if (curl_errno($ch))
{
$this->lastError = 'Curl error: ' . curl_error($ch);
return null;
}
curl_close($ch);
$result = (array)json_decode($response, true);
if ($result['success'] == false)
{
$this->lastError = $result['errorMsg'];
return null;
}
$this->lastError = null;
unset($result['success']);
if (count($result) == 0)
return true;
return reset($result);
}
}
?>

View File

@ -2,8 +2,7 @@
CModule::AddAutoloadClasses( CModule::AddAutoloadClasses(
'intaro.crm', // module name 'intaro.crm', // module name
array ( array (
'IntaroCrmRestApi' => 'classes/general/IntaroCrmRestApi.php', 'IntaroCrm\RestApi' => 'classes/general/RestApi.php'
'ICrmApi' => 'classes/general/ICrmApi.php'
) )
); );
?> ?>

View File

@ -28,6 +28,8 @@ class intaro_crm extends CModule
var $CRM_DELIVERY_TYPES_ARR = 'deliv_types_arr'; var $CRM_DELIVERY_TYPES_ARR = 'deliv_types_arr';
var $CRM_PAYMENT_TYPES = 'pay_types_arr'; var $CRM_PAYMENT_TYPES = 'pay_types_arr';
var $CRM_PAYMENT_STATUSES = 'pay_statuses_arr'; var $CRM_PAYMENT_STATUSES = 'pay_statuses_arr';
var $CRM_PAYMENT = 'payment_arr'; //order payment Y/N
var $INSTALL_PATH; var $INSTALL_PATH;
@ -55,7 +57,7 @@ class intaro_crm extends CModule
{ {
global $APPLICATION, $step, $arResult; global $APPLICATION, $step, $arResult;
include($this->INSTALL_PATH . '/../classes/general/ICrmApi.php'); include($this->INSTALL_PATH . '/../classes/general/RestApi.php');
$step = intval($_REQUEST['step']); $step = intval($_REQUEST['step']);
@ -81,7 +83,7 @@ class intaro_crm extends CModule
return; return;
} }
$this->INTARO_CRM_API = new ICrmApi($api_host, $api_key); $this->INTARO_CRM_API = new \IntaroCrm\RestApi($api_host, $api_key);
$this->INTARO_CRM_API->paymentStatusesList(); $this->INTARO_CRM_API->paymentStatusesList();
@ -104,7 +106,8 @@ class intaro_crm extends CModule
$arResult['orderTypesList'] = $this->INTARO_CRM_API->orderTypesList(); $arResult['orderTypesList'] = $this->INTARO_CRM_API->orderTypesList();
$arResult['deliveryTypesList'] = $this->INTARO_CRM_API->deliveryTypesList(); $arResult['deliveryTypesList'] = $this->INTARO_CRM_API->deliveryTypesList();
$arResult['paymentTypesList'] = $this->INTARO_CRM_API->paymentTypesList(); $arResult['paymentTypesList'] = $this->INTARO_CRM_API->paymentTypesList();
$arResult['paymentStatusesList'] = $this->INTARO_CRM_API->paymentStatusesList(); $arResult['paymentStatusesList'] = $this->INTARO_CRM_API->paymentStatusesList(); // --statuses
//$arResult['payment'] = $this->INTARO_CRM_API->getPymentsList() -- not exist
//bitrix orderTypesList -- personTypes //bitrix orderTypesList -- personTypes
$dbOrderTypesList = CSalePersonType::GetList( $dbOrderTypesList = CSalePersonType::GetList(
@ -163,7 +166,7 @@ class intaro_crm extends CModule
} while ($arPaymentTypesList = $dbPaymentTypesList->Fetch()); } while ($arPaymentTypesList = $dbPaymentTypesList->Fetch());
} }
//bitrix paymentStatusesList //bitrix paymentStatusesList --statuses
$dbPaymentStatusesList = CSaleStatus::GetList( $dbPaymentStatusesList = CSaleStatus::GetList(
array( array(
"SORT" => "ASC", "SORT" => "ASC",
@ -209,7 +212,7 @@ class intaro_crm extends CModule
$orderTypesArr = array(); $orderTypesArr = array();
if ($arOrderTypesList = $dbOrderTypesList->Fetch()) { if ($arOrderTypesList = $dbOrderTypesList->Fetch()) {
do { do {
$orderTypesArr[$arOrderTypesList['ID']] = $_POST['order-type-' . $arOrderTypesList['ID']]; $orderTypesArr[$arOrderTypesList['ID']] = htmlspecialchars(trim($_POST['order-type-' . $arOrderTypesList['ID']]));
} while ($arOrderTypesList = $dbOrderTypesList->Fetch()); } while ($arOrderTypesList = $dbOrderTypesList->Fetch());
} }
@ -231,7 +234,7 @@ class intaro_crm extends CModule
$deliveryTypesArr = array(); $deliveryTypesArr = array();
if ($arDeliveryTypesList = $dbDeliveryTypesList->Fetch()) { if ($arDeliveryTypesList = $dbDeliveryTypesList->Fetch()) {
do { do {
$deliveryTypesArr[$arDeliveryTypesList['ID']] = $_POST['delivery-type-' . $arDeliveryTypesList['ID']]; $deliveryTypesArr[$arDeliveryTypesList['ID']] = htmlspecialchars(trim($_POST['delivery-type-' . $arDeliveryTypesList['ID']]));
} while ($arDeliveryTypesList = $dbDeliveryTypesList->Fetch()); } while ($arDeliveryTypesList = $dbDeliveryTypesList->Fetch());
} }
@ -250,7 +253,7 @@ class intaro_crm extends CModule
$paymentTypesArr = array(); $paymentTypesArr = array();
if ($arPaymentTypesList = $dbPaymentTypesList->Fetch()) { if ($arPaymentTypesList = $dbPaymentTypesList->Fetch()) {
do { do {
$paymentTypesArr[$arPaymentTypesList['ID']] = $_POST['payment-type-' . $arPaymentTypesList['ID']]; $paymentTypesArr[$arPaymentTypesList['ID']] = htmlspecialchars(trim($_POST['payment-type-' . $arPaymentTypesList['ID']]));
} while ($arPaymentTypesList = $dbPaymentTypesList->Fetch()); } while ($arPaymentTypesList = $dbPaymentTypesList->Fetch());
} }
@ -270,14 +273,20 @@ class intaro_crm extends CModule
$paymentStatusesArr = array(); $paymentStatusesArr = array();
if ($arPaymentStatusesList = $dbPaymentStatusesList->Fetch()) { if ($arPaymentStatusesList = $dbPaymentStatusesList->Fetch()) {
do { do {
$paymentStatusesArr[$arPaymentStatusesList['ID']] = $_POST['payment-status-' . $arPaymentStatusesList['ID']]; $paymentStatusesArr[$arPaymentStatusesList['ID']] = htmlspecialchars(trim($_POST['payment-status-' . $arPaymentStatusesList['ID']]));
} while ($arPaymentStatusesList = $dbPaymentStatusesList->Fetch()); } while ($arPaymentStatusesList = $dbPaymentStatusesList->Fetch());
} }
//form payment ids arr
$paymentArr = array();
$paymentArr['Y'] = htmlspecialchars(trim($_POST['payment-Y']));
$paymentArr['N'] = htmlspecialchars(trim($_POST['payment-N']));
COption::SetOptionString($this->MODULE_ID, $this->CRM_ORDER_TYPES_ARR, serialize($orderTypesArr)); COption::SetOptionString($this->MODULE_ID, $this->CRM_ORDER_TYPES_ARR, serialize($orderTypesArr));
COption::SetOptionString($this->MODULE_ID, $this->CRM_DELIVERY_TYPES_ARR, serialize($deliveryTypesArr)); COption::SetOptionString($this->MODULE_ID, $this->CRM_DELIVERY_TYPES_ARR, serialize($deliveryTypesArr));
COption::SetOptionString($this->MODULE_ID, $this->CRM_PAYMENT_TYPES, serialize($paymentTypesArr)); COption::SetOptionString($this->MODULE_ID, $this->CRM_PAYMENT_TYPES, serialize($paymentTypesArr));
COption::SetOptionString($this->MODULE_ID, $this->CRM_PAYMENT_STATUSES, serialize($paymentStatusesArr)); COption::SetOptionString($this->MODULE_ID, $this->CRM_PAYMENT_STATUSES, serialize($paymentStatusesArr));
COption::SetOptionString($this->MODULE_ID, $this->CRM_PAYMENT, serialize($paymentArr));
RegisterModule($this->MODULE_ID); RegisterModule($this->MODULE_ID);
$APPLICATION->IncludeAdminFile( $APPLICATION->IncludeAdminFile(
@ -297,6 +306,7 @@ class intaro_crm extends CModule
COption::RemoveOption($this->MODULE_ID, $this->CRM_DELIVERY_TYPES_ARR); COption::RemoveOption($this->MODULE_ID, $this->CRM_DELIVERY_TYPES_ARR);
COption::RemoveOption($this->MODULE_ID, $this->CRM_PAYMENT_TYPES); COption::RemoveOption($this->MODULE_ID, $this->CRM_PAYMENT_TYPES);
COption::RemoveOption($this->MODULE_ID, $this->CRM_PAYMENT_STATUSES); COption::RemoveOption($this->MODULE_ID, $this->CRM_PAYMENT_STATUSES);
COption::RemoveOption($this->MODULE_ID, $this->CRM_PAYMENT);
$APPLICATION->IncludeAdminFile( $APPLICATION->IncludeAdminFile(
GetMessage('MODULE_UNINSTALL_TITLE'), GetMessage('MODULE_UNINSTALL_TITLE'),

View File

@ -1,4 +1,12 @@
<?php IncludeModuleLangFile(__FILE__); ?> <?php
IncludeModuleLangFile(__FILE__);
//bitrix pyament Y/N
$arResult['bitrixPaymentList'][0]['NAME'] = GetMessage('PAYMENT_Y');
$arResult['bitrixPaymentList'][0]['ID'] = 'Y';
$arResult['bitrixPaymentList'][1]['NAME'] = GetMessage('PAYMENT_N');
$arResult['bitrixPaymentList'][1]['ID'] = 'N';
?>
<div class="adm-detail-content-item-block"> <div class="adm-detail-content-item-block">
<form action="<?php echo $APPLICATION->GetCurPage() ?>" method="POST"> <form action="<?php echo $APPLICATION->GetCurPage() ?>" method="POST">
@ -63,6 +71,26 @@
</td> </td>
<td width="50%" class="adm-detail-content-cell-r"> <td width="50%" class="adm-detail-content-cell-r">
<select name="payment-status-<?php echo $bitrixPaymentStatus['ID']; ?>" class="typeselect"> <select name="payment-status-<?php echo $bitrixPaymentStatus['ID']; ?>" class="typeselect">
<option value="" selected=""></option>
<?php foreach($arResult['paymentList'] as $payment): ?>
<option value="<?php echo $payment['code']; ?>">
<?php echo $APPLICATION->ConvertCharset($payment['name'], 'utf-8', SITE_CHARSET); ?>
</option>
<?php endforeach; ?>
</select>
</td>
</tr>
<?php endforeach; ?>
<tr class="heading">
<td colspan="2"><b><?php echo GetMessage('PAYMENT_LIST'); ?></b></td>
</tr>
<?php foreach($arResult['bitrixPaymentList'] as $bitrixPayment): ?>
<tr>
<td width="50%" class="adm-detail-content-cell-l" name="<?php echo $bitrixPayment['ID']; ?>">
<?php echo $bitrixPayment['NAME']; ?>
</td>
<td width="50%" class="adm-detail-content-cell-r">
<select name="payment-<?php echo $bitrixPayment['ID']; ?>" class="typeselect">
<option value="" selected=""></option> <option value="" selected=""></option>
<?php foreach($arResult['paymentStatusesList'] as $paymentStatus): ?> <?php foreach($arResult['paymentStatusesList'] as $paymentStatus): ?>
<option value="<?php echo $paymentStatus['code']; ?>"> <option value="<?php echo $paymentStatus['code']; ?>">

View File

@ -1,6 +1,6 @@
<? <?
$arModuleVersion = array( $arModuleVersion = array(
'VERSION' => '0.2a', 'VERSION' => '0.2a',
'VERSION_DATE' => '2013-07-05 21:08:00', 'VERSION_DATE' => '2013-07-08 15:04:00',
); );
?> ?>

View File

@ -3,6 +3,9 @@ $MESS ['STEP_NAME'] = 'Шаг 2';
$MESS ['MOD_NEXT_STEP'] = 'Следующий шаг'; $MESS ['MOD_NEXT_STEP'] = 'Следующий шаг';
$MESS ['DELIVERY_TYPES_LIST'] = 'Способы доставки'; $MESS ['DELIVERY_TYPES_LIST'] = 'Способы доставки';
$MESS ['PAYMENT_TYPES_LIST'] = 'Способы оплаты'; $MESS ['PAYMENT_TYPES_LIST'] = 'Способы оплаты';
$MESS ['PAYMENT_STATUS_LIST'] = 'Статусы оплаты'; $MESS ['PAYMENT_STATUS_LIST'] = 'Статусы';
$MESS ['ORDER_TYPES_LIST'] = 'Типы плательщиков'; $MESS ['ORDER_TYPES_LIST'] = 'Типы заказа';
$MESS ['PAYMENT_LIST'] = 'Оплата';
$MESS ['PAYMENT_Y'] = 'Оплачен';
$MESS ['PAYMENT_N'] = 'Не оплачен';
?> ?>

View File

@ -5,10 +5,14 @@ $MESS ['ICRM_CONN_SETTINGS'] = 'Настройка соединения';
$MESS ['ICRM_API_HOST'] = 'Адрес Intaro CRM:'; $MESS ['ICRM_API_HOST'] = 'Адрес Intaro CRM:';
$MESS ['ICRM_API_KEY'] = 'Ключ авторизации:'; $MESS ['ICRM_API_KEY'] = 'Ключ авторизации:';
$MESS ['ICRM_OPTIONS_CATALOG_TAB'] = 'Настройка каталогов'; $MESS ['ICRM_OPTIONS_CATALOG_TAB'] = 'Настройка справочников';
$MESS ['DELIVERY_TYPES_LIST'] = 'Способы доставки'; $MESS ['DELIVERY_TYPES_LIST'] = 'Способы доставки';
$MESS ['PAYMENT_TYPES_LIST'] = 'Способы оплаты'; $MESS ['PAYMENT_TYPES_LIST'] = 'Способы оплаты';
$MESS ['PAYMENT_STATUS_LIST'] = 'Статусы оплаты'; $MESS ['PAYMENT_STATUS_LIST'] = 'Статусы';
$MESS ['ORDER_TYPES_LIST'] = 'Типы заказа';
$MESS ['PAYMENT_LIST'] = 'Оплата';
$MESS ['PAYMENT_Y'] = 'Оплачен';
$MESS ['PAYMENT_N'] = 'Не оплачен';
$MESS ['ICRM_OPTIONS_SUBMIT_TITLE'] = 'Сохранить настройки'; $MESS ['ICRM_OPTIONS_SUBMIT_TITLE'] = 'Сохранить настройки';
$MESS ['ICRM_OPTIONS_SUBMIT_VALUE'] = 'Сохранить'; $MESS ['ICRM_OPTIONS_SUBMIT_VALUE'] = 'Сохранить';

View File

@ -3,6 +3,14 @@ IncludeModuleLangFile(__FILE__);
$mid = 'intaro.crm'; $mid = 'intaro.crm';
$uri = $APPLICATION->GetCurPage() . '?mid=' . htmlspecialchars($mid) . '&lang=' . LANGUAGE_ID; $uri = $APPLICATION->GetCurPage() . '?mid=' . htmlspecialchars($mid) . '&lang=' . LANGUAGE_ID;
$CRM_API_HOST_OPTION = 'api_host';
$CRM_API_KEY_OPTION = 'api_key';
$CRM_ORDER_TYPES_ARR = 'order_types_arr';
$CRM_DELIVERY_TYPES_ARR = 'deliv_types_arr';
$CRM_PAYMENT_TYPES = 'pay_types_arr';
$CRM_PAYMENT_STATUSES = 'pay_statuses_arr';
$CRM_PAYMENT = 'payment_arr'; //order payment Y/N
CModule::IncludeModule('intaro.crm'); CModule::IncludeModule('intaro.crm');
CModule::IncludeModule('sale'); CModule::IncludeModule('sale');
@ -20,7 +28,7 @@ if (isset($_POST['Update']) && $_POST['Update']=='Y') {
$api_key = htmlspecialchars(trim($_POST['api_key'])); $api_key = htmlspecialchars(trim($_POST['api_key']));
if($api_host && $api_key) { if($api_host && $api_key) {
$api = new ICrmApi($api_host, $api_key); $api = new IntaroCrm\RestApi($api_host, $api_key);
$api->paymentStatusesList(); $api->paymentStatusesList();
@ -74,7 +82,7 @@ if (isset($_POST['Update']) && $_POST['Update']=='Y') {
$deliveryTypesArr = array(); $deliveryTypesArr = array();
if ($arDeliveryTypesList = $dbDeliveryTypesList->Fetch()) { if ($arDeliveryTypesList = $dbDeliveryTypesList->Fetch()) {
do { do {
$deliveryTypesArr[$arDeliveryTypesList['ID']] = $_POST['delivery-type-' . $arDeliveryTypesList['ID']]; $deliveryTypesArr[$arDeliveryTypesList['ID']] = htmlspecialchars(trim($_POST['delivery-type-' . $arDeliveryTypesList['ID']]));
} while ($arDeliveryTypesList = $dbDeliveryTypesList->Fetch()); } while ($arDeliveryTypesList = $dbDeliveryTypesList->Fetch());
} }
@ -93,7 +101,7 @@ if (isset($_POST['Update']) && $_POST['Update']=='Y') {
$paymentTypesArr = array(); $paymentTypesArr = array();
if ($arPaymentTypesList = $dbPaymentTypesList->Fetch()) { if ($arPaymentTypesList = $dbPaymentTypesList->Fetch()) {
do { do {
$paymentTypesArr[$arPaymentTypesList['ID']] = $_POST['payment-type-' . $arPaymentTypesList['ID']]; $paymentTypesArr[$arPaymentTypesList['ID']] = htmlspecialchars(trim($_POST['payment-type-' . $arPaymentTypesList['ID']]));
} while ($arPaymentTypesList = $dbPaymentTypesList->Fetch()); } while ($arPaymentTypesList = $dbPaymentTypesList->Fetch());
} }
@ -113,14 +121,20 @@ if (isset($_POST['Update']) && $_POST['Update']=='Y') {
$paymentStatusesArr = array(); $paymentStatusesArr = array();
if ($arPaymentStatusesList = $dbPaymentStatusesList->Fetch()) { if ($arPaymentStatusesList = $dbPaymentStatusesList->Fetch()) {
do { do {
$paymentStatusesArr[$arPaymentStatusesList['ID']] = $_POST['payment-status-' . $arPaymentStatusesList['ID']]; $paymentStatusesArr[$arPaymentStatusesList['ID']] = htmlspecialchars(trim($_POST['payment-status-' . $arPaymentStatusesList['ID']]));
} while ($arPaymentStatusesList = $dbPaymentStatusesList->Fetch()); } while ($arPaymentStatusesList = $dbPaymentStatusesList->Fetch());
} }
COption::SetOptionString($mid, 'order_types_arr', serialize($orderTypesArr)); //form payment ids arr
COption::SetOptionString($mid, 'deliv_types_arr', serialize($deliveryTypesArr)); $paymentArr = array();
COption::SetOptionString($mid, 'pay_types_arr', serialize($paymentTypesArr)); $paymentArr['Y'] = htmlspecialchars(trim($_POST['payment-Y']));
COption::SetOptionString($mid, 'pay_statuses_arr', serialize($paymentStatusesArr)); $paymentArr['N'] = htmlspecialchars(trim($_POST['payment-N']));
COption::SetOptionString($mid, $CRM_ORDER_TYPES_ARR, serialize($orderTypesArr));
COption::SetOptionString($mid, $CRM_DELIVERY_TYPES_ARR, serialize($deliveryTypesArr));
COption::SetOptionString($mid, $CRM_PAYMENT_TYPES, serialize($paymentTypesArr));
COption::SetOptionString($mid, $CRM_PAYMENT_STATUSES, serialize($paymentStatusesArr));
COption::SetOptionString($mid, $CRM_PAYMENT, serialize($paymentArr));
$uri .= '&ok=Y'; $uri .= '&ok=Y';
LocalRedirect($uri); LocalRedirect($uri);
@ -128,13 +142,14 @@ if (isset($_POST['Update']) && $_POST['Update']=='Y') {
$api_host = COption::GetOptionString($mid, 'api_host', 0); $api_host = COption::GetOptionString($mid, 'api_host', 0);
$api_key = COption::GetOptionString($mid, 'api_key', 0); $api_key = COption::GetOptionString($mid, 'api_key', 0);
$api = new ICrmApi($api_host, $api_key); $api = new IntaroCrm\RestApi($api_host, $api_key);
//prepare crm lists //prepare crm lists
$arResult['orderTypesList'] = $api->orderTypesList(); $arResult['orderTypesList'] = $api->orderTypesList();
$arResult['deliveryTypesList'] = $api->deliveryTypesList(); $arResult['deliveryTypesList'] = $api->deliveryTypesList();
$arResult['paymentTypesList'] = $api->paymentTypesList(); $arResult['paymentTypesList'] = $api->paymentTypesList();
$arResult['paymentStatusesList'] = $api->paymentStatusesList(); $arResult['paymentStatusesList'] = $api->paymentStatusesList(); // --statuses
//$arResult['payment'] = $this->INTARO_CRM_API->getPymentsList() -- not exist
//bitrix orderTypesList -- personTypes //bitrix orderTypesList -- personTypes
$dbOrderTypesList = CSalePersonType::GetList( $dbOrderTypesList = CSalePersonType::GetList(
@ -211,11 +226,18 @@ if (isset($_POST['Update']) && $_POST['Update']=='Y') {
} while ($arPaymentStatusesList = $dbPaymentStatusesList->Fetch()); } while ($arPaymentStatusesList = $dbPaymentStatusesList->Fetch());
} }
//bitrix pyament Y/N
$arResult['bitrixPaymentList'][0]['NAME'] = GetMessage('PAYMENT_Y');
$arResult['bitrixPaymentList'][0]['ID'] = 'Y';
$arResult['bitrixPaymentList'][1]['NAME'] = GetMessage('PAYMENT_N');
$arResult['bitrixPaymentList'][1]['ID'] = 'N';
//saved cat params //saved cat params
$optionsOrderTypes = unserialize(COption::GetOptionString($mid, 'order_types_arr', 0)); $optionsOrderTypes = unserialize(COption::GetOptionString($mid, $CRM_ORDER_TYPES_ARR, 0));
$optionsDelivTypes = unserialize(COption::GetOptionString($mid, 'deliv_types_arr', 0)); $optionsDelivTypes = unserialize(COption::GetOptionString($mid, $CRM_DELIVERY_TYPES_ARR, 0));
$optionsPayTypes = unserialize(COption::GetOptionString($mid, 'pay_types_arr', 0)); $optionsPayTypes = unserialize(COption::GetOptionString($mid, $CRM_PAYMENT_TYPES, 0));
$optionsPayStatuses = unserialize(COption::GetOptionString($mid, 'pay_statuses_arr', 0)); $optionsPayStatuses = unserialize(COption::GetOptionString($mid, $CRM_PAYMENT_STATUSES, 0)); // --statuses
$optionsPayment = unserialize(COption::GetOptionString($mid, $CRM_PAYMENT, 0));
$aTabs = array( $aTabs = array(
array( array(
@ -303,9 +325,29 @@ if (isset($_POST['Update']) && $_POST['Update']=='Y') {
</td> </td>
<td width="50%" class="adm-detail-content-cell-r"> <td width="50%" class="adm-detail-content-cell-r">
<select name="payment-status-<?php echo $bitrixPaymentStatus['ID']; ?>" class="typeselect"> <select name="payment-status-<?php echo $bitrixPaymentStatus['ID']; ?>" class="typeselect">
<option value="" selected=""></option> <option value=""></option>
<?php foreach($arResult['paymentList'] as $payment): ?>
<option value="<?php echo $payment['code']; ?>" <?php if ($optionsPayStatuses[$bitrixPaymentStatus['ID']] == $payment['code']) echo 'selected'; ?>>
<?php echo $APPLICATION->ConvertCharset($payment['name'], 'utf-8', SITE_CHARSET); ?>
</option>
<?php endforeach; ?>
</select>
</td>
</tr>
<?php endforeach; ?>
<tr class="heading">
<td colspan="2"><b><?php echo GetMessage('PAYMENT_LIST'); ?></b></td>
</tr>
<?php foreach($arResult['bitrixPaymentList'] as $bitrixPayment): ?>
<tr>
<td width="50%" class="adm-detail-content-cell-l" name="<?php echo $bitrixPayment['ID']; ?>">
<?php echo $bitrixPayment['NAME']; ?>
</td>
<td width="50%" class="adm-detail-content-cell-r">
<select name="payment-<?php echo $bitrixPayment['ID']; ?>" class="typeselect">
<option value=""></option>
<?php foreach($arResult['paymentStatusesList'] as $paymentStatus): ?> <?php foreach($arResult['paymentStatusesList'] as $paymentStatus): ?>
<option value="<?php echo $paymentStatus['code']; ?>" <?php if ($optionsPayStatuses[$bitrixPaymentStatus['ID']] == $paymentStatus['code']) echo 'selected'; ?>> <option value="<?php echo $paymentStatus['code']; ?>" <?php if ($optionsPayment[$bitrixPayment['ID']] == $paymentStatus['code']) echo 'selected'; ?>>
<?php echo $APPLICATION->ConvertCharset($paymentStatus['name'], 'utf-8', SITE_CHARSET); ?> <?php echo $APPLICATION->ConvertCharset($paymentStatus['name'], 'utf-8', SITE_CHARSET); ?>
</option> </option>
<?php endforeach; ?> <?php endforeach; ?>