From 274fd7a9a4db50097066b59f96a85909a5b9f16e Mon Sep 17 00:00:00 2001 From: Grisha Pomadchin Date: Thu, 13 Mar 2014 12:58:52 +0400 Subject: [PATCH] event side effects (hisotry) fix --- .../classes/general/ICrmOrderActions.php | 8 +++++--- .../classes/general/events/ICrmOrderEvent.php | 12 ++++++++++-- intaro.intarocrm/install/version.php | 4 ++-- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/intaro.intarocrm/classes/general/ICrmOrderActions.php b/intaro.intarocrm/classes/general/ICrmOrderActions.php index 49c42114..29cd8ae2 100755 --- a/intaro.intarocrm/classes/general/ICrmOrderActions.php +++ b/intaro.intarocrm/classes/general/ICrmOrderActions.php @@ -368,10 +368,10 @@ class ICrmOrderActions $dateStart = $dateStart->format('Y-m-d H:i:s'); } - $dateFinish = new \DateTime(); - $orderHistory = $api->orderHistory($dateStart); + $dateStart = new \DateTime($dateStart); + // pushing existing orders foreach ($orderHistory as $order) { @@ -866,11 +866,13 @@ class ICrmOrderActions // set PAYED if($optionsPayment[$order['paymentStatus']]) CSaleOrder::PayOrder($order['externalId'], $optionsPayment[$order['paymentStatus']]); + + $dateStart = new \DateTime(); } } if(count($orderHistory)) - COption::SetOptionString(self::$MODULE_ID, self::$CRM_ORDER_HISTORY_DATE, $dateFinish->format('Y-m-d H:i:s')); + COption::SetOptionString(self::$MODULE_ID, self::$CRM_ORDER_HISTORY_DATE, $dateStart->format('Y-m-d H:i:s')); $USER->Logout(); if($realUser) $USER->Authorize($realUser); diff --git a/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php b/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php index d2bc424f..df3eed8f 100644 --- a/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php +++ b/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php @@ -59,6 +59,9 @@ class ICrmOrderEvent { * @param mixed $arFields - Order arFields for sending template */ function onSendOrderMail($ID, &$eventName, &$arFields) { + if(isset($GLOBALS['INTARO_CRM_FROM_HISTORY']) && $GLOBALS['INTARO_CRM_FROM_HISTORY']) + return; + if(self::writeDataOnOrderCreate($ID)) COption::SetOptionString(self::$MODULE_ID, self::$CRM_ORDER_LAST_ID, $ID); else { @@ -160,6 +163,9 @@ class ICrmOrderEvent { * @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; @@ -223,6 +229,9 @@ class ICrmOrderEvent { * @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; @@ -258,8 +267,7 @@ class ICrmOrderEvent { ); $api->orderEdit($order); - - + // error pushing order if ($api->getStatusCode() != 201) ICrmOrderActions::eventLog('ICrmOrderEvent::onSalePayOrder', 'IntaroCrm\RestApi::orderEdit', $api->getLastError()); diff --git a/intaro.intarocrm/install/version.php b/intaro.intarocrm/install/version.php index d04b3ed1..0d5f1cb3 100644 --- a/intaro.intarocrm/install/version.php +++ b/intaro.intarocrm/install/version.php @@ -1,5 +1,5 @@ "1.0.1", - "VERSION_DATE" => "2014-03-13 11:57:00", + "VERSION" => "0.5.3", + "VERSION_DATE" => "2014-01-28 12:55:00", ); \ No newline at end of file