diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f4b8d9a..c0bfd994 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 2024-07-15 v.6.5.21 +- Добавлена передача поля link при выгрузке брошенных корзин + ## 2024-06-20 v.6.5.20 - Рефакторинг настроек модуля diff --git a/intaro.retailcrm/classes/general/cart/RetailCrmCart_v5.php b/intaro.retailcrm/classes/general/cart/RetailCrmCart_v5.php index cc98454f..a6089ddd 100644 --- a/intaro.retailcrm/classes/general/cart/RetailCrmCart_v5.php +++ b/intaro.retailcrm/classes/general/cart/RetailCrmCart_v5.php @@ -105,6 +105,7 @@ class RetailCrmCart $date => date(self::$dateFormat), 'droppedAt' => date(self::$dateFormat), 'items' => $items, + 'link' => static::generateCartLink(), ], $site ); @@ -139,4 +140,13 @@ class RetailCrmCart return $arBasket; } + + public static function generateCartLink() + { + return sprintf( + '%s://%s/personal/cart', + !empty($_SERVER['HTTPS']) ? 'https' : 'http', + $_SERVER['HTTP_HOST'] + ); + } } diff --git a/intaro.retailcrm/classes/general/events/RetailCrmEvent.php b/intaro.retailcrm/classes/general/events/RetailCrmEvent.php index 7459c04a..7a916ef3 100644 --- a/intaro.retailcrm/classes/general/events/RetailCrmEvent.php +++ b/intaro.retailcrm/classes/general/events/RetailCrmEvent.php @@ -10,6 +10,7 @@ */ use Bitrix\Main\Context\Culture; +use Bitrix\Main\Engine\CurrentUser; use Intaro\RetailCrm\Component\Constants; use Intaro\RetailCrm\Component\ServiceLocator; use Intaro\RetailCrm\Repository\UserRepository; @@ -113,8 +114,6 @@ class RetailCrmEvent public static function orderDelete($event) { $GLOBALS['RETAILCRM_ORDER_DELETE'] = true; - - return; } /** @@ -130,7 +129,7 @@ class RetailCrmEvent return; } - $id = \Bitrix\Main\Engine\CurrentUser::get()->getId(); + $id = CurrentUser::get()->getId(); if ($id) { $arBasket = RetailCrmCart::getBasketArray($event); diff --git a/intaro.retailcrm/description.ru b/intaro.retailcrm/description.ru index e65e0a05..64484a9b 100644 --- a/intaro.retailcrm/description.ru +++ b/intaro.retailcrm/description.ru @@ -1 +1 @@ -- Рефакторинг настроек модуля +- Добавлена передача поля link при выгрузке брошенных корзин diff --git a/intaro.retailcrm/install/version.php b/intaro.retailcrm/install/version.php index 09c380d0..16f903d2 100644 --- a/intaro.retailcrm/install/version.php +++ b/intaro.retailcrm/install/version.php @@ -1,6 +1,6 @@ '6.5.20', - 'VERSION_DATE' => '2024-06-20 17:40:00' + 'VERSION' => '6.5.21', + 'VERSION_DATE' => '2024-07-15 17:00:00' ]; diff --git a/tests/classes/general/cart/RetailCrmCartTest.php b/tests/classes/general/cart/RetailCrmCartTest.php new file mode 100644 index 00000000..3e610aae --- /dev/null +++ b/tests/classes/general/cart/RetailCrmCartTest.php @@ -0,0 +1,110 @@ +getBasket(); + $crmBasket = $this->getCrmCart(); + $actionsMock = Mockery::mock('alias:' . RCrmActions::class); + + $actionsMock->shouldReceive('apiMethod')->withAnyArgs()->andReturn($crmBasket, ['success' => true]); + + $result = RetailCrmCart::handlerCart($arBasket); + + self::assertTrue($result['success']); + } + + /** + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + public function testClearBasket(): void + { + $arBasket = ['LID' => 's1', 'USER_ID' => '1']; + $crmBasket = $this->getCrmCart(); + $actionsMock = Mockery::mock('alias:' . RCrmActions::class); + + $actionsMock->shouldReceive('apiMethod')->withAnyArgs()->andReturn($crmBasket, ['success' => true]); + + $result = RetailCrmCart::handlerCart($arBasket); + + self::assertTrue($result['success']); + } + + /** + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + public function testIgnoreChangeBasket() + { + $arBasket = ['LID' => 's1', 'USER_ID' => '1']; + $crmBasket = []; + $actionsMock = Mockery::mock('alias:' . RCrmActions::class); + + $actionsMock->shouldReceive('apiMethod')->withAnyArgs()->andReturn($crmBasket); + + $result = RetailCrmCart::handlerCart($arBasket); + + self::assertNull($result); + } + + public function testGenerateCartLink() + { + $cartLink = RetailCrmCart::generateCartLink(); + + self::assertNotNull($cartLink); + self::assertContains('/personal/cart', $cartLink); + } + + /** + * @return array + */ + public function getBasket(): array + { + return [ + 'LID' => 's1', + 'USER_ID' => '1', + 'BASKET' => [ + [ + 'QUANTITY' => 2, + 'PRICE' => 100, + 'DATE_INSERT' => new DateTime('now'), + 'DATE_UPDATE' => new DateTime('now'), + 'PRODUCT_ID' => '10' + ], + [ + 'QUANTITY' => 1, + 'PRICE' => 300, + 'DATE_INSERT' => new DateTime('now'), + 'DATE_UPDATE' => new DateTime('now'), + 'PRODUCT_ID' => '2' + ], + ], + ]; + } + + /** + * @return array + */ + public function getCrmCart(): array + { + return [ + 'cart' => [ + 'items' => 'items' + ] + ]; + } +} diff --git a/tests/classes/general/events/RetailCrmEventTest.php b/tests/classes/general/events/RetailCrmEventTest.php index 9254896e..010ec9b6 100755 --- a/tests/classes/general/events/RetailCrmEventTest.php +++ b/tests/classes/general/events/RetailCrmEventTest.php @@ -271,67 +271,12 @@ class RetailCrmEventTest extends PHPUnit\Framework\TestCase 'ORDER_PROP' => [] ]; - $result = RetailCrmEvent::OnUpdateOrder(1, $arFields); + RetailCrmEvent::OnUpdateOrder(1, $arFields); $this->assertEquals(true, $GLOBALS['RETAILCRM_ORDER_OLD_EVENT']); - $this->assertEquals(true, $GLOBALS['ORDER_DELETE_USER_ADMIN']); } - /** - * @runInSeparateProcess - * @preserveGlobalState disabled - */ - public function testSetBasket(): void - { - $arBasket = $this->getBasket(); - $crmBasket = $this->getCrmCart(); - - $actionsMock = Mockery::mock('alias:' . RCrmActions::class); - - $actionsMock->shouldReceive('apiMethod')->withAnyArgs()->andReturn($crmBasket, ['success' => true]); - - $result = RetailCrmCart::handlerCart($arBasket); - - self::assertTrue($result['success']); - } - - /** - * @runInSeparateProcess - * @preserveGlobalState disabled - */ - public function testClearBasket(): void - { - $arBasket = ['LID' => 's1', 'USER_ID' => '1']; - $crmBasket = $this->getCrmCart(); - - $actionsMock = Mockery::mock('alias:' . RCrmActions::class); - - $actionsMock->shouldReceive('apiMethod')->withAnyArgs()->andReturn($crmBasket, ['success' => true]); - - $result = RetailCrmCart::handlerCart($arBasket); - - self::assertTrue($result['success']); - } - - /** - * @runInSeparateProcess - * @preserveGlobalState disabled - */ - public function testIgnoreChangeBasket() - { - $arBasket = ['LID' => 's1', 'USER_ID' => '1']; - $crmBasket = []; - - $actionsMock = Mockery::mock('alias:' . RCrmActions::class); - - $actionsMock->shouldReceive('apiMethod')->withAnyArgs()->andReturn($crmBasket); - - $result = RetailCrmCart::handlerCart($arBasket); - - self::assertNull($result); - } - /** * @return array */ @@ -392,43 +337,4 @@ class RetailCrmEventTest extends PHPUnit\Framework\TestCase $GLOBALS['RETAILCRM_ORDER_OLD_EVENT'] = true; $GLOBALS['RETAILCRM_ORDER_DELETE'] = false; } - - /** - * @return array - */ - public function getBasket(): array - { - return [ - 'LID' => 's1', - 'USER_ID' => '1', - 'BASKET' => [ - [ - 'QUANTITY' => 2, - 'PRICE' => 100, - 'DATE_INSERT' => new DateTime('now'), - 'DATE_UPDATE' => new DateTime('now'), - 'PRODUCT_ID' => '10' - ], - [ - 'QUANTITY' => 1, - 'PRICE' => 300, - 'DATE_INSERT' => new DateTime('now'), - 'DATE_UPDATE' => new DateTime('now'), - 'PRODUCT_ID' => '2' - ], - ], - ]; - } - - /** - * @return array - */ - public function getCrmCart(): array - { - return [ - 'cart' => [ - 'items' => 'items' - ] - ]; - } }