added onCancelOrderEvent
This commit is contained in:
parent
e4176b2856
commit
1a674a91be
@ -154,7 +154,7 @@ class ICrmOrderActions
|
|||||||
*
|
*
|
||||||
* w+ event in bitrix log
|
* w+ event in bitrix log
|
||||||
*/
|
*/
|
||||||
private static function eventLog($auditType, $itemId, $description) {
|
public static function eventLog($auditType, $itemId, $description) {
|
||||||
CEventLog::Add(array(
|
CEventLog::Add(array(
|
||||||
"SEVERITY" => "SECURITY",
|
"SEVERITY" => "SECURITY",
|
||||||
"AUDIT_TYPE_ID" => $auditType,
|
"AUDIT_TYPE_ID" => $auditType,
|
||||||
@ -358,7 +358,7 @@ class ICrmOrderActions
|
|||||||
* @param type $str in SITE_CHARSET
|
* @param type $str in SITE_CHARSET
|
||||||
* @return type $str in utf-8
|
* @return type $str in utf-8
|
||||||
*/
|
*/
|
||||||
protected static function toJSON($str) {
|
public static function toJSON($str) {
|
||||||
global $APPLICATION;
|
global $APPLICATION;
|
||||||
|
|
||||||
return $APPLICATION->ConvertCharset($str, SITE_CHARSET, 'utf-8');
|
return $APPLICATION->ConvertCharset($str, SITE_CHARSET, 'utf-8');
|
||||||
|
156
intaro.intarocrm/classes/general/events/ICrmOrderEvent.php
Normal file
156
intaro.intarocrm/classes/general/events/ICrmOrderEvent.php
Normal file
@ -0,0 +1,156 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* OrderEvent
|
||||||
|
*/
|
||||||
|
class ICrmOrderEvent {
|
||||||
|
|
||||||
|
protected static $MODULE_ID = 'intaro.intarocrm';
|
||||||
|
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';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* onUpdateOrder
|
||||||
|
*
|
||||||
|
* @param mixed $ID - Order id
|
||||||
|
* @param mixed $arFields - Order arFields
|
||||||
|
*/
|
||||||
|
function onUpdateOrder($ID, $arFields = array()) {
|
||||||
|
//self::writeDataOnOrderCreate($ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* onSendOrderMail
|
||||||
|
* in: sale.order.ajax, sale.order.full
|
||||||
|
*
|
||||||
|
* @param mixed $ID - Order id
|
||||||
|
* @param mixed $eventName - Event type
|
||||||
|
* @param mixed $arFields - Order arFields for sending template
|
||||||
|
*/
|
||||||
|
function onSendOrderMail($ID, &$eventName, &$arFields) {
|
||||||
|
self::writeDataOnOrderCreate($ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* writeDataOnOrderCreate via api
|
||||||
|
*
|
||||||
|
* @param integer $ID - Order Id
|
||||||
|
*/
|
||||||
|
function writeDataOnOrderCreate($ID) {
|
||||||
|
if (!CModule::IncludeModule('iblock')) {
|
||||||
|
//handle err
|
||||||
|
ICrmOrderActions::eventLog('ICrmOrderEvent::writeDataOnOrderCreate', 'iblock', 'module not found');
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!CModule::IncludeModule("sale")) {
|
||||||
|
//handle err
|
||||||
|
ICrmOrderActions::eventLog('ICrmOrderEvent::writeDataOnOrderCreate', 'sale', 'module not found');
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!CModule::IncludeModule("catalog")) {
|
||||||
|
//handle err
|
||||||
|
ICrmOrderActions::eventLog('ICrmOrderEvent::writeDataOnOrderCreate', 'catalog', 'module not found');
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$api_host = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_HOST_OPTION, 0);
|
||||||
|
$api_key = COption::GetOptionString(Iself::$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);
|
||||||
|
|
||||||
|
$arParams = array(
|
||||||
|
'optionsOrderTypes' => $optionsOrderTypes,
|
||||||
|
'optionsDelivTypes' => $optionsDelivTypes,
|
||||||
|
'optionsPayTypes' => $optionsPayTypes,
|
||||||
|
'optionsPayStatuses' => $optionsPayStatuses,
|
||||||
|
'optionsPayment' => $optionsPayment
|
||||||
|
);
|
||||||
|
|
||||||
|
$result = ICrmOrderActions::orderCreate($ID, $api, $arParams, true);
|
||||||
|
|
||||||
|
if(!$result) {
|
||||||
|
ICrmOrderActions::eventLog('ICrmOrderEvent::writeDataOnOrderCreate', 'ICrmOrderActions::orderCreate', 'error during creating order');
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param type $ID -- orderId
|
||||||
|
* @param type $cancel -- Y / N - cancel order status
|
||||||
|
* @param type $reason -- cancel reason
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
function onSaleCancelOrder($ID, $cancel, $reason) {
|
||||||
|
if(!$ID || !$cancel || ($cancel != 'Y'))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (!CModule::IncludeModule('iblock')) {
|
||||||
|
//handle err
|
||||||
|
ICrmOrderActions::eventLog('ICrmOrderEvent::onSaleCancelOrder', 'iblock', 'module not found');
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!CModule::IncludeModule("sale")) {
|
||||||
|
//handle err
|
||||||
|
ICrmOrderActions::eventLog('ICrmOrderEvent::onSaleCancelOrder', 'sale', 'module not found');
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!CModule::IncludeModule("catalog")) {
|
||||||
|
//handle err
|
||||||
|
ICrmOrderActions::eventLog('ICrmOrderEvent::onSaleCancelOrder', 'catalog', 'module not found');
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$arFields = CSaleOrder::GetById($ID);
|
||||||
|
|
||||||
|
if (empty($arFields)) {
|
||||||
|
//handle err
|
||||||
|
self::eventLog('ICrmOrderEvent::onSaleCancelOrder', 'empty($arFields)', 'incorrect order');
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$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));
|
||||||
|
$optionsPayStatuses = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT_STATUSES, 0)); // --statuses
|
||||||
|
|
||||||
|
$api = new IntaroCrm\RestApi($api_host, $api_key);
|
||||||
|
|
||||||
|
$order = array(
|
||||||
|
'externalId' => (int) $ID,
|
||||||
|
'customerId' => (int) $arFields['USER_ID'],
|
||||||
|
'orderType' => $optionsOrderTypes[$arFields['PERSON_TYPE_ID']],
|
||||||
|
'status' => $optionsPayStatuses[$cancel],
|
||||||
|
'statusComment' => ICrmOrderActions::toJSON($reason)
|
||||||
|
);
|
||||||
|
|
||||||
|
$api->orderEdit($order);
|
||||||
|
|
||||||
|
// error pushing order
|
||||||
|
if ($api->getStatusCode() != 201)
|
||||||
|
ICrmOrderActions::eventLog('ICrmOrderEvent::onSaleCancelOrder', 'IntaroCrm\RestApi::orderEdit', $api->getLastError());
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -378,6 +378,7 @@ class intaro_intarocrm extends CModule
|
|||||||
} else if ($step == 4) {
|
} else if ($step == 4) {
|
||||||
|
|
||||||
RegisterModule($this->MODULE_ID);
|
RegisterModule($this->MODULE_ID);
|
||||||
|
RegisterModuleDependences("sale", "OnSaleCancelOrder", $this->MODULE_ID, "ICrmOrderEvent", "onSaleCancelOrder");
|
||||||
|
|
||||||
//agent
|
//agent
|
||||||
$dateAgent = new DateTime();
|
$dateAgent = new DateTime();
|
||||||
@ -416,6 +417,7 @@ class intaro_intarocrm extends CModule
|
|||||||
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);
|
COption::RemoveOption($this->MODULE_ID, $this->CRM_ORDER_LAST_ID);
|
||||||
|
UnRegisterModuleDependences("sale", "OnSaleCancelOrder", $this->MODULE_ID, "ICrmOrderEvent", "onSaleCancelOrder");
|
||||||
|
|
||||||
$this->DeleteFiles();
|
$this->DeleteFiles();
|
||||||
|
|
||||||
|
5
intaro.intarocrm/install/version.php~
Executable file
5
intaro.intarocrm/install/version.php~
Executable file
@ -0,0 +1,5 @@
|
|||||||
|
<?
|
||||||
|
$arModuleVersion = array(
|
||||||
|
'VERSION' => '0.4.6',
|
||||||
|
'VERSION_DATE' => '2013-07-25 15:35:00',
|
||||||
|
);
|
Loading…
Reference in New Issue
Block a user