From c7aad78e5f2caf765ffe67ed8661d83971797bc6 Mon Sep 17 00:00:00 2001 From: Uryvskiy Dima Date: Tue, 28 Mar 2023 18:12:03 +0300 Subject: [PATCH] =?UTF-8?q?ref=20#87970=20=D0=9F=D0=B5=D1=80=D0=B5=D0=B4?= =?UTF-8?q?=D0=B0=D1=87=D0=B0=20=D0=BC=D0=B5=D0=BD=D0=B5=D0=B4=D0=B6=D0=B5?= =?UTF-8?q?=D1=80=D0=B0=20=D0=BF=D1=80=D0=B8=20=D0=B8=D0=B7=D0=BC=D0=B5?= =?UTF-8?q?=D0=BD=D0=B5=D0=BD=D0=B8=20=D0=B7=D0=B0=D0=BA=D0=B0=D0=B7=D0=B0?= =?UTF-8?q?=20=D0=BF=D0=BE=20=D0=B8=D1=81=D1=82=D0=BE=D1=80=D0=B8=D0=B8=20?= =?UTF-8?q?(#280)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 3 +++ .../general/history/RetailCrmHistory_v5.php | 27 ++++++++++++++----- intaro.retailcrm/description.ru | 2 +- intaro.retailcrm/install/version.php | 4 +-- .../history/RetailCrmHistory_v5Test.php | 13 +++++++++ 5 files changed, 40 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 32070810..f365eeb8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 2023-03-17 v.6.2.1 +- Добавлена передача менеджера при изменении заказа по истории + ## 2023-03-10 v.6.2.0 - Добавлена поддержка PHP 8.0 diff --git a/intaro.retailcrm/classes/general/history/RetailCrmHistory_v5.php b/intaro.retailcrm/classes/general/history/RetailCrmHistory_v5.php index 6d137cc7..ddcce3ab 100644 --- a/intaro.retailcrm/classes/general/history/RetailCrmHistory_v5.php +++ b/intaro.retailcrm/classes/general/history/RetailCrmHistory_v5.php @@ -494,11 +494,7 @@ class RetailCrmHistory $newOrder = Order::create($site, $orderCustomerExtId, $currency); - if (array_key_exists('managerId', $order)) { - $service = ManagerService::getInstance(); - - $newOrder->setField('RESPONSIBLE_ID', $service->getManagerBitrixId($order['managerId'])); - } + self::setManager($newOrder, $order); if (isset($buyerProfileToAppend['ID']) && isset($optionsLegalDetails['legalName'])) { $newOrder->setFields([ @@ -564,6 +560,8 @@ class RetailCrmHistory continue; } + self::setManager($newOrder, $order); + $propsRemove = false; $personType = $newOrder->getField('PERSON_TYPE_ID'); @@ -608,7 +606,10 @@ class RetailCrmHistory if ($optionsPayStatuses[$order['status']]) { $newOrder->setField('STATUS_ID', $optionsPayStatuses[$order['status']]); - if (in_array($optionsPayStatuses[$order['status']], $optionsCanselOrder)) { + if ( + is_array($optionsCanselOrder) + && in_array($optionsPayStatuses[$order['status']], $optionsCanselOrder) + ) { self::unreserveShipment($newOrder); $newOrder->setFieldNoDemand('CANCELED', 'Y'); } else { @@ -1948,6 +1949,20 @@ class RetailCrmHistory return false; } + public static function setManager($newOrder, $order) + { + if (array_key_exists('managerId', $order)) { + $service = ManagerService::getInstance(); + + $newOrder->setField('RESPONSIBLE_ID', $service->getManagerBitrixId($order['managerId'])); + + // If the order exists in CRM, need to save the changes in the CMS order + if (!empty($order['externalId'])) { + self::orderSave($newOrder); + } + } + } + public static function getInfoElement($offerId) { $elementInfo = CIBlockElement::GetByID($offerId)->fetch(); diff --git a/intaro.retailcrm/description.ru b/intaro.retailcrm/description.ru index 3fe9bc9e..61b31c05 100644 --- a/intaro.retailcrm/description.ru +++ b/intaro.retailcrm/description.ru @@ -1 +1 @@ -- Добавлена поддержка PHP 8.0 +- Добавлена передача менеджера при изменении заказа по истории diff --git a/intaro.retailcrm/install/version.php b/intaro.retailcrm/install/version.php index 447e0a59..68cf856d 100644 --- a/intaro.retailcrm/install/version.php +++ b/intaro.retailcrm/install/version.php @@ -1,6 +1,6 @@ '6.2.0', - 'VERSION_DATE' => '2023-03-10 12:00:00' + 'VERSION' => '6.2.1', + 'VERSION_DATE' => '2023-03-17 18:00:00' ]; diff --git a/tests/classes/general/history/RetailCrmHistory_v5Test.php b/tests/classes/general/history/RetailCrmHistory_v5Test.php index 72888cee..b2277517 100644 --- a/tests/classes/general/history/RetailCrmHistory_v5Test.php +++ b/tests/classes/general/history/RetailCrmHistory_v5Test.php @@ -1,6 +1,7 @@ assertEquals(null, RetailCrmHistory::shipmentItemReset($order)); } + public function testSetManager() + { + $currency = CurrencyManager::getBaseCurrency(); + $cmsOrder = Order::create('bitrix', 1, $currency); + $crmManagerId = 123; + + RetailcrmConfigProvider::setUsersMap(['bitrixUserId-1515' => $crmManagerId]); + RetailCrmHistory::setManager($cmsOrder, ['externalId' => 1, 'managerId' => $crmManagerId]); + + $this->assertEquals(1515, $cmsOrder->getField('RESPONSIBLE_ID')); + } + private function getCustomers(): array { return [