1
0
mirror of synced 2024-11-24 14:26:08 +03:00

Merge remote-tracking branch 'refs/remotes/origin/master'

This commit is contained in:
m.korolev 2013-07-10 17:00:54 +04:00
commit 4166e448f5
9 changed files with 691 additions and 234 deletions

View File

@ -0,0 +1,292 @@
<?php
//namespace IntaroCrm;
class ICrmOrderActions
{
protected static $MODULE_ID = 'intaro.crm';
protected static $CRM_API_HOST_OPTION = 'api_host';
protected static $CRM_API_KEY_OPTION = 'api_key';
protected static $CRM_ORDER_TYPES_ARR = 'order_types_arr';
protected static $CRM_DELIVERY_TYPES_ARR = 'deliv_types_arr';
protected static $CRM_PAYMENT_TYPES = 'pay_types_arr';
protected static $CRM_PAYMENT_STATUSES = 'pay_statuses_arr';
protected static $CRM_PAYMENT = 'payment_arr'; //order payment Y/N
protected static $CRM_ORDER_LAST_ID = 'order_last_id';
/**
*
* @global type $APPLICATION
* @param type $str in SITE_CHARSET
* @return type $str in utf-8
*/
protected static function toJSON($str) {
global $APPLICATION;
return $APPLICATION->ConvertCharset($str, SITE_CHARSET, 'utf-8');
}
/**
*
* @global type $APPLICATION
* @param type $str in utf-8
* @return type $str in SITE_CHARSET
*/
public static function fromJSON($str) {
global $APPLICATION;
return $APPLICATION->ConvertCharset($str, 'utf-8', SITE_CHARSET);
}
/**
* Mass order uploading func
*/
public static function uploadOrders() {
//COption::SetOptionString(self::$MODULE_ID, self::$CRM_ORDER_LAST_ID, 0); // -- for test
if (!CModule::IncludeModule('iblock')) {
//handle err
self::eventLog('iblock', 'module not found');
return false;
}
if (!CModule::IncludeModule("sale")) {
//handle err
self::eventLog('sale', 'module not found');
return false;
}
if (!CModule::IncludeModule("catalog")) {
//handle err
self::eventLog('catalog', 'module not found');
return false;
}
$resOrders = array();
$dbOrder = CSaleOrder::GetList();
$lastUpOrderId = COption::GetOptionString(self::$MODULE_ID, self::$CRM_ORDER_LAST_ID, 0);
$lastUpOrderIdNew = 0;
$api_host = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_HOST_OPTION, 0);
$api_key = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_KEY_OPTION, 0);
//saved cat params
$optionsOrderTypes = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_ORDER_TYPES_ARR, 0));
$optionsDelivTypes = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_DELIVERY_TYPES_ARR, 0));
$optionsPayTypes = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT_TYPES, 0));
$optionsPayStatuses = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT_STATUSES, 0)); // --statuses
$optionsPayment = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT, 0));
$api = new IntaroCrm\RestApi($api_host, $api_key);
while ($arOrder = $dbOrder->GetNext()) {
if ($arOrder['ID'] <= $lastUpOrderId) //old orders not to upload
return true;
if(!$lastUpOrderIdNew)
$lastUpOrderIdNew = $arOrder['ID'];
$arFields = CSaleOrder::GetById($arOrder['ID']);
if (empty($arFields)) {
//handle err
self::eventLog('empty($arFields)', 'incorrect order');
return false;
}
$rsUser = CUser::GetByID($arFields['USER_ID']);
$arUser = $rsUser->Fetch();
// push customer (for crm)
$firstName = self::toJSON($arUser['NAME']);
$lastName = self::toJSON($arUser['LAST_NAME']);
$patronymic = self::toJSON($arUser['SECOND_NAME']);
$phonePersonal = array(
'number' => self::toJSON($arUser['PERSONAL_PHONE']),
'type' => 'mobile'
);
$phones[] = $phonePersonal;
$phoneWork = array(
'number' => self::toJSON($arUser['WORK_PHONE']),
'type' => 'work'
);
$phones[] = $phoneWork;
$addressPersonal = array(
'index' => self::toJSON($arUser['PERSONAL_ZIP']),
'country' => self::toJSON(GetCountryByID($arUser['PERSONAL_COUNTRY'])),
'city' => self::toJSON($arUser['PERSONAL_CITY']),
'street' => self::toJSON($arUser['PERSONAL_STREET']),
'building' => self::toJSON($arUser['UF_PERSONAL_BUILDING']),
'flat' => self::toJSON($arUser['UF_PERSONAL_FLAT']),
'notes' => self::toJSON($arUser['PERSONAL_NOTES']),
'text' => self::toJSON($arUser['UF_PERSONAL_TEXT']),
'type' => 'home'
);
$addresses[] = $addressPersonal;
$addressWork = array(
'index' => self::toJSON($arUser['WORK_ZIP']),
'country' => self::toJSON(GetCountryByID($arUser['WORK_COUNTRY'])),
'city' => self::toJSON($arUser['WORK_CITY']),
'street' => self::toJSON($arUser['WORK_STREET']),
'building' => self::toJSON($arUser['UF_WORK_BUILDING']), // --
'flat' => self::toJSON($arUser['UF_WORK_FLAT']),
'notes' => self::toJSON($arUser['PERSONAL_NOTES']),
'text' => self::toJSON($arUser['UF_WORK_TEXT']),
'type' => 'work'
);
$addresses[] = $addressWork;
$result = array(
'externalId' => $arFields['USER_ID'],
'lastName' => $lastName,
'firstName' => $firstName,
'patronymic' => $patronymic,
'phones' => $phones,
'addresses' => $addresses
);
$customer = $api->customerEdit($result);
// error pushing customer
if (!$customer) {
//handle err
self::eventLog('IntaroCrm\RestApi::customerEdit', $api->getLastError());
return false;
}
// delivery types
$arId = array();
if (strpos($arFields['DELIVERY_ID'], ":") !== false)
$arId = explode(":", $arFields["DELIVERY_ID"]);
if ($arId)
$resultDeliveryTypeId = $arId[0];
else
$resultDeliveryTypeId = $arFields['DELIVERY_ID'];
$resOrder = array();
$resOrderDeliveryAddress = array();
$rsOrderProps = CSaleOrderPropsValue::GetList(array(), array('ORDER_ID' => $arFields['ID']));
while ($ar = $rsOrderProps->Fetch()) {
switch ($ar['CODE']) {
case 'ZIP': $resOrderDeliveryAddress['index'] = self::toJSON($ar['VALUE']);
break;
case 'CITY': $resOrderDeliveryAddress['city'] = self::toJSON($ar['VALUE']);
break;
case 'ADDRESS': $resOrderDeliveryAddress['text'] = self::toJSON($ar['VALUE']);
break;
case 'FIO': $resOrder['contactName'] = self::toJSON($ar['VALUE']);
break;
case 'PHONE': $resOrder['phone'] = $ar['VALUE'];
break;
case 'EMAIL': $resOrder['email'] = $ar['VALUE'];
break;
}
}
$resOrder['deliveryCost'] = $arFields['PRICE_DELIVERY'];
$resOrder['summ'] = $arFields['PRICE'];
$resOrder['markDateTime'] = $arFields['DATE_MARKED'];
$resOrder['externalId'] = $arFields['ID'];
$resOrder['customerId'] = $arFields['USER_ID'];
$resOrder['paymentType'] = $optionsPayTypes[$arFields['PAY_SYSTEM_ID']];
$resOrder['paymentStatus'] = $optionsPayment[$arFields['PAYED']];
$resOrder['orderType'] = $optionsOrderTypes[$arFields['PERSON_TYPE_ID']];
$resOrder['deliveryType'] = $optionsDelivTypes[$resultDeliveryTypeId];
$resOrder['status'] = $optionsPayStatuses[$arFields['STATUS_ID']];
$resOrder['deliveryAddress'] = $resOrderDeliveryAddress;
$items = array();
$rsOrderBasket = CSaleBasket::GetList(array('PRODUCT_ID' => 'ASC'), array('ORDER_ID' => $arFields['ID']));
while ($p = $rsOrderBasket->Fetch()) {
$pr = CCatalogProduct::GetList(array('ID' => $p['PRODUCT_ID']))->Fetch();
if($pr)
$pr = $pr['PURCHASING_PRICE'];
else
$pr = '';
$items[] = array(
'price' => $p['PRICE'],
'purchasePrice' => $pr,
'discount' => $p['DISCOUNT_VALUE'],
'quantity' => $p['QUANTITY'],
'productId' => $p['PRODUCT_ID'],
'productName' => self::toJSON($p['NAME'])
);
}
$resOrder['items'] = $items;
$resOrders[] = $resOrder;
}
$orders = $api->orderUpload($resOrders);
// error pushing orders
if(!$orders) {
//handle err
self::eventLog('IntaroCrm\RestApi::orderUpload', $api->getLastError());
return false;
}
COption::SetOptionString(self::$MODULE_ID, self::$CRM_ORDER_LAST_ID, $lastUpOrderIdNew);
return true; //all ok!
}
/**
*
* w event in bitrix log
* @param type $auditType
* @param type $itemId
* @param type $description
*/
private static function eventLog($itemId, $description) {
CEventLog::Add(array(
"SEVERITY" => "SECURITY",
"AUDIT_TYPE_ID" => 'ICrmOrderActions::uploadOrders',
"MODULE_ID" => self::$MODULE_ID,
"ITEM_ID" => $itemId,
"DESCRIPTION" => $description,
));
self::sendEmail($itemId, $description);
}
private static function sendEmail($itemId, $description) {
$title = 'Error: Intaro CRM.';
$text = 'Error: ' . $itemId . ' - ' . $description;
$to = COption::GetOptionString("main", "email_from");
$from = COption::GetOptionString("main", "email_from");
mail($to, $title, $text, 'From:'.$from);
}
/**
*
* Agent function
*
* @return self name
*/
public static function uploadOrdersAgent() {
if(self::uploadOrders())
return 'ICrmOrderActions::uploadOrdersAgent();';
else return;
}
}
?>

View File

@ -1,6 +1,7 @@
<?php <?php
namespace IntaroCrm;
class ICrmApi class RestApi
{ {
protected static $jsonReplaceSource = array( protected static $jsonReplaceSource = array(
'\u0410','\u0430','\u0411','\u0431','\u0412','\u0432','\u0413','\u0433', '\u0410','\u0430','\u0411','\u0431','\u0412','\u0432','\u0413','\u0433',
@ -32,6 +33,7 @@ class ICrmApi
protected $apiVersion = '1'; protected $apiVersion = '1';
protected $lastError; protected $lastError;
protected $statusCode; protected $statusCode;
protected $parameters;
/** /**
* @param string $crmUrl - адрес CRM * @param string $crmUrl - адрес CRM
@ -41,6 +43,7 @@ class ICrmApi
{ {
$this->apiUrl = $crmUrl.'/api/v'.$this->apiVersion.'/'; $this->apiUrl = $crmUrl.'/api/v'.$this->apiVersion.'/';
$this->apiKey = $apiKey; $this->apiKey = $apiKey;
$this->parameters = array('apiKey' => $this->apiKey);
} }
@ -70,11 +73,15 @@ class ICrmApi
* Получение заказа по id * Получение заказа по id
* *
* @param string $id - идентификатор заказа * @param string $id - идентификатор заказа
* @param string $by - поиск заказа по id или externalId
* @return array - информация о заказе * @return array - информация о заказе
*/ */
public function orderGet($id) public function orderGet($id, $by = 'externalId')
{ {
$url = $this->apiUrl.'orders/'.$id; $url = $this->apiUrl.'orders/'.$id;
if ($by != 'externalId')
$this->parameters['by'] = $by;
$result = $this->curlRequest($url); $result = $this->curlRequest($url);
return $result; return $result;
} }
@ -90,11 +97,10 @@ class ICrmApi
$dataJson = json_encode($order); $dataJson = json_encode($order);
$dataJson = str_replace(self::$jsonReplaceSource, self::$jsonReplaceTarget, $dataJson = str_replace(self::$jsonReplaceSource, self::$jsonReplaceTarget,
$dataJson); $dataJson);
$parameters = array(); $this->parameters['order'] = $dataJson;
$parameters['order'] = $dataJson;
$url = $this->apiUrl.'orders/create'; $url = $this->apiUrl.'orders/create';
$result = $this->curlRequest($url, $parameters, 'POST'); $result = $this->curlRequest($url, 'POST');
return $result; return $result;
} }
@ -109,11 +115,10 @@ class ICrmApi
$dataJson = json_encode($order); $dataJson = json_encode($order);
$dataJson = str_replace(self::$jsonReplaceSource, self::$jsonReplaceTarget, $dataJson = str_replace(self::$jsonReplaceSource, self::$jsonReplaceTarget,
$dataJson); $dataJson);
$parameters = array(); $this->parameters['order'] = $dataJson;
$parameters['order'] = $dataJson;
$url = $this->apiUrl.'orders/'.$order['id'].'/edit'; $url = $this->apiUrl.'orders/'.$order['externalId'].'/edit';
$result = $this->curlRequest($url, $parameters, 'POST'); $result = $this->curlRequest($url, 'POST');
return $result; return $result;
} }
@ -128,11 +133,10 @@ class ICrmApi
$dataJson = json_encode($orders); $dataJson = json_encode($orders);
$dataJson = str_replace(self::$jsonReplaceSource, self::$jsonReplaceTarget, $dataJson = str_replace(self::$jsonReplaceSource, self::$jsonReplaceTarget,
$dataJson); $dataJson);
$parameters = array(); $this->parameters['orders'] = $dataJson;
$parameters['orders'] = $dataJson;
$url = $this->apiUrl.'orders/upload'; $url = $this->apiUrl.'orders/upload';
$result = $this->curlRequest($url, $parameters, 'POST'); $result = $this->curlRequest($url, 'POST');
return $result; return $result;
} }
@ -140,12 +144,15 @@ class ICrmApi
* Удаление заказа * Удаление заказа
* *
* @param string $id - идентификатор заказа * @param string $id - идентификатор заказа
* @param string $by - поиск заказа по id или externalId
* @return array * @return array
*/ */
public function orderDelete($id) public function orderDelete($id, $by = 'externalId')
{ {
$url = $this->apiUrl.'orders/'.$id.'/delete'; $url = $this->apiUrl.'orders/'.$id.'/delete';
$result = $this->curlRequest($url, array(), 'POST'); if ($by != 'externalId')
$this->parameters['by'] = $by;
$result = $this->curlRequest($url, 'POST');
return $result; return $result;
} }
@ -161,13 +168,12 @@ class ICrmApi
public function orderHistory($startDate = null, $endDate = null, $limit = 100, $offset = 0) public function orderHistory($startDate = null, $endDate = null, $limit = 100, $offset = 0)
{ {
$url = $this->apiUrl.'orders/history'; $url = $this->apiUrl.'orders/history';
$parameters = array(); $this->parameters['startDate'] = $startDate;
$parameters['startDate'] = $startDate; $this->parameters['endDate'] = $endDate;
$parameters['endDate'] = $endDate; $this->parameters['limit'] = $limit;
$parameters['limit'] = $limit; $this->parameters['offset'] = $offset;
$parameters['offset'] = $offset;
$result = $this->curlRequest($url, $parameters); $result = $this->curlRequest($url);
return $result; return $result;
} }
@ -177,11 +183,14 @@ class ICrmApi
* Получение клиента по id * Получение клиента по id
* *
* @param string $id - идентификатор * @param string $id - идентификатор
* @param string $by - поиск заказа по id или externalId
* @return array - информация о клиенте * @return array - информация о клиенте
*/ */
public function customerGet($id) public function customerGet($id, $by = 'externalId')
{ {
$url = $this->apiUrl.'customers/'.$id; $url = $this->apiUrl.'customers/'.$id;
if ($by != 'externalId')
$this->parameters['by'] = $by;
$result = $this->curlRequest($url); $result = $this->curlRequest($url);
return $result; return $result;
} }
@ -197,11 +206,10 @@ class ICrmApi
$dataJson = json_encode($customer); $dataJson = json_encode($customer);
$dataJson = str_replace(self::$jsonReplaceSource, self::$jsonReplaceTarget, $dataJson = str_replace(self::$jsonReplaceSource, self::$jsonReplaceTarget,
$dataJson); $dataJson);
$parameters = array(); $this->parameters['customer'] = $dataJson;
$parameters['customer'] = $dataJson;
$url = $this->apiUrl.'customers/create'; $url = $this->apiUrl.'customers/create';
$result = $this->curlRequest($url, $parameters, 'POST'); $result = $this->curlRequest($url, 'POST');
return $result; return $result;
} }
@ -216,11 +224,10 @@ class ICrmApi
$dataJson = json_encode($customer); $dataJson = json_encode($customer);
$dataJson = str_replace(self::$jsonReplaceSource, self::$jsonReplaceTarget, $dataJson = str_replace(self::$jsonReplaceSource, self::$jsonReplaceTarget,
$dataJson); $dataJson);
$parameters = array(); $this->parameters['customer'] = $dataJson;
$parameters['customer'] = $dataJson;
$url = $this->apiUrl.'customers/'.$customer['id'].'/edit'; $url = $this->apiUrl.'customers/'.$customer['externalId'].'/edit';
$result = $this->curlRequest($url, $parameters, 'POST'); $result = $this->curlRequest($url, 'POST');
return $result; return $result;
} }
@ -228,12 +235,15 @@ class ICrmApi
* Удаление клиента * Удаление клиента
* *
* @param string $id - идентификатор * @param string $id - идентификатор
* @param string $by - поиск заказа по id или externalId
* @return array * @return array
*/ */
public function customerDelete($id) public function customerDelete($id, $by = 'externalId')
{ {
$url = $this->apiUrl.'customers/'.$id.'/delete'; $url = $this->apiUrl.'customers/'.$id.'/delete';
$result = $this->curlRequest($url, array(), 'POST'); if ($by != 'externalId')
$this->parameters['by'] = $by;
$result = $this->curlRequest($url, 'POST');
return $result; return $result;
} }
@ -241,6 +251,7 @@ class ICrmApi
* Получение списка заказов клиента * Получение списка заказов клиента
* *
* @param string $id - идентификатор клиента * @param string $id - идентификатор клиента
* @param string $by - поиск заказа по id или externalId
* @param DateTime $startDate - начальная дата выборки * @param DateTime $startDate - начальная дата выборки
* @param DateTime $endDate - конечная дата * @param DateTime $endDate - конечная дата
* @param int $limit - ограничение на размер выборки * @param int $limit - ограничение на размер выборки
@ -248,16 +259,17 @@ class ICrmApi
* @return array - массив заказов * @return array - массив заказов
*/ */
public function customerOrdersList($id, $startDate = null, $endDate = null, public function customerOrdersList($id, $startDate = null, $endDate = null,
$limit = 100, $offset = 0) $limit = 100, $offset = 0, $by = 'externalId')
{ {
$url = $this->apiUrl.'customers/'.$id.'/orders'; $url = $this->apiUrl.'customers/'.$id.'/orders';
$parameters = array(); if ($by != 'externalId')
$parameters['startDate'] = $startDate; $this->parameters['by'] = $by;
$parameters['endDate'] = $endDate; $this->parameters['startDate'] = $startDate;
$parameters['limit'] = $limit; $this->parameters['endDate'] = $endDate;
$parameters['offset'] = $offset; $this->parameters['limit'] = $limit;
$this->parameters['offset'] = $offset;
$result = $this->curlRequest($url, $parameters); $result = $this->curlRequest($url);
return $result; return $result;
} }
@ -285,14 +297,14 @@ class ICrmApi
$dataJson = json_encode($deliveryType); $dataJson = json_encode($deliveryType);
$dataJson = str_replace(self::$jsonReplaceSource, self::$jsonReplaceTarget, $dataJson = str_replace(self::$jsonReplaceSource, self::$jsonReplaceTarget,
$dataJson); $dataJson);
$parameters = array(); $this->parameters['deliveryType'] = $dataJson;
$parameters['deliveryType'] = $dataJson;
$url = $this->apiUrl.'delivery-types/'.$deliveryType['code'].'/edit'; $url = $this->apiUrl.'delivery-types/'.$deliveryType['code'].'/edit';
$result = $this->curlRequest($url, $parameters, 'POST'); $result = $this->curlRequest($url, 'POST');
return $result; return $result;
} }
/** /**
* Получение списка типов оплаты * Получение списка типов оплаты
* *
@ -316,11 +328,10 @@ class ICrmApi
$dataJson = json_encode($paymentType); $dataJson = json_encode($paymentType);
$dataJson = str_replace(self::$jsonReplaceSource, self::$jsonReplaceTarget, $dataJson = str_replace(self::$jsonReplaceSource, self::$jsonReplaceTarget,
$dataJson); $dataJson);
$parameters = array(); $this->parameters['paymentType'] = $dataJson;
$parameters['paymentType'] = $dataJson;
$url = $this->apiUrl.'payment-types/'.$paymentType['code'].'/edit'; $url = $this->apiUrl.'payment-types/'.$paymentType['code'].'/edit';
$result = $this->curlRequest($url, $parameters, 'POST'); $result = $this->curlRequest($url, 'POST');
return $result; return $result;
} }
@ -348,14 +359,14 @@ class ICrmApi
$dataJson = json_encode($paymentStatus); $dataJson = json_encode($paymentStatus);
$dataJson = str_replace(self::$jsonReplaceSource, self::$jsonReplaceTarget, $dataJson = str_replace(self::$jsonReplaceSource, self::$jsonReplaceTarget,
$dataJson); $dataJson);
$parameters = array(); $this->parameters['paymentStatus'] = $dataJson;
$parameters['paymentStatus'] = $dataJson;
$url = $this->apiUrl.'payment-statuses/'.$paymentStatus['code'].'/edit'; $url = $this->apiUrl.'payment-statuses/'.$paymentStatus['code'].'/edit';
$result = $this->curlRequest($url, $parameters, 'POST'); $result = $this->curlRequest($url, 'POST');
return $result; return $result;
} }
/** /**
* Получение списка типов заказа * Получение списка типов заказа
* *
@ -371,7 +382,7 @@ class ICrmApi
/** /**
* Редактирование типа заказа * Редактирование типа заказа
* *
* @param array $paymentType - информация о типе заказа * @param array $orderType - информация о типе заказа
* @return array * @return array
*/ */
public function orderTypesEdit($orderType) public function orderTypesEdit($orderType)
@ -379,36 +390,82 @@ class ICrmApi
$dataJson = json_encode($orderType); $dataJson = json_encode($orderType);
$dataJson = str_replace(self::$jsonReplaceSource, self::$jsonReplaceTarget, $dataJson = str_replace(self::$jsonReplaceSource, self::$jsonReplaceTarget,
$dataJson); $dataJson);
$parameters = array(); $this->parameters['orderType'] = $dataJson;
$parameters['orderType'] = $dataJson;
$url = $this->apiUrl.'order-types/'.$paymentType['code'].'/edit'; $url = $this->apiUrl.'order-types/'.$orderType['code'].'/edit';
$result = $this->curlRequest($url, $parameters, 'POST'); $result = $this->curlRequest($url, 'POST');
return $result; return $result;
} }
protected function curlRequest($url, $parameters = null, $method = 'GET', $format = 'json') /**
* Получение списка статусов заказа
*
* @return array - массив статусов заказа
*/
public function orderStatusesList()
{ {
$parameters['apiKey'] = $this->apiKey; $url = $this->apiUrl.'reference/statuses';
$result = $this->curlRequest($url);
return $result;
}
if ($method == 'GET' && !is_null($parameters)) /**
$url .= '?'.http_build_query($parameters); * Редактирование статуса заказа
*
* @param array $status - информация о статусе заказа
* @return array
*/
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';
$result = $this->curlRequest($url, 'POST');
return $result;
}
/**
* Получение списка групп статусов заказа
*
* @return array - массив групп статусов заказа
*/
public function orderStatusGroupsList()
{
$url = $this->apiUrl.'reference/status-groups';
$result = $this->curlRequest($url);
return $result;
}
protected function curlRequest($url, $method = 'GET', $format = 'json')
{
if ($method == 'GET' && !is_null($this->parameters))
$url .= '?'.http_build_query($this->parameters);
$ch = curl_init(); $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FAILONERROR, FALSE); curl_setopt($ch, CURLOPT_FAILONERROR, FALSE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // return into a variable curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // return into a variable
curl_setopt($ch, CURLOPT_TIMEOUT, 6); // times out after 6s curl_setopt($ch, CURLOPT_TIMEOUT, 30); // times out after 30s
if ($method == 'POST') if ($method == 'POST')
{ {
curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $parameters); curl_setopt($ch, CURLOPT_POSTFIELDS, $this->parameters);
} }
$response = curl_exec($ch); $response = curl_exec($ch);
$this->statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); $this->statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
unset($this->parameters);
/* Сброс массива с параметрами */
$this->parameters = array('apiKey' => $this->apiKey);
if (curl_errno($ch)) if (curl_errno($ch))
{ {
@ -432,4 +489,4 @@ class ICrmApi
} }
} }
?> ?>

View File

@ -1,9 +1,9 @@
<?php <?php
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' 'ICrmOrderActions' => 'classes/general/ICrmOrderActions.php'
) )
); );
?> ?>

View File

@ -28,6 +28,9 @@ 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 $CRM_ORDER_LAST_ID = 'order_last_id';
var $INSTALL_PATH; var $INSTALL_PATH;
@ -55,8 +58,8 @@ 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']);
if ($step <= 1) { if ($step <= 1) {
@ -81,7 +84,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 +107,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['paymentList'] = $this->INTARO_CRM_API->orderStatusesList();
//bitrix orderTypesList -- personTypes //bitrix orderTypesList -- personTypes
$dbOrderTypesList = CSalePersonType::GetList( $dbOrderTypesList = CSalePersonType::GetList(
@ -163,7 +167,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",
@ -181,12 +185,12 @@ class intaro_crm extends CModule
} while ($arPaymentStatusesList = $dbPaymentStatusesList->Fetch()); } while ($arPaymentStatusesList = $dbPaymentStatusesList->Fetch());
} }
$APPLICATION->IncludeAdminFile( $APPLICATION->IncludeAdminFile(
GetMessage('MODULE_INSTALL_TITLE'), GetMessage('MODULE_INSTALL_TITLE'),
$_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/step2.php' $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/step2.php'
); );
} else if ($step == 3) { } else if ($step == 3) {
if(!CModule::IncludeModule("sale")) { if(!CModule::IncludeModule("sale")) {
//handler //handler
} }
@ -206,14 +210,14 @@ class intaro_crm extends CModule
); );
//form order types ids arr //form order types ids arr
$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());
} }
//bitrix deliveryTypesList //bitrix deliveryTypesList
$dbDeliveryTypesList = CSaleDelivery::GetList( $dbDeliveryTypesList = CSaleDelivery::GetList(
array( array(
"SORT" => "ASC", "SORT" => "ASC",
@ -228,14 +232,14 @@ class intaro_crm extends CModule
); );
//form delivery types ids arr //form delivery types ids arr
$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());
} }
//bitrix paymentTypesList //bitrix paymentTypesList
$dbPaymentTypesList = CSalePaySystem::GetList( $dbPaymentTypesList = CSalePaySystem::GetList(
array( array(
"SORT" => "ASC", "SORT" => "ASC",
@ -247,14 +251,14 @@ class intaro_crm extends CModule
); );
//form payment types ids arr //form payment types ids arr
$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());
} }
//bitrix paymentStatusesList //bitrix paymentStatusesList
$dbPaymentStatusesList = CSaleStatus::GetList( $dbPaymentStatusesList = CSaleStatus::GetList(
array( array(
"SORT" => "ASC", "SORT" => "ASC",
@ -270,16 +274,39 @@ 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));
COption::SetOptionString($this->MODULE_ID, $this->CRM_ORDER_LAST_ID, 0);
RegisterModule($this->MODULE_ID); RegisterModule($this->MODULE_ID);
//agent
$dateAgent = new DateTime();
$intAgent = new DateInterval('PT60S');
$dateAgent->add($intAgent);
CAgent::AddAgent(
"ICrmOrderActions::uploadOrdersAgent();",
$this->MODULE_ID,
"N",
600, // interval - 10 mins
$dateAgent->format('d.m.Y H:i:s'), // date of first check
"Y", // агент активен
$dateAgent->format('d.m.Y H:i:s'), // date of first start
30
);
$APPLICATION->IncludeAdminFile( $APPLICATION->IncludeAdminFile(
GetMessage('MODULE_INSTALL_TITLE'), GetMessage('MODULE_INSTALL_TITLE'),
$_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/step3.php' $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/step3.php'
@ -289,7 +316,8 @@ class intaro_crm extends CModule
function DoUninstall() { function DoUninstall() {
global $APPLICATION; global $APPLICATION;
CAgent::RemoveAgent("ICrmOrderActions::uploadOrdersAgent();", $this->MODULE_ID);
UnRegisterModule($this->MODULE_ID); UnRegisterModule($this->MODULE_ID);
COption::RemoveOption($this->MODULE_ID, $this->CRM_API_HOST_OPTION); COption::RemoveOption($this->MODULE_ID, $this->CRM_API_HOST_OPTION);
@ -297,11 +325,13 @@ 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);
COption::RemoveOption($this->MODULE_ID, $this->CRM_ORDER_LAST_ID);
$APPLICATION->IncludeAdminFile( $APPLICATION->IncludeAdminFile(
GetMessage('MODULE_UNINSTALL_TITLE'), GetMessage('MODULE_UNINSTALL_TITLE'),
$_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/unstep1.php' $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/unstep1.php'
); );
} }
} }
?> ?>

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">
@ -10,91 +18,111 @@
<table class="adm-detail-content-table edit-table" id="edit1_edit_table"> <table class="adm-detail-content-table edit-table" id="edit1_edit_table">
<tbody> <tbody>
<tr class="heading"> <tr class="heading">
<td colspan="2"><b><?php echo GetMessage('STEP_NAME'); ?></b></td> <td colspan="2"><b><?php echo GetMessage('STEP_NAME'); ?></b></td>
</tr> </tr>
<tr class="heading"> <tr class="heading">
<td colspan="2"><b><?php echo GetMessage('DELIVERY_TYPES_LIST'); ?></b></td> <td colspan="2"><b><?php echo GetMessage('DELIVERY_TYPES_LIST'); ?></b></td>
</tr> </tr>
<?php foreach($arResult['bitrixDeliveryTypesList'] as $bitrixDeliveryType): ?> <?php foreach($arResult['bitrixDeliveryTypesList'] as $bitrixDeliveryType): ?>
<tr> <tr>
<td width="50%" class="adm-detail-content-cell-l" name="<?php echo $bitrixDeliveryType['ID']; ?>"> <td width="50%" class="adm-detail-content-cell-l" name="<?php echo $bitrixDeliveryType['ID']; ?>">
<?php echo $bitrixDeliveryType['NAME']; ?> <?php echo $bitrixDeliveryType['NAME']; ?>
</td> </td>
<td width="50%" class="adm-detail-content-cell-r"> <td width="50%" class="adm-detail-content-cell-r">
<select name="delivery-type-<?php echo $bitrixDeliveryType['ID']; ?>" class="typeselect"> <select name="delivery-type-<?php echo $bitrixDeliveryType['ID']; ?>" class="typeselect">
<option value="" selected=""></option> <option value="" selected=""></option>
<?php foreach($arResult['deliveryTypesList'] as $deliveryType): ?> <?php foreach($arResult['deliveryTypesList'] as $deliveryType): ?>
<option value="<?php echo $deliveryType['code']; ?>"> <option value="<?php echo $deliveryType['code']; ?>">
<?php echo $APPLICATION->ConvertCharset($deliveryType['name'], 'utf-8', SITE_CHARSET); ?> <?php echo $APPLICATION->ConvertCharset($deliveryType['name'], 'utf-8', SITE_CHARSET); ?>
</option> </option>
<?php endforeach; ?> <?php endforeach; ?>
</select> </select>
</td> </td>
</tr> </tr>
<?php endforeach; ?> <?php endforeach; ?>
<tr class="heading"> <tr class="heading">
<td colspan="2"><b><?php echo GetMessage('PAYMENT_TYPES_LIST'); ?></b></td> <td colspan="2"><b><?php echo GetMessage('PAYMENT_TYPES_LIST'); ?></b></td>
</tr> </tr>
<?php foreach($arResult['bitrixPaymentTypesList'] as $bitrixPaymentType): ?> <?php foreach($arResult['bitrixPaymentTypesList'] as $bitrixPaymentType): ?>
<tr> <tr>
<td width="50%" class="adm-detail-content-cell-l" name="<?php echo $bitrixPaymentType['ID']; ?>"> <td width="50%" class="adm-detail-content-cell-l" name="<?php echo $bitrixPaymentType['ID']; ?>">
<?php echo $bitrixPaymentType['NAME']; ?> <?php echo $bitrixPaymentType['NAME']; ?>
</td> </td>
<td width="50%" class="adm-detail-content-cell-r"> <td width="50%" class="adm-detail-content-cell-r">
<select name="payment-type-<?php echo $bitrixPaymentType['ID']; ?>" class="typeselect"> <select name="payment-type-<?php echo $bitrixPaymentType['ID']; ?>" class="typeselect">
<option value="" selected=""></option> <option value="" selected=""></option>
<?php foreach($arResult['paymentTypesList'] as $paymentType): ?> <?php foreach($arResult['paymentTypesList'] as $paymentType): ?>
<option value="<?php echo $paymentType['code']; ?>"> <option value="<?php echo $paymentType['code']; ?>">
<?php echo $APPLICATION->ConvertCharset($paymentType['name'], 'utf-8', SITE_CHARSET); ?> <?php echo $APPLICATION->ConvertCharset($paymentType['name'], 'utf-8', SITE_CHARSET); ?>
</option> </option>
<?php endforeach; ?> <?php endforeach; ?>
</select> </select>
</td> </td>
</tr> </tr>
<?php endforeach; ?> <?php endforeach; ?>
<tr class="heading"> <tr class="heading">
<td colspan="2"><b><?php echo GetMessage('PAYMENT_STATUS_LIST'); ?></b></td> <td colspan="2"><b><?php echo GetMessage('PAYMENT_STATUS_LIST'); ?></b></td>
</tr> </tr>
<?php foreach($arResult['bitrixPaymentStatusesList'] as $bitrixPaymentStatus): ?> <?php foreach($arResult['bitrixPaymentStatusesList'] as $bitrixPaymentStatus): ?>
<tr> <tr>
<td width="50%" class="adm-detail-content-cell-l" name="<?php echo $bitrixPaymentStatus['ID']; ?>"> <td width="50%" class="adm-detail-content-cell-l" name="<?php echo $bitrixPaymentStatus['ID']; ?>">
<?php echo $bitrixPaymentStatus['NAME']; ?> <?php echo $bitrixPaymentStatus['NAME']; ?>
</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']; ?>">
<?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; ?>
</select> </select>
</td> </td>
</tr> </tr>
<?php endforeach; ?> <?php endforeach; ?>
<tr class="heading"> <tr class="heading">
<td colspan="2"><b><?php echo GetMessage('ORDER_TYPES_LIST'); ?></b></td> <td colspan="2"><b><?php echo GetMessage('ORDER_TYPES_LIST'); ?></b></td>
</tr> </tr>
<?php foreach($arResult['bitrixOrderTypesList'] as $bitrixOrderType): ?> <?php foreach($arResult['bitrixOrderTypesList'] as $bitrixOrderType): ?>
<tr> <tr>
<td width="50%" class="adm-detail-content-cell-l" name="<?php echo $bitrixOrderType['ID']; ?>"> <td width="50%" class="adm-detail-content-cell-l" name="<?php echo $bitrixOrderType['ID']; ?>">
<?php echo $bitrixOrderType['NAME']; ?> <?php echo $bitrixOrderType['NAME']; ?>
</td> </td>
<td width="50%" class="adm-detail-content-cell-r"> <td width="50%" class="adm-detail-content-cell-r">
<select name="order-type-<?php echo $bitrixOrderType['ID']; ?>" class="typeselect"> <select name="order-type-<?php echo $bitrixOrderType['ID']; ?>" class="typeselect">
<option value="" selected=""></option> <option value="" selected=""></option>
<?php foreach($arResult['orderTypesList'] as $orderType): ?> <?php foreach($arResult['orderTypesList'] as $orderType): ?>
<option value="<?php echo $orderType['code']; ?>"> <option value="<?php echo $orderType['code']; ?>">
<?php echo $APPLICATION->ConvertCharset($orderType['name'], 'utf-8', SITE_CHARSET); ?> <?php echo $APPLICATION->ConvertCharset($orderType['name'], 'utf-8', SITE_CHARSET); ?>
</option> </option>
<?php endforeach; ?> <?php endforeach; ?>
</select> </select>
</td> </td>
</tr> </tr>
<?php endforeach; ?> <?php endforeach; ?>
</tbody> </tbody>
</table> </table>
<br /> <br />
<input type="submit" name="inst" value="<?php echo GetMessage("MOD_NEXT_STEP"); ?>" class="adm-btn-save"> <input type="submit" name="inst" value="<?php echo GetMessage("MOD_NEXT_STEP"); ?>" class="adm-btn-save">
</form> </form>

View File

@ -1,6 +1,6 @@
<? <?
$arModuleVersion = array( $arModuleVersion = array(
'VERSION' => '0.2a', 'VERSION' => '0.3a',
'VERSION_DATE' => '2013-07-05 21:08:00', 'VERSION_DATE' => '2013-07-10 16:49: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,15 @@ 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
$CRM_ORDER_LAST_ID = 'order_last_id';
CModule::IncludeModule('intaro.crm'); CModule::IncludeModule('intaro.crm');
CModule::IncludeModule('sale'); CModule::IncludeModule('sale');
@ -20,7 +29,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();
@ -49,7 +58,7 @@ if (isset($_POST['Update']) && $_POST['Update']=='Y') {
); );
//form order types ids arr //form order types ids arr
$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']] = $_POST['order-type-' . $arOrderTypesList['ID']];
@ -68,73 +77,80 @@ if (isset($_POST['Update']) && $_POST['Update']=='Y') {
false, false,
false, false,
array() array()
); );
//form delivery types ids arr //form delivery types ids arr
$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());
} }
//bitrix paymentTypesList //bitrix paymentTypesList
$dbPaymentTypesList = CSalePaySystem::GetList( $dbPaymentTypesList = CSalePaySystem::GetList(
array( array(
"SORT" => "ASC", "SORT" => "ASC",
"NAME" => "ASC" "NAME" => "ASC"
), ),
array( array(
"ACTIVE" => "Y" "ACTIVE" => "Y"
) )
); );
//form payment types ids arr //form payment types ids arr
$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());
} }
//bitrix paymentStatusesList //bitrix paymentStatusesList
$dbPaymentStatusesList = CSaleStatus::GetList( $dbPaymentStatusesList = CSaleStatus::GetList(
array( array(
"SORT" => "ASC", "SORT" => "ASC",
"NAME" => "ASC" "NAME" => "ASC"
), ),
array( array(
"LID" => "ru", //ru "LID" => "ru", //ru
"ACTIVE" => "Y" "ACTIVE" => "Y"
) )
); );
//form payment statuses ids arr //form payment statuses ids arr
$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));
COption::SetOptionString($mid, 'deliv_types_arr', serialize($deliveryTypesArr));
COption::SetOptionString($mid, 'pay_types_arr', serialize($paymentTypesArr));
COption::SetOptionString($mid, 'pay_statuses_arr', serialize($paymentStatusesArr));
$uri .= '&ok=Y'; //form payment ids arr
LocalRedirect($uri); $paymentArr = array();
} else { $paymentArr['Y'] = htmlspecialchars(trim($_POST['payment-Y']));
$api_host = COption::GetOptionString($mid, 'api_host', 0); $paymentArr['N'] = htmlspecialchars(trim($_POST['payment-N']));
$api_key = COption::GetOptionString($mid, 'api_key', 0);
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));
$api = new ICrmApi($api_host, $api_key); $uri .= '&ok=Y';
LocalRedirect($uri);
} else {
$api_host = COption::GetOptionString($mid, $CRM_API_HOST_OPTION, 0);
$api_key = COption::GetOptionString($mid, $CRM_API_KEY_OPTION, 0);
$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['paymentList'] = $api->orderStatusesList();
//bitrix orderTypesList -- personTypes //bitrix orderTypesList -- personTypes
$dbOrderTypesList = CSalePersonType::GetList( $dbOrderTypesList = CSalePersonType::GetList(
@ -210,12 +226,19 @@ if (isset($_POST['Update']) && $_POST['Update']=='Y') {
$arResult['bitrixPaymentStatusesList'][] = $arPaymentStatusesList; $arResult['bitrixPaymentStatusesList'][] = $arPaymentStatusesList;
} 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(
@ -228,7 +251,7 @@ if (isset($_POST['Update']) && $_POST['Update']=='Y') {
"DIV" => "edit2", "DIV" => "edit2",
"TAB" => GetMessage('ICRM_OPTIONS_CATALOG_TAB'), "TAB" => GetMessage('ICRM_OPTIONS_CATALOG_TAB'),
"ICON" => '', "ICON" => '',
"TITLE" => GetMessage('ICRM_OPTIONS_IMPORT_CAPTION') "TITLE" => GetMessage('ICRM_OPTIONS_CATALOG_CAPTION')
), ),
); );
$tabControl = new CAdminTabControl("tabControl", $aTabs); $tabControl = new CAdminTabControl("tabControl", $aTabs);
@ -293,31 +316,51 @@ if (isset($_POST['Update']) && $_POST['Update']=='Y') {
</td> </td>
</tr> </tr>
<?php endforeach; ?> <?php endforeach; ?>
<tr class="heading"> <tr class="heading">
<td colspan="2"><b><?php echo GetMessage('PAYMENT_STATUS_LIST'); ?></b></td> <td colspan="2"><b><?php echo GetMessage('PAYMENT_STATUS_LIST'); ?></b></td>
</tr> </tr>
<?php foreach($arResult['bitrixPaymentStatusesList'] as $bitrixPaymentStatus): ?> <?php foreach($arResult['bitrixPaymentStatusesList'] as $bitrixPaymentStatus): ?>
<tr> <tr>
<td width="50%" class="adm-detail-content-cell-l" name="<?php echo $bitrixPaymentStatus['ID']; ?>"> <td width="50%" class="adm-detail-content-cell-l" name="<?php echo $bitrixPaymentStatus['ID']; ?>">
<?php echo $bitrixPaymentStatus['NAME']; ?> <?php echo $bitrixPaymentStatus['NAME']; ?>
</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; ?>
</select> </select>
</td> </td>
</tr> </tr>
<?php endforeach; ?> <?php endforeach; ?>
<tr class="heading"> <tr class="heading">
<td colspan="2"><b><?php echo GetMessage('ORDER_TYPES_LIST'); ?></b></td> <td colspan="2"><b><?php echo GetMessage('ORDER_TYPES_LIST'); ?></b></td>
</tr> </tr>
<?php foreach($arResult['bitrixOrderTypesList'] as $bitrixOrderType): ?> <?php foreach($arResult['bitrixOrderTypesList'] as $bitrixOrderType): ?>
<tr> <tr>
<td width="50%" class="adm-detail-content-cell-l" name="<?php echo $bitrixOrderType['ID']; ?>"> <td width="50%" class="adm-detail-content-cell-l" name="<?php echo $bitrixOrderType['ID']; ?>">
<?php echo $bitrixOrderType['NAME']; ?> <?php echo $bitrixOrderType['NAME']; ?>
</td> </td>
@ -331,8 +374,8 @@ if (isset($_POST['Update']) && $_POST['Update']=='Y') {
<?php endforeach; ?> <?php endforeach; ?>
</select> </select>
</td> </td>
</tr> </tr>
<?php endforeach; ?> <?php endforeach; ?>
<?php $tabControl->BeginNextTab(); ?> <?php $tabControl->BeginNextTab(); ?>
<?php $tabControl->Buttons(); ?> <?php $tabControl->Buttons(); ?>
<input type="hidden" name="Update" value="Y" /> <input type="hidden" name="Update" value="Y" />