diff --git a/intaro.intarocrm/classes/general/ICrmOrderActions.php b/intaro.intarocrm/classes/general/ICrmOrderActions.php index 13e7c9b2..9099e0a3 100755 --- a/intaro.intarocrm/classes/general/ICrmOrderActions.php +++ b/intaro.intarocrm/classes/general/ICrmOrderActions.php @@ -490,12 +490,18 @@ class ICrmOrderActions $GLOBALS['INTARO_CRM_FROM_HISTORY'] = true; + // clear intarocrm user basket + CSaleBasket::DeleteAll($USER->GetID()); + // pushing existing orders foreach ($orderHistory as $order) { + if(function_exists('intarocrm_order_pre_persist')) { + $order = intarocrm_order_pre_persist($order); + } if(!isset($order['externalId']) || !$order['externalId']) { - // custom orderType functunion + // custom orderType function if(function_exists('intarocrm_set_order_type')) { $orderType = intarocrm_set_order_type($order); if($orderType) @@ -997,12 +1003,19 @@ class ICrmOrderActions // set PAYED if(isset($order['paymentStatus']) && $order['paymentStatus'] && $optionsPayment[$order['paymentStatus']]) CSaleOrder::PayOrder($order['externalId'], $optionsPayment[$order['paymentStatus']]); + + if(function_exists('intarocrm_order_post_persist')) { + intarocrm_order_post_persist($order); + } } } if(count($orderHistory)) COption::SetOptionString(self::$MODULE_ID, self::$CRM_ORDER_HISTORY_DATE, $dateFinish->format('Y-m-d H:i:s')); + // clear intarocrm user basket + CSaleBasket::DeleteAll($USER->GetID()); + $USER->Logout(); if($realUser) $USER->Authorize($realUser); diff --git a/intaro.intarocrm/classes/general/RestApi.php b/intaro.intarocrm/classes/general/RestApi.php index ac2be520..b201f748 100644 --- a/intaro.intarocrm/classes/general/RestApi.php +++ b/intaro.intarocrm/classes/general/RestApi.php @@ -1,4 +1,5 @@ apiUrl.'orders/'.$id.'/delete'; - if ($by != 'externalId') - $this->parameters['by'] = $by; - $result = $this->curlRequest($url, 'POST'); - return $result; - }*/ - /** * Получение последних измененных заказов * - * @param DateTime $startDate - начальная дата выборки - * @param DateTime $endDate - конечная дата + * @param \DateTime|string|int $startDate - начальная дата и время выборки (Y-m-d H:i:s) + * @param \DateTime|string|int $endDate - конечная дата и время выборки (Y-m-d H:i:s) * @param int $limit - ограничение на размер выборки * @param int $offset - сдвиг * @return array - массив заказов @@ -134,9 +118,8 @@ class RestApi public function orderHistory($startDate = null, $endDate = null, $limit = 100, $offset = 0) { $url = $this->apiUrl.'orders/history'; - $this->parameters['skipMyChanges'] = true; - $this->parameters['startDate'] = $startDate; - $this->parameters['endDate'] = $endDate; + $this->parameters['startDate'] = $this->ensureDateTime($startDate); + $this->parameters['endDate'] = $this->ensureDateTime($endDate); $this->parameters['limit'] = $limit; $this->parameters['offset'] = $offset; @@ -144,7 +127,6 @@ class RestApi return $result; } - /* Методы для работы с клиентами */ /** * Получение клиента по id @@ -175,9 +157,9 @@ class RestApi public function customers($phone = null, $email = null, $fio = null, $limit = 200, $offset = 0) { $url = $this->apiUrl.'customers'; - $this->parameters['phone'] = $phone; - $this->parameters['email'] = $email; - $this->parameters['fio'] = $fio; + if($phone) $this->parameters['phone'] = $phone; + if($email) $this->parameters['email'] = $email; + if($fio) $this->parameters['fio'] = $fio; $this->parameters['limit'] = $limit; $this->parameters['offset'] = $offset; @@ -251,30 +233,13 @@ class RestApi return $result; } - /** - * Удаление клиента - * - * @param string $id - идентификатор - * @param string $by - поиск заказа по id или externalId - * @return array - */ - /* - public function customerDelete($id, $by = 'externalId') - { - $url = $this->apiUrl.'customers/'.$id.'/delete'; - if ($by != 'externalId') - $this->parameters['by'] = $by; - $result = $this->curlRequest($url, 'POST'); - return $result; - }*/ - /** * Получение списка заказов клиента * * @param string $id - идентификатор клиента * @param string $by - поиск заказа по id или externalId - * @param DateTime $startDate - начальная дата выборки - * @param DateTime $endDate - конечная дата + * @param \DateTime|string|int $startDate - начальная дата выборки (Y-m-d H:i:s) + * @param \DateTime|string|int $endDate - конечная дата выборки (Y-m-d H:i:s) * @param int $limit - ограничение на размер выборки * @param int $offset - сдвиг * @return array - массив заказов @@ -285,8 +250,8 @@ class RestApi $url = $this->apiUrl.'customers/'.$id.'/orders'; if ($by != 'externalId') $this->parameters['by'] = $by; - $this->parameters['startDate'] = $startDate; - $this->parameters['endDate'] = $endDate; + $this->parameters['startDate'] = $this->ensureDateTime($startDate); + $this->parameters['endDate'] = $this->ensureDateTime($endDate); $this->parameters['limit'] = $limit; $this->parameters['offset'] = $offset; @@ -523,10 +488,22 @@ class RestApi /** * @return \DateTime */ - public function getGeneratedAt() { + public function getGeneratedAt() + { return $this->generatedAt; } + protected function ensureDateTime($value) + { + if ($value instanceof \DateTime) { + return $value->format('Y-m-d H:i:s'); + } elseif (is_int($value)) { + return date('Y-m-d H:i:s', $value); + } + + return $value; + } + protected function getErrorMessage($response) { $str = ''; diff --git a/intaro.intarocrm/install/version.php b/intaro.intarocrm/install/version.php index 0716cc3d..9473b577 100644 --- a/intaro.intarocrm/install/version.php +++ b/intaro.intarocrm/install/version.php @@ -1,5 +1,5 @@ "1.0.14", - "VERSION_DATE" => "2014-11-09 19:51:00" + "VERSION" => "1.0.15", + "VERSION_DATE" => "2014-11-18 17:00:00" );