diff --git a/intaro.intarocrm/classes/general/ICrmOrderActions.php b/intaro.intarocrm/classes/general/ICrmOrderActions.php index 0ac3ea8f..b687a8fb 100755 --- a/intaro.intarocrm/classes/general/ICrmOrderActions.php +++ b/intaro.intarocrm/classes/general/ICrmOrderActions.php @@ -157,7 +157,7 @@ class ICrmOrderActions * * w+ event in bitrix log */ - private static function eventLog($auditType, $itemId, $description) { + public static function eventLog($auditType, $itemId, $description) { CEventLog::Add(array( "SEVERITY" => "SECURITY", "AUDIT_TYPE_ID" => $auditType, @@ -186,7 +186,11 @@ class ICrmOrderActions if(!$api || empty($arParams)) { // add cond to check $arParams return false; } +<<<<<<< HEAD +======= + +>>>>>>> cancelEvent if (empty($arFields)) { //handle err self::eventLog('ICrmOrderActions::orderCreate', 'empty($arFields)', 'incorrect order'); @@ -385,7 +389,7 @@ class ICrmOrderActions * @param type $str in SITE_CHARSET * @return type $str in utf-8 */ - protected static function toJSON($str) { + public static function toJSON($str) { global $APPLICATION; return $APPLICATION->ConvertCharset($str, SITE_CHARSET, 'utf-8'); diff --git a/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php b/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php new file mode 100644 index 00000000..01ee9dcf --- /dev/null +++ b/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php @@ -0,0 +1,145 @@ + $optionsOrderTypes, + 'optionsDelivTypes' => $optionsDelivTypes, + 'optionsPayTypes' => $optionsPayTypes, + 'optionsPayStatuses' => $optionsPayStatuses, + 'optionsPayment' => $optionsPayment + ); + + $arOrder = CSaleOrder::GetById($ID); + $result = ICrmOrderActions::orderCreate($arOrder, $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; + } + + $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 + $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, + '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; + } +} \ No newline at end of file diff --git a/intaro.intarocrm/install/index.php b/intaro.intarocrm/install/index.php index 84b38aff..85236673 100755 --- a/intaro.intarocrm/install/index.php +++ b/intaro.intarocrm/install/index.php @@ -389,6 +389,7 @@ class intaro_intarocrm extends CModule } else if ($step == 4) { RegisterModule($this->MODULE_ID); + RegisterModuleDependences("sale", "OnSaleCancelOrder", $this->MODULE_ID, "ICrmOrderEvent", "onSaleCancelOrder"); //agent $dateAgent = new DateTime(); @@ -427,9 +428,10 @@ class intaro_intarocrm extends CModule 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); - + UnRegisterModuleDependences("sale", "OnSaleCancelOrder", $this->MODULE_ID, "ICrmOrderEvent", "onSaleCancelOrder"); + $this->DeleteFiles(); - + UnRegisterModule($this->MODULE_ID); $APPLICATION->IncludeAdminFile(