Fix existing customer in loyalty (#262)
This commit is contained in:
parent
d52974c7d1
commit
19fbf04f60
@ -1,4 +1,4 @@
|
|||||||
FROM php:7.1-apache
|
FROM php:7.3-apache
|
||||||
|
|
||||||
RUN a2enmod rewrite
|
RUN a2enmod rewrite
|
||||||
|
|
||||||
|
4
.github/workflows/ci.yml
vendored
4
.github/workflows/ci.yml
vendored
@ -20,7 +20,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
php-version: ['7.1', '7.2', '7.3']
|
php-version: ['7.3']
|
||||||
bitrix-edition: ['small_business_encode', 'business_encode']
|
bitrix-edition: ['small_business_encode', 'business_encode']
|
||||||
services:
|
services:
|
||||||
mysql:
|
mysql:
|
||||||
@ -42,7 +42,7 @@ jobs:
|
|||||||
- name: Install Bitrix
|
- name: Install Bitrix
|
||||||
env:
|
env:
|
||||||
BITRIX_EDITION: ${{ matrix.bitrix-edition }}
|
BITRIX_EDITION: ${{ matrix.bitrix-edition }}
|
||||||
run: make bitrix_install
|
run: make install_bitrix
|
||||||
- name: Enable debug mode for tests
|
- name: Enable debug mode for tests
|
||||||
run: php bin/enable_debugging "${{ env.BITRIX_PATH }}"
|
run: php bin/enable_debugging "${{ env.BITRIX_PATH }}"
|
||||||
- name: Validate composer.json and composer.lock
|
- name: Validate composer.json and composer.lock
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
## 2022-07-18 v.6.1.3
|
||||||
|
- Исправление работы модуля при попытки регистрации в программе лояльности уже существующего в ней клиента
|
||||||
|
- Исправлени тестов
|
||||||
|
|
||||||
## 2022-07-01 v.6.1.2
|
## 2022-07-01 v.6.1.2
|
||||||
- Исправление передачи корпоративных клиентов
|
- Исправление передачи корпоративных клиентов
|
||||||
|
|
||||||
|
11
Makefile
11
Makefile
@ -11,7 +11,7 @@ ifneq ($(NOT_USE_VENDOR),1)
|
|||||||
composer install
|
composer install
|
||||||
endif
|
endif
|
||||||
|
|
||||||
bitrix_install: download_bitrix
|
install_bitrix: download_bitrix
|
||||||
@echo "===== Installing Bitrix..."
|
@echo "===== Installing Bitrix..."
|
||||||
@php bin/bitrix-install db_type
|
@php bin/bitrix-install db_type
|
||||||
@php bin/bitrix-install requirement
|
@php bin/bitrix-install requirement
|
||||||
@ -43,11 +43,4 @@ endif
|
|||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
@rm -rf $(ROOT_DIR)/release/$(CURRENT_VERSION)
|
@rm -rf $(ROOT_DIR)/release/$(CURRENT_VERSION)
|
||||||
@rm $(ROOT_DIR)/release/$(CURRENT_VERSION).tar.gz
|
@rm $(ROOT_DIR)/release/$(CURRENT_VERSION).tar.gz
|
||||||
|
|
||||||
# docker commands
|
|
||||||
install:
|
|
||||||
docker-compose exec bitrix make bitrix_install
|
|
||||||
|
|
||||||
run_tests:
|
|
||||||
docker-compose exec bitrix make test
|
|
@ -19,6 +19,7 @@ services:
|
|||||||
volumes:
|
volumes:
|
||||||
- ./:/bitrix-module
|
- ./:/bitrix-module
|
||||||
- ./.docker/php.ini:/usr/local/etc/php/conf.d/z-bitrix.ini
|
- ./.docker/php.ini:/usr/local/etc/php/conf.d/z-bitrix.ini
|
||||||
|
- ./tmp:/tmp
|
||||||
mysql:
|
mysql:
|
||||||
env_file:
|
env_file:
|
||||||
- .env
|
- .env
|
||||||
|
@ -1 +1,2 @@
|
|||||||
- Исправление передачи корпоративных клиентов
|
- Исправление работы модуля при попытки регистрации в программе лояльности уже существующего в ней клиента
|
||||||
|
- Исправлени тестов
|
@ -58,7 +58,6 @@ foreach ($arJsConfig as $ext => $arExt) {
|
|||||||
|
|
||||||
if (empty(ConfigProvider::getSitesAvailable())) {
|
if (empty(ConfigProvider::getSitesAvailable())) {
|
||||||
$client = ClientFactory::createClientAdapter();
|
$client = ClientFactory::createClientAdapter();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$credentials = $client->getCredentials();
|
$credentials = $client->getCredentials();
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
$arModuleVersion = [
|
$arModuleVersion = [
|
||||||
'VERSION' => '6.1.2',
|
'VERSION' => '6.1.3',
|
||||||
'VERSION_DATE' => '2022-07-01 15:00:00'
|
'VERSION_DATE' => '2022-07-18 10:00:00'
|
||||||
];
|
];
|
||||||
|
@ -20,6 +20,8 @@ use Intaro\RetailCrm\Component\Factory\ClientFactory;
|
|||||||
use Intaro\RetailCrm\Component\Json\Serializer;
|
use Intaro\RetailCrm\Component\Json\Serializer;
|
||||||
use Intaro\RetailCrm\Component\ServiceLocator;
|
use Intaro\RetailCrm\Component\ServiceLocator;
|
||||||
use Intaro\RetailCrm\Model\Api\LoyaltyAccount;
|
use Intaro\RetailCrm\Model\Api\LoyaltyAccount;
|
||||||
|
use Intaro\RetailCrm\Model\Api\LoyaltyAccountApiFilterType;
|
||||||
|
use Intaro\RetailCrm\Model\Api\Request\Loyalty\Account\LoyaltyAccountRequest;
|
||||||
use Intaro\RetailCrm\Model\Api\Request\Loyalty\Account\LoyaltyAccountActivateRequest;
|
use Intaro\RetailCrm\Model\Api\Request\Loyalty\Account\LoyaltyAccountActivateRequest;
|
||||||
use Intaro\RetailCrm\Model\Api\Request\Loyalty\Account\LoyaltyAccountCreateRequest;
|
use Intaro\RetailCrm\Model\Api\Request\Loyalty\Account\LoyaltyAccountCreateRequest;
|
||||||
use Intaro\RetailCrm\Model\Api\Request\Loyalty\Account\LoyaltyAccountEditRequest;
|
use Intaro\RetailCrm\Model\Api\Request\Loyalty\Account\LoyaltyAccountEditRequest;
|
||||||
@ -144,9 +146,34 @@ class LoyaltyAccountService
|
|||||||
'UF_EXT_REG_PL_INTARO' => $createResponse->loyaltyAccount->active === true ? 'Y' : '',
|
'UF_EXT_REG_PL_INTARO' => $createResponse->loyaltyAccount->active === true ? 'Y' : '',
|
||||||
'UF_LP_ID_INTARO' => $createResponse->loyaltyAccount->id,
|
'UF_LP_ID_INTARO' => $createResponse->loyaltyAccount->id,
|
||||||
]);
|
]);
|
||||||
}
|
|
||||||
|
|
||||||
Utils::handleApiErrors($createResponse, GetMessage('REGISTER_ERROR'));
|
Utils::handleApiErrors($createResponse, GetMessage('REGISTER_ERROR'));
|
||||||
|
} elseif ($this->proveUserInLpExists($createResponse)) {
|
||||||
|
global $USER_FIELD_MANAGER;
|
||||||
|
|
||||||
|
/** @var \Intaro\RetailCrm\Component\ApiClient\ClientAdapter $client */
|
||||||
|
$client = ClientFactory::createClientAdapter();
|
||||||
|
|
||||||
|
$sitesAvailable = ConfigProvider::getSitesAvailable();
|
||||||
|
|
||||||
|
$getRequest = new LoyaltyAccountRequest();
|
||||||
|
|
||||||
|
$getRequest->filter = new LoyaltyAccountApiFilterType();
|
||||||
|
$getRequest->filter->sites = $sitesAvailable;
|
||||||
|
$getRequest->filter->customerExternalId = (string)$userId;
|
||||||
|
|
||||||
|
|
||||||
|
$getResponse = $client->getLoyaltyAccounts($getRequest);
|
||||||
|
|
||||||
|
if ($getResponse instanceof LoyaltyAccountCreateResponse) {
|
||||||
|
Utils::handleApiErrors($getResponse, GetMessage('REGISTER_ERROR'));
|
||||||
|
}
|
||||||
|
|
||||||
|
$USER_FIELD_MANAGER->Update('USER', $userId, [
|
||||||
|
'UF_EXT_REG_PL_INTARO' => ($getResponse->loyaltyAccounts)[0]->active === true ? 'Y' : '',
|
||||||
|
'UF_LP_ID_INTARO' => ($getResponse->loyaltyAccounts)[0]->id,
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -510,6 +537,20 @@ class LoyaltyAccountService
|
|||||||
|
|
||||||
$errorMsg = Utils::getErrorMsg($createResponse);
|
$errorMsg = Utils::getErrorMsg($createResponse);
|
||||||
|
|
||||||
|
if ($this->proveUserInLpExists($createResponse)) {
|
||||||
|
if (
|
||||||
|
$createResponse->loyaltyAccount->active === false
|
||||||
|
&& $createResponse->loyaltyAccount->activatedAt === null
|
||||||
|
) {
|
||||||
|
return [
|
||||||
|
'msg' => GetMessage('GO_TO_PERSONAL'),
|
||||||
|
'error' => false
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
return ['msg' => GetMessage('REG_COMPLETE'), 'error' => false];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($errorMsg !== null) {
|
if ($errorMsg !== null) {
|
||||||
return ['msg' => $errorMsg, 'error' => true];
|
return ['msg' => $errorMsg, 'error' => true];
|
||||||
}
|
}
|
||||||
@ -617,4 +658,26 @@ class LoyaltyAccountService
|
|||||||
|
|
||||||
return $resultFieldsArray;
|
return $resultFieldsArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \Intaro\RetailCrm\Model\Api\Response\Loyalty\Account\LoyaltyAccountCreateResponse|null $createResponse
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function proveUserInLpExists(?LoyaltyAccountCreateResponse $createResponse): bool
|
||||||
|
{
|
||||||
|
if (
|
||||||
|
$createResponse !== null
|
||||||
|
&& $createResponse->success !== true
|
||||||
|
&& isset($createResponse->errors)
|
||||||
|
&& isset(($createResponse->errors)['loyalty'])
|
||||||
|
&& ($createResponse->errors)['loyalty'] === 'The customer is in this loyalty program already'
|
||||||
|
) {
|
||||||
|
$response = true;
|
||||||
|
} else {
|
||||||
|
$response = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,12 +25,16 @@ require($_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/include/prolog_before.
|
|||||||
global $USER;
|
global $USER;
|
||||||
$USER->Authorize(1);
|
$USER->Authorize(1);
|
||||||
|
|
||||||
if (!IsModuleInstalled('intaro.retailcrm')) {
|
$retailcrmModuleId = 'intaro.retailcrm';
|
||||||
RegisterModule('intaro.retailcrm');
|
|
||||||
|
if (!IsModuleInstalled($retailcrmModuleId)) {
|
||||||
|
RegisterModule($retailcrmModuleId);
|
||||||
}
|
}
|
||||||
|
|
||||||
COption::SetOptionString('intaro.retailcrm', 'api_version', 'v5');
|
COption::SetOptionString($retailcrmModuleId, 'api_host', 'https://test.retailcrm.ru');
|
||||||
CModule::IncludeModule('intaro.retailcrm');
|
COption::SetOptionString($retailcrmModuleId, 'api_key', 'nvwhebvwevboihbwvoijn');
|
||||||
|
COption::SetOptionString($retailcrmModuleId, 'api_version', 'v5');
|
||||||
|
CModule::IncludeModule($retailcrmModuleId);
|
||||||
|
|
||||||
CModule::IncludeModule("main");
|
CModule::IncludeModule("main");
|
||||||
global $DB;
|
global $DB;
|
||||||
|
@ -151,7 +151,7 @@ class RetailCrmEventTest extends PHPUnit\Framework\TestCase
|
|||||||
|
|
||||||
$result = $this->retailcrmEvent->OrderDelete($event);
|
$result = $this->retailcrmEvent->OrderDelete($event);
|
||||||
|
|
||||||
$this->assertEquals(null, $result);
|
$this->assertEquals(true, $GLOBALS['RETAILCRM_ORDER_DELETE']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -160,11 +160,17 @@ class RetailCrmEventTest extends PHPUnit\Framework\TestCase
|
|||||||
*/
|
*/
|
||||||
public function testOnUpdateOrder()
|
public function testOnUpdateOrder()
|
||||||
{
|
{
|
||||||
$arFields = [];
|
$arFields = [
|
||||||
|
'CANCELED' => 'Y',
|
||||||
|
'BASKET_ITEMS' => [],
|
||||||
|
'ORDER_PROP' => []
|
||||||
|
];
|
||||||
|
|
||||||
$result = $this->retailcrmEvent->OnUpdateOrder(1, $arFields);
|
$result = $this->retailcrmEvent->OnUpdateOrder(1, $arFields);
|
||||||
|
|
||||||
$this->assertEquals(null, $result);
|
$this->assertEquals(true, $GLOBALS['RETAILCRM_ORDER_OLD_EVENT']);
|
||||||
|
|
||||||
|
$this->assertEquals(true, $GLOBALS['ORDER_DELETE_USER_ADMIN']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -116,7 +116,8 @@ class RetailCrmOrder_v5Test extends BitrixTestCase {
|
|||||||
'externalId' => RCrmActions::generatePaymentExternalId($arFields['PAYMENTS'][0]['ID']),
|
'externalId' => RCrmActions::generatePaymentExternalId($arFields['PAYMENTS'][0]['ID']),
|
||||||
'status' => 'paid',
|
'status' => 'paid',
|
||||||
'paidAt' => $this->getDateTime()->format('Y-m-d H:i:s')
|
'paidAt' => $this->getDateTime()->format('Y-m-d H:i:s')
|
||||||
]]
|
]],
|
||||||
|
'privilegeType' => 'none'
|
||||||
],
|
],
|
||||||
]];
|
]];
|
||||||
}
|
}
|
||||||
|
@ -33,4 +33,50 @@ class RetailCrmServiceTest extends PHPUnit\Framework\TestCase
|
|||||||
|
|
||||||
$this->assertEquals($newParams, $expectedArray);
|
$this->assertEquals($newParams, $expectedArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $data
|
||||||
|
* @param array $expected
|
||||||
|
* @dataProvider selectIntegrationDeliveriesProvider
|
||||||
|
*/
|
||||||
|
public function testSelectIntegrationDeliveries(array $data, array $expected)
|
||||||
|
{
|
||||||
|
$this->assertEquals($expected, RetailCrmService::selectIntegrationDeliveries($data));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $data
|
||||||
|
* @param array $expected
|
||||||
|
* @dataProvider selectIntegrationPaymentsProvider
|
||||||
|
*/
|
||||||
|
public function testSelectIntegrationPayments(array $data, array $expected)
|
||||||
|
{
|
||||||
|
$this->assertEquals($expected, RetailCrmService::selectIntegrationPayments($data));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function selectIntegrationDeliveriesProvider()
|
||||||
|
{
|
||||||
|
return [[
|
||||||
|
'data' => [
|
||||||
|
[
|
||||||
|
'code' => 'test1',
|
||||||
|
'integrationCode' => 'test2'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'expected' => ['test1' => 'test2']
|
||||||
|
]];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function selectIntegrationPaymentsProvider()
|
||||||
|
{
|
||||||
|
return [[
|
||||||
|
'data' => [
|
||||||
|
[
|
||||||
|
'code' => 'test1',
|
||||||
|
'integrationModule' => 'test2'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'expected' => ['test1']
|
||||||
|
]];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
78
tests/lib/service/LoyaltyAccountServiceTest.php
Normal file
78
tests/lib/service/LoyaltyAccountServiceTest.php
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Intaro\RetailCrm\Model\Api\Response\Loyalty\Account\LoyaltyAccountCreateResponse;
|
||||||
|
use Intaro\RetailCrm\Service\LoyaltyAccountService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class LoyaltyAccountService
|
||||||
|
*/
|
||||||
|
class LoyaltyAccountServiceTest extends BitrixTestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* setUp method
|
||||||
|
*/
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
COption::SetOptionString('intaro.retailcrm', 'api_version', 'v5');
|
||||||
|
CModule::IncludeModule('intaro.retailcrm');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param LoyaltyAccountCreateResponse $createResponse
|
||||||
|
* @param bool $expected
|
||||||
|
*
|
||||||
|
* @dataProvider proveUserInLpExistsProvider
|
||||||
|
*/
|
||||||
|
public function testProveUserInLpExists(LoyaltyAccountCreateResponse $createResponse, $expected)
|
||||||
|
{
|
||||||
|
self::assertEquals($expected,LoyaltyAccountService::proveUserInLpExists($createResponse));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param LoyaltyAccountCreateResponse $createResponse
|
||||||
|
* @param bool $expected
|
||||||
|
*
|
||||||
|
* @dataProvider proveNotUserInLpExistsProvider
|
||||||
|
*/
|
||||||
|
public function testNotProveUserInLpExists(LoyaltyAccountCreateResponse $createResponse, $expected)
|
||||||
|
{
|
||||||
|
self::assertEquals($expected,LoyaltyAccountService::proveUserInLpExists($createResponse));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array[]
|
||||||
|
*/
|
||||||
|
public function proveUserInLpExistsProvider()
|
||||||
|
{
|
||||||
|
$createResponse = new LoyaltyAccountCreateResponse();
|
||||||
|
$createResponse->success = false;
|
||||||
|
$createResponse->errors = [
|
||||||
|
'loyalty' => 'The customer is in this loyalty program already'
|
||||||
|
];
|
||||||
|
|
||||||
|
return [[
|
||||||
|
'createResponse' => $createResponse,
|
||||||
|
'expected' => true
|
||||||
|
]];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array[]
|
||||||
|
*/
|
||||||
|
public function proveNotUserInLpExistsProvider()
|
||||||
|
{
|
||||||
|
$createResponse = new LoyaltyAccountCreateResponse();
|
||||||
|
$createResponse->success = false;
|
||||||
|
$createResponse->errors = [
|
||||||
|
'loyalty' => 'Some other failure'
|
||||||
|
];
|
||||||
|
|
||||||
|
return [[
|
||||||
|
'createResponse' => $createResponse,
|
||||||
|
'expected' => false
|
||||||
|
]];
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user