$optionsOrderTypes, 'optionsDelivTypes' => $optionsDelivTypes, 'optionsPayTypes' => $optionsPayTypes, 'optionsPayStatuses' => $optionsPayStatuses, 'optionsPayment' => $optionsPayment, 'optionsOrderProps' => $optionsOrderProps, 'optionsLegalDetails' => $optionsLegalDetails, 'optionsContragentType' => $optionsContragentType, 'optionsSitesList' => $optionsSitesList, 'optionsCustomFields' => $optionsCustomFields )); $arOrder = CSaleOrder::GetById($ID); if (is_array($arFields) && !empty($arFields)) { $arFieldsNew = array( 'USER_ID' => $arOrder['USER_ID'], 'ID' => $ID, 'PERSON_TYPE_ID' => $arOrder['PERSON_TYPE_ID'], 'CANCELED' => $arOrder['CANCELED'], 'STATUS_ID' => $arOrder['STATUS_ID'], 'DATE_INSERT' => $arOrder['DATE_INSERT'], 'LID' => $arOrder['LID'] ); $arFieldsNew = array_merge($arFieldsNew, $arFields); $arOrder = $arFieldsNew; } if(count($optionsSitesList)>1){ $result = ICrmOrderActions::orderCreate($arOrder, $api, $arParams, true, $optionsSitesList[$arOrder['LID']]); } else{ $result = ICrmOrderActions::orderCreate($arOrder, $api, $arParams, true); } if(!$result) { ICrmOrderActions::eventLog('ICrmOrderEvent::writeDataOnOrderCreate', 'ICrmOrderActions::orderCreate', 'error during creating order'); return false; } 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(isset($GLOBALS['INTARO_CRM_FROM_HISTORY']) && $GLOBALS['INTARO_CRM_FROM_HISTORY']) return; if(!$ID || !$cancel) 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 RetailCrm\RestApi($api_host, $api_key); $order = array(); if($cancel == 'Y') { $order = array( 'externalId' => (int) $ID, 'status' => $optionsPayStatuses[$cancel.$cancel], 'statusComment' => ICrmOrderActions::toJSON($reason) ); } else if($cancel == 'N') { $arOrder = CSaleOrder::GetById((int) $ID); $order = array( 'externalId' => (int) $ID, 'status' => $optionsPayStatuses[$arOrder['STATUS_ID']], 'managerComment' => $arOrder['COMMENTS'] ); } $log = new Logger(); $log->write($order, 'order'); try { $api->orderEdit($order); } catch (\RetailCrm\Exception\CurlException $e) { ICrmOrderActions::eventLog( 'ICrmOrderEvent::onSaleCancelOrder', 'RetailCrm\RestApi::orderEdit::CurlException', $e->getCode() . ': ' . $e->getMessage() ); } return true; } /** * * @param type $ID -- orderId * @param type $payed -- Y / N - pay order status * @return boolean */ function onSalePayOrder($ID, $payed) { if(isset($GLOBALS['INTARO_CRM_FROM_HISTORY']) && $GLOBALS['INTARO_CRM_FROM_HISTORY']) return; if(!$ID || !$payed || ($payed != 'Y')) return true; if (!CModule::IncludeModule('iblock')) { //handle err ICrmOrderActions::eventLog('ICrmOrderEvent::onSalePayOrder', 'iblock', 'module not found'); return true; } if (!CModule::IncludeModule("sale")) { //handle err ICrmOrderActions::eventLog('ICrmOrderEvent::onSalePayOrder', 'sale', 'module not found'); return true; } if (!CModule::IncludeModule("catalog")) { //handle err ICrmOrderActions::eventLog('ICrmOrderEvent::onSalePayOrder', '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 $optionsPayment = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT, 0)); $api = new RetailCrm\RestApi($api_host, $api_key); $order = array( 'externalId' => (int) $ID, 'paymentStatus' => $optionsPayment[$payed] ); $log = new Logger(); $log->write($order, 'order'); try { $api->orderEdit($order); } catch (\RetailCrm\Exception\CurlException $e) { ICrmOrderActions::eventLog( 'ICrmOrderEvent::onSalePayOrder', 'RetailCrm\RestApi::orderEdit::CurlException', $e->getCode() . ': ' . $e->getMessage() ); } return true; } /** * * @param type $ID -- orderId * @param type $value -- ACCOUNT_NUMBER * @return boolean */ function onBeforeOrderAccountNumberSet($ID, $value) { if(isset($GLOBALS['ICRM_ACCOUNT_NUMBER']) && $GLOBALS['ICRM_ACCOUNT_NUMBER']) return $GLOBALS['ICRM_ACCOUNT_NUMBER']; return false; } }