diff --git a/CHANGELOG.md b/CHANGELOG.md index adc5f804..48e3d9a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2016-10-06 v.2.0.4 +* Оптимизация History +* Исправлена ошибка выгрузки доставок при установке + ## 2016-10-04 v.2.0.3 * fix состава отгрузки diff --git a/intaro.retailcrm/classes/general/history/RetailCrmHistory.php b/intaro.retailcrm/classes/general/history/RetailCrmHistory.php index 01469a49..8b841162 100644 --- a/intaro.retailcrm/classes/general/history/RetailCrmHistory.php +++ b/intaro.retailcrm/classes/general/history/RetailCrmHistory.php @@ -443,6 +443,7 @@ class RetailCrmHistory } if (isset($order['externalId']) && $order['externalId']) { + $itemUpdate = false; $newOrder = Bitrix\Sale\Order::load($order['externalId']); if (!$newOrder instanceof \Bitrix\Sale\Order) { @@ -597,62 +598,67 @@ class RetailCrmHistory //items $basket = $newOrder->getBasket(); - - foreach ($order['items'] as $product) { - $item = self::getExistsItem($basket, 'catalog', $product['offer']['externalId']); - if (!$item) { - $item = $basket->createItem('catalog', $product['offer']['externalId']); - if ($item instanceof \Bitrix\Sale\Basket) { - $elem = self::getInfoElement(); - $item->setFields(array( - 'CURRENCY' => \Bitrix\Currency\CurrencyManager::getBaseCurrency(), - 'LID' => \Bitrix\Main\Context::getCurrent()->getSite(), - 'BASE_PRICE' => $product['initialPrice'], - 'NAME' => $elem['NAME'], - 'DETAIL_PAGE_URL' => $elem['URL'] - )); - } else { - RCrmActions::eventLog('RetailCrmHistory::orderHistory', 'createItem', 'Error item add'); + if (isset($order['items'])) { + $itemUpdate = true; + foreach ($order['items'] as $product) { + $item = self::getExistsItem($basket, 'catalog', $product['offer']['externalId']); + if (!$item) { + if($product['delete']){ + continue; + } + $item = $basket->createItem('catalog', $product['offer']['externalId']); + if ($item instanceof \Bitrix\Sale\Basket) { + $elem = self::getInfoElement(); + $item->setFields(array( + 'CURRENCY' => \Bitrix\Currency\CurrencyManager::getBaseCurrency(), + 'LID' => \Bitrix\Main\Context::getCurrent()->getSite(), + 'BASE_PRICE' => $product['initialPrice'], + 'NAME' => $elem['NAME'], + 'DETAIL_PAGE_URL' => $elem['URL'] + )); + } else { + RCrmActions::eventLog('RetailCrmHistory::orderHistory', 'createItem', 'Error item add'); + continue; + } + } + if ($product['delete']) { + $item->delete(); continue; } - } - if ($product['quantity']) { - $item->setFieldNoDemand('QUANTITY', $product['quantity']); - } - - if (array_key_exists('discount', $product) || array_key_exists('discountPercent', $product)) { - if (!isset($orderCrm)) { - try { - $orderCrm = $api->ordersGet($order['id'], 'id'); - } catch (\RetailCrm\Exception\CurlException $e) { - RCrmActions::eventLog( - 'RetailCrmHistory::orderHistory', 'RetailCrm\RestApi::ordersGet::CurlException', - $e->getCode() . ': ' . $e->getMessage() - ); + if ($product['quantity']) { + $item->setFieldNoDemand('QUANTITY', $product['quantity']); + } + + if (array_key_exists('discount', $product) || array_key_exists('discountPercent', $product)) { + if (!isset($orderCrm)) { + try { + $orderCrm = $api->ordersGet($order['id'], 'id'); + } catch (\RetailCrm\Exception\CurlException $e) { + RCrmActions::eventLog( + 'RetailCrmHistory::orderHistory', 'RetailCrm\RestApi::ordersGet::CurlException', + $e->getCode() . ': ' . $e->getMessage() + ); + } + } + + foreach ($orderCrm['order']['items'] as $itemCrm) { + if ($itemCrm['offer']['externalId'] == $product['offer']['externalId']) { + $itemCost = $itemCrm['initialPrice'] - $itemCrm['discount'] - round(($itemCrm['initialPrice'] / 100 * $itemCrm['discountPercent']), 2); + break; + } + } + + if (isset($itemCost) && $itemCost > 0) { + $item->setField('CUSTOM_PRICE', 'Y'); + $item->setField('PRICE', $itemCost); + $item->setField('DISCOUNT_NAME', ''); + $item->setField('DISCOUNT_VALUE', ''); } } - foreach ($orderCrm['order']['items'] as $itemCrm) { - if ($itemCrm['offer']['externalId'] == $product['offer']['externalId']) { - $itemCost = $itemCrm['initialPrice'] - $itemCrm['discount'] - round(($itemCrm['initialPrice'] / 100 * $itemCrm['discountPercent']), 2); - break; - } - } - - if (isset($itemCost) && $itemCost > 0) { - $item->setField('CUSTOM_PRICE', 'Y'); - $item->setField('PRICE', $itemCost); - $item->setField('DISCOUNT_NAME', ''); - $item->setField('DISCOUNT_VALUE', ''); - } + $basket->save(); } - - if ($product['delete']) { - $item->delete(); - } - $basket->save(); - } $orderSumm = 0; @@ -678,7 +684,8 @@ class RetailCrmHistory } //delivery - if (array_key_exists('code', $order['delivery'])/* || array_key_exists('service', $order['delivery'])*/) { + if (array_key_exists('code', $order['delivery'])) { + $itemUpdate = true; //если пусто, удаляем, если нет, update или add if (!isset($orderCrm)) { try { @@ -711,7 +718,9 @@ class RetailCrmHistory Bitrix\Sale\OrderTable::update($order['externalId'], array('MARKED' => 'N', 'EMP_MARKED_ID' => '', 'REASON_MARKED' => '')); - self::updateShipmentItem($order['externalId']); + if ($itemUpdate) { + self::updateShipmentItem($order['externalId']); + } if (function_exists('retailCrmAfterOrderSave')) { retailCrmAfterOrderSave($order); diff --git a/intaro.retailcrm/description.ru b/intaro.retailcrm/description.ru index 5fe3bdf3..1ccfa339 100644 --- a/intaro.retailcrm/description.ru +++ b/intaro.retailcrm/description.ru @@ -1 +1,2 @@ -- fix состава отгрузки \ No newline at end of file +- Оптимизация History +- Исправлена ошибка выгрузки доставок при установке \ No newline at end of file diff --git a/intaro.retailcrm/install/index.php b/intaro.retailcrm/install/index.php index c04fc146..8450c134 100644 --- a/intaro.retailcrm/install/index.php +++ b/intaro.retailcrm/install/index.php @@ -680,7 +680,8 @@ class intaro_retailcrm extends CModule } } elseif (htmlspecialchars(trim($_POST['delivery-types-export'])) == 'true') {//отправка доставок в црм // send to intaro crm and save delivery types! - foreach ($optionsDelivTypes as $deliveryType) { + $arDeliveryServiceAll = \Bitrix\Sale\Delivery\Services\Manager::getActiveList(); + foreach ($arResult['bitrixDeliveryTypesList'] as $deliveryType) { $load = true; try { $this->RETAIL_CRM_API->deliveryTypesEdit(RCrmActions::clearArr(array( @@ -698,7 +699,8 @@ class intaro_retailcrm extends CModule ); } if ($load) { - foreach ($optionsDelivTypes as $deliveryService) { + $deliveryTypesArr[$deliveryType['ID']] = $deliveryType['ID']; + foreach ($arDeliveryServiceAll as $deliveryService) { if ($deliveryService['PARENT_ID'] != 0 && $deliveryService['PARENT_ID'] == $deliveryType['ID']) { $srv = explode(':', $deliveryService['CODE']); if (count($srv) == 2) { @@ -710,7 +712,7 @@ class intaro_retailcrm extends CModule ))); } catch (\RetailCrm\Exception\CurlException $e) { RCrmActions::eventLog( - 'intaro.retailcrm/options.php', 'RetailCrm\ApiClient::deliveryServiceEdit::CurlException', + 'intaro.crm/install/index.php', 'RetailCrm\ApiClient::deliveryServiceEdit::CurlException', $e->getCode() . ': ' . $e->getMessage() ); } diff --git a/intaro.retailcrm/install/version.php b/intaro.retailcrm/install/version.php index d9f7cf70..87a40ad2 100644 --- a/intaro.retailcrm/install/version.php +++ b/intaro.retailcrm/install/version.php @@ -1,6 +1,6 @@ "2.0.3", - "VERSION_DATE" => "2016-10-04 18:00:00" + "VERSION" => "2.0.4", + "VERSION_DATE" => "2016-10-06 18:00:00" ); diff --git a/intaro.retailcrm/lang/ru/options.php b/intaro.retailcrm/lang/ru/options.php index d51766b4..670a4872 100644 --- a/intaro.retailcrm/lang/ru/options.php +++ b/intaro.retailcrm/lang/ru/options.php @@ -19,7 +19,7 @@ $MESS ['PAYMENT_N'] = 'Не оплачен'; $MESS ['LEGAL_DETAIL'] = 'Юридические и банковские реквизиты'; $MESS ['ORDER_CUSTOM'] = 'Кастомные поля'; $MESS ['ORDER_UPLOAD'] = 'Повторная выгрузка заказов'; -$MESS ['ORDER_NUMBERS'] = 'Номера заказов: '; +$MESS ['ORDER_NUMBER'] = 'Номера заказов: '; $MESS ['ORDER_UPLOAD_INFO'] = 'Для загрузки всех заказов нажмите кнопку «Начать выгрузку». Или перечислите необходимые ID заказов через запятую, интервалы через тире. Например: 1, 3, 5-10, 12, 13... и т.д.'; $MESS ['ICRM_OPTIONS_SUBMIT_TITLE'] = 'Сохранить настройки'; diff --git a/intaro.retailcrm/options.php b/intaro.retailcrm/options.php index 9b0e65bf..2d344ef1 100644 --- a/intaro.retailcrm/options.php +++ b/intaro.retailcrm/options.php @@ -930,7 +930,7 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) { - +