1
0
mirror of synced 2024-11-21 21:06:09 +03:00

Добавлена передача поля link при выгрузке брошенных корзин (#352)

This commit is contained in:
Uryvskiy Dima 2024-07-15 17:24:27 +03:00 committed by GitHub
parent 1ab3dacaf7
commit 3e3e37b297
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 129 additions and 101 deletions

View File

@ -1,3 +1,6 @@
## 2024-07-15 v.6.5.21
- Добавлена передача поля link при выгрузке брошенных корзин
## 2024-06-20 v.6.5.20
- Рефакторинг настроек модуля

View File

@ -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']
);
}
}

View File

@ -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);

View File

@ -1 +1 @@
- Рефакторинг настроек модуля
- Добавлена передача поля link при выгрузке брошенных корзин

View File

@ -1,6 +1,6 @@
<?php
$arModuleVersion = [
'VERSION' => '6.5.20',
'VERSION_DATE' => '2024-06-20 17:40:00'
'VERSION' => '6.5.21',
'VERSION_DATE' => '2024-07-15 17:00:00'
];

View File

@ -0,0 +1,110 @@
<?php
namespace classes\general\cart;
use DateTime;
use Mockery;
use PHPUnit\Framework\TestCase;
use RCrmActions;
use RetailCrmCart;
class RetailCrmCartTest extends TestCase
{
/**
* @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);
}
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'
]
];
}
}

View File

@ -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'
]
];
}
}