+method to upload orders; +api upd;
This commit is contained in:
parent
139d47d2fc
commit
fd34304c5f
256
intaro.crm/classes/general/ICrmOrderActions.php
Normal file
256
intaro.crm/classes/general/ICrmOrderActions.php
Normal file
@ -0,0 +1,256 @@
|
|||||||
|
<?php
|
||||||
|
//namespace IntaroCrm;
|
||||||
|
|
||||||
|
class ICrmOrderActions
|
||||||
|
{
|
||||||
|
public static $MODULE_ID = 'intaro.crm';
|
||||||
|
public static $CRM_API_HOST_OPTION = 'api_host';
|
||||||
|
public static $CRM_API_KEY_OPTION = 'api_key';
|
||||||
|
public static $CRM_ORDER_TYPES_ARR = 'order_types_arr';
|
||||||
|
public static $CRM_DELIVERY_TYPES_ARR = 'deliv_types_arr';
|
||||||
|
public static $CRM_PAYMENT_TYPES = 'pay_types_arr';
|
||||||
|
public static $CRM_PAYMENT_STATUSES = 'pay_statuses_arr';
|
||||||
|
public static $CRM_PAYMENT = 'payment_arr'; //order payment Y/N
|
||||||
|
public static $CRM_ORDER_LAST_ID = 'order_last_id';
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @global type $APPLICATION
|
||||||
|
* @param type $str in SITE_CHARSET
|
||||||
|
* @return type $str in utf-8
|
||||||
|
*/
|
||||||
|
public 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
|
||||||
|
*/
|
||||||
|
function uploadOrders() {
|
||||||
|
|
||||||
|
//ini_set('display_errors', 1);
|
||||||
|
//error_reporting(E_ALL);
|
||||||
|
|
||||||
|
COption::SetOptionString(self::$MODULE_ID, self::$CRM_ORDER_LAST_ID, 0);
|
||||||
|
|
||||||
|
if (!CModule::IncludeModule('iblock')) {
|
||||||
|
//ShowError(GetMessage("SOA_MODULE_NOT_INSTALL"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!CModule::IncludeModule("sale")) {
|
||||||
|
//ShowError(GetMessage("SOA_MODULE_NOT_INSTALL"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$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
|
||||||
|
break;
|
||||||
|
|
||||||
|
if(!$lastUpOrderIdNew)
|
||||||
|
$lastUpOrderIdNew = $arOrder['ID'];
|
||||||
|
|
||||||
|
$arFields = CSaleOrder::GetById($arOrder['ID']);
|
||||||
|
|
||||||
|
if (empty($arFields)) {
|
||||||
|
//handle err
|
||||||
|
CEventLog::Add(array(
|
||||||
|
"SEVERITY" => "SECURITY",
|
||||||
|
"AUDIT_TYPE_ID" => "IntroCrm\uploadOrders",
|
||||||
|
"MODULE_ID" => self::$MODULE_ID,
|
||||||
|
"ITEM_ID" => 'empty($arFields)',
|
||||||
|
"DESCRIPTION" => "Не корректный заказ.",
|
||||||
|
));
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$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
|
||||||
|
CEventLog::Add(array(
|
||||||
|
"SEVERITY" => "SECURITY",
|
||||||
|
"AUDIT_TYPE_ID" => "IntroCrm\uploadOrders",
|
||||||
|
"MODULE_ID" => self::$MODULE_ID,
|
||||||
|
"ITEM_ID" => "customerEdit",
|
||||||
|
"DESCRIPTION" => $api->getLastError(),
|
||||||
|
));
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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()) {
|
||||||
|
$items[] = array(
|
||||||
|
'price' => $p['PRICE'],
|
||||||
|
'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
|
||||||
|
CEventLog::Add(array(
|
||||||
|
"SEVERITY" => "SECURITY",
|
||||||
|
"AUDIT_TYPE_ID" => "IntroCrm\uploadOrders",
|
||||||
|
"MODULE_ID" => self::$MODULE_ID,
|
||||||
|
"ITEM_ID" => "orderUpload",
|
||||||
|
"DESCRIPTION" => $api->getLastError(),
|
||||||
|
));
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
COption::SetOptionString(self::$MODULE_ID, self::$CRM_ORDER_LAST_ID, $lastUpOrderIdNew);
|
||||||
|
|
||||||
|
return; //all ok!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
@ -33,6 +33,7 @@ class RestApi
|
|||||||
protected $apiVersion = '1';
|
protected $apiVersion = '1';
|
||||||
protected $lastError;
|
protected $lastError;
|
||||||
protected $statusCode;
|
protected $statusCode;
|
||||||
|
protected $parameters;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $crmUrl - адрес CRM
|
* @param string $crmUrl - адрес CRM
|
||||||
@ -42,6 +43,7 @@ class RestApi
|
|||||||
{
|
{
|
||||||
$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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -71,11 +73,15 @@ class RestApi
|
|||||||
* Получение заказа по 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;
|
||||||
}
|
}
|
||||||
@ -91,11 +97,10 @@ class RestApi
|
|||||||
$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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,11 +115,10 @@ class RestApi
|
|||||||
$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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,11 +133,10 @@ class RestApi
|
|||||||
$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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,12 +144,15 @@ class RestApi
|
|||||||
* Удаление заказа
|
* Удаление заказа
|
||||||
*
|
*
|
||||||
* @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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,13 +168,12 @@ class RestApi
|
|||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,11 +183,14 @@ class RestApi
|
|||||||
* Получение клиента по 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;
|
||||||
}
|
}
|
||||||
@ -198,11 +206,10 @@ class RestApi
|
|||||||
$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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -217,11 +224,10 @@ class RestApi
|
|||||||
$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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -229,12 +235,15 @@ class RestApi
|
|||||||
* Удаление клиента
|
* Удаление клиента
|
||||||
*
|
*
|
||||||
* @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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -242,6 +251,7 @@ class RestApi
|
|||||||
* Получение списка заказов клиента
|
* Получение списка заказов клиента
|
||||||
*
|
*
|
||||||
* @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 - ограничение на размер выборки
|
||||||
@ -249,16 +259,17 @@ class RestApi
|
|||||||
* @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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -286,11 +297,10 @@ class RestApi
|
|||||||
$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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -318,11 +328,10 @@ class RestApi
|
|||||||
$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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -350,11 +359,10 @@ class RestApi
|
|||||||
$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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -374,7 +382,7 @@ class RestApi
|
|||||||
/**
|
/**
|
||||||
* Редактирование типа заказа
|
* Редактирование типа заказа
|
||||||
*
|
*
|
||||||
* @param array $paymentType - информация о типе заказа
|
* @param array $orderType - информация о типе заказа
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function orderTypesEdit($orderType)
|
public function orderTypesEdit($orderType)
|
||||||
@ -382,39 +390,82 @@ class RestApi
|
|||||||
$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 array - массив статусов заказа
|
||||||
|
*/
|
||||||
|
public function orderStatusesList()
|
||||||
|
{
|
||||||
|
$url = $this->apiUrl.'reference/statuses';
|
||||||
|
$result = $this->curlRequest($url);
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Редактирование статуса заказа
|
||||||
|
*
|
||||||
|
* @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;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected function curlRequest($url, $parameters = null, $method = 'GET', $format = 'json')
|
protected function curlRequest($url, $method = 'GET', $format = 'json')
|
||||||
{
|
{
|
||||||
$parameters['apiKey'] = $this->apiKey;
|
if ($method == 'GET' && !is_null($this->parameters))
|
||||||
|
$url .= '?'.http_build_query($this->parameters);
|
||||||
if ($method == 'GET' && !is_null($parameters))
|
|
||||||
$url .= '?'.http_build_query($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, 3); // times out after 3s
|
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))
|
||||||
{
|
{
|
||||||
|
@ -2,7 +2,8 @@
|
|||||||
CModule::AddAutoloadClasses(
|
CModule::AddAutoloadClasses(
|
||||||
'intaro.crm', // module name
|
'intaro.crm', // module name
|
||||||
array (
|
array (
|
||||||
'IntaroCrm\RestApi' => 'classes/general/RestApi.php'
|
'IntaroCrm\RestApi' => 'classes/general/RestApi.php',
|
||||||
|
'ICrmOrderActions' => 'classes/general/ICrmOrderActions.php'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
?>
|
?>
|
||||||
|
@ -29,6 +29,7 @@ class intaro_crm extends CModule
|
|||||||
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_PAYMENT = 'payment_arr'; //order payment Y/N
|
||||||
|
var $CRM_ORDER_LAST_ID = 'order_last_id';
|
||||||
|
|
||||||
|
|
||||||
var $INSTALL_PATH;
|
var $INSTALL_PATH;
|
||||||
@ -107,7 +108,7 @@ class intaro_crm extends CModule
|
|||||||
$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(); // --statuses
|
$arResult['paymentStatusesList'] = $this->INTARO_CRM_API->paymentStatusesList(); // --statuses
|
||||||
//$arResult['payment'] = $this->INTARO_CRM_API->getPymentsList() -- not exist
|
$arResult['paymentList'] = $this->INTARO_CRM_API->orderStatusesList();
|
||||||
|
|
||||||
//bitrix orderTypesList -- personTypes
|
//bitrix orderTypesList -- personTypes
|
||||||
$dbOrderTypesList = CSalePersonType::GetList(
|
$dbOrderTypesList = CSalePersonType::GetList(
|
||||||
@ -307,6 +308,7 @@ class intaro_crm extends CModule
|
|||||||
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_PAYMENT);
|
||||||
|
COption::RemoveOption($this->MODULE_ID, $this->CRM_ORDER_LAST_ID);
|
||||||
|
|
||||||
$APPLICATION->IncludeAdminFile(
|
$APPLICATION->IncludeAdminFile(
|
||||||
GetMessage('MODULE_UNINSTALL_TITLE'),
|
GetMessage('MODULE_UNINSTALL_TITLE'),
|
||||||
|
@ -10,6 +10,7 @@ $CRM_DELIVERY_TYPES_ARR = 'deliv_types_arr';
|
|||||||
$CRM_PAYMENT_TYPES = 'pay_types_arr';
|
$CRM_PAYMENT_TYPES = 'pay_types_arr';
|
||||||
$CRM_PAYMENT_STATUSES = 'pay_statuses_arr';
|
$CRM_PAYMENT_STATUSES = 'pay_statuses_arr';
|
||||||
$CRM_PAYMENT = 'payment_arr'; //order payment Y/N
|
$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');
|
||||||
@ -139,8 +140,8 @@ if (isset($_POST['Update']) && $_POST['Update']=='Y') {
|
|||||||
$uri .= '&ok=Y';
|
$uri .= '&ok=Y';
|
||||||
LocalRedirect($uri);
|
LocalRedirect($uri);
|
||||||
} else {
|
} else {
|
||||||
$api_host = COption::GetOptionString($mid, 'api_host', 0);
|
$api_host = COption::GetOptionString($mid, $CRM_API_HOST_OPTION, 0);
|
||||||
$api_key = COption::GetOptionString($mid, 'api_key', 0);
|
$api_key = COption::GetOptionString($mid, $CRM_API_KEY_OPTION, 0);
|
||||||
|
|
||||||
$api = new IntaroCrm\RestApi($api_host, $api_key);
|
$api = new IntaroCrm\RestApi($api_host, $api_key);
|
||||||
|
|
||||||
@ -149,7 +150,7 @@ if (isset($_POST['Update']) && $_POST['Update']=='Y') {
|
|||||||
$arResult['deliveryTypesList'] = $api->deliveryTypesList();
|
$arResult['deliveryTypesList'] = $api->deliveryTypesList();
|
||||||
$arResult['paymentTypesList'] = $api->paymentTypesList();
|
$arResult['paymentTypesList'] = $api->paymentTypesList();
|
||||||
$arResult['paymentStatusesList'] = $api->paymentStatusesList(); // --statuses
|
$arResult['paymentStatusesList'] = $api->paymentStatusesList(); // --statuses
|
||||||
//$arResult['payment'] = $this->INTARO_CRM_API->getPymentsList() -- not exist
|
$arResult['paymentList'] = $api->orderStatusesList();
|
||||||
|
|
||||||
//bitrix orderTypesList -- personTypes
|
//bitrix orderTypesList -- personTypes
|
||||||
$dbOrderTypesList = CSalePersonType::GetList(
|
$dbOrderTypesList = CSalePersonType::GetList(
|
||||||
@ -250,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);
|
||||||
|
Loading…
Reference in New Issue
Block a user