From 6a07f5220b96e9644fc68320431897da1f78ab33 Mon Sep 17 00:00:00 2001 From: Kocmonavtik <61938582+Kocmonavtik@users.noreply.github.com> Date: Tue, 24 Jan 2023 15:54:48 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BE=D1=82=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BA=D0=B8=20=D0=B7=D0=B0=D0=BA=D0=B0=D0=B7=D0=B0=20=D0=B2=20?= =?UTF-8?q?=D1=86=D1=80=D0=BC=20=D1=81=D0=B8=D1=81=D1=82=D0=B5=D0=BC=D1=83?= =?UTF-8?q?=20(#275)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 4 +- intaro.retailcrm/description.ru | 2 +- intaro.retailcrm/install/version.php | 2 +- .../lib/component/handlers/eventshandlers.php | 19 +++--- .../component/handlers/EventsHandlersTest.php | 60 +++++++++++++++++++ 5 files changed, 76 insertions(+), 11 deletions(-) create mode 100644 tests/lib/component/handlers/EventsHandlersTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e88a31b..3f307b66 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ -## 2023-01-20 v.6.1.14 -- Исправление ошибки изменения отгрузки при её завершении +## 2023-01-24 v.6.1.14 +- Исправление обновления и отправки заказа в црм систему ## 2023-01-10 v.6.1.13 - Изменение метода обновления полей программы лояльности в административной панели diff --git a/intaro.retailcrm/description.ru b/intaro.retailcrm/description.ru index b970d9a6..bf6191b4 100644 --- a/intaro.retailcrm/description.ru +++ b/intaro.retailcrm/description.ru @@ -1 +1 @@ -- Изменение логики обновления полей программы лояльности в административной панели \ No newline at end of file +- исправление отправки заказа в црм систему \ No newline at end of file diff --git a/intaro.retailcrm/install/version.php b/intaro.retailcrm/install/version.php index 8defcce6..74f5adc4 100644 --- a/intaro.retailcrm/install/version.php +++ b/intaro.retailcrm/install/version.php @@ -2,5 +2,5 @@ $arModuleVersion = [ 'VERSION' => '6.1.14', - 'VERSION_DATE' => '2023-01-20 17:00:00' + 'VERSION_DATE' => '2023-01-24 14:30:00' ]; diff --git a/intaro.retailcrm/lib/component/handlers/eventshandlers.php b/intaro.retailcrm/lib/component/handlers/eventshandlers.php index 1d306671..84ebd13e 100644 --- a/intaro.retailcrm/lib/component/handlers/eventshandlers.php +++ b/intaro.retailcrm/lib/component/handlers/eventshandlers.php @@ -127,7 +127,18 @@ class EventsHandlers */ public function OnSaleOrderSavedHandler(Event $event): void { + if (self::$disableSaleHandler === true) { + return; + } + try { + /** @var Order $order */ + $order = $event->getParameter('ENTITY'); + + // TODO: Replace old call with a new one. + $saveResult = RetailCrmEvent::orderSave($order); + Utils::handleApiErrors($saveResult); + $isBonusInput = ( !empty($_POST['bonus-input']) && !empty($_POST['available-bonuses']) @@ -135,7 +146,7 @@ class EventsHandlers $isDataForLoyaltyDiscount = isset($_POST['calculate-items-input'], $_POST['loyalty-discount-input']); - if (self::$disableSaleHandler === true || !($isDataForLoyaltyDiscount || $isBonusInput) ) { + if (!($isDataForLoyaltyDiscount || $isBonusInput) ) { return; } @@ -144,12 +155,6 @@ class EventsHandlers /* @var OrderLoyaltyDataService $orderLoyaltyDataService */ $orderLoyaltyDataService = ServiceLocator::get(OrderLoyaltyDataService::class); - /** @var Order $order */ - $order = $event->getParameter('ENTITY'); - - // TODO: Replace old call with a new one. - $saveResult = RetailCrmEvent::orderSave($order); - Utils::handleApiErrors($saveResult); $bonusFloat = (float) $_POST['bonus-input']; diff --git a/tests/lib/component/handlers/EventsHandlersTest.php b/tests/lib/component/handlers/EventsHandlersTest.php new file mode 100644 index 00000000..ea55fbff --- /dev/null +++ b/tests/lib/component/handlers/EventsHandlersTest.php @@ -0,0 +1,60 @@ +setPersonTypeId(2); + + $event = $this->createMock(\Bitrix\Main\Event::class); + $event->method('getParameter')->willReturn($order); + + $spy = \Mockery::spy('overload:' .RetailCrmEvent::class); + + $onSaleOrderSaved = new EventsHandlers(); + $onSaleOrderSaved->OnSaleOrderSavedHandler($event); + + //Проверяет, был ли вызван метод класса. Если метод не вызывался, выдает ошибку теста + //Если метод вызывался, ошибку не выдает, но phpunit выдает сообщение об отсутствии тестов + $spy->shouldHaveReceived('orderSave'); + self::assertTrue(true); + } + + /** + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + public function testOnSaleOrderNotSavedHandler() + { + $order = \Bitrix\Sale\Order::create('s1', 2, 'RUB'); + $order->setPersonTypeId(2); + + $event = $this->createMock(\Bitrix\Main\Event::class); + $event->method('getParameter')->willReturn($order); + + $spy = \Mockery::spy('overload:' .RetailCrmEvent::class); + + $onSaleOrderSaved = new EventsHandlers(); + $onSaleOrderSaved::$disableSaleHandler = true; + $onSaleOrderSaved->OnSaleOrderSavedHandler($event); + + $spy->shouldNotHaveReceived('orderSave'); + self::assertTrue(true); + } +} \ No newline at end of file