1
0
mirror of synced 2024-11-21 12:56:11 +03:00

ref #87785 Добавление передачи сайта для корпоративных клиентов (#277)

This commit is contained in:
Kocmonavtik 2023-03-02 16:20:57 +03:00 committed by GitHub
parent 4c61df9701
commit 6cd01dd572
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 70 additions and 14 deletions

View File

@ -1,3 +1,6 @@
## 2023-02-16 v.6.1.16
- Добавление передачи магазина для корпоративных клиентов
## 2023-01-10 v.6.1.15
- Добавлен фильтр активности менеджеров

View File

@ -170,9 +170,9 @@ class RetailCrmEvent
if (
('Y' === $optionCorpClient)
&& true === RetailCrmCorporateClient::isCorpTookExternalId((string)$arOrder['USER_ID'], $api)
&& true === RetailCrmCorporateClient::isCorpTookExternalId((string)$arOrder['USER_ID'], $api, $site)
) {
RetailCrmCorporateClient::setPrefixForExternalId((string) $arOrder['USER_ID'], $api);
RetailCrmCorporateClient::setPrefixForExternalId((string) $arOrder['USER_ID'], $api, $site);
}
//TODO эта управляющая конструкция по функционалу дублирует RetailCrmOrder::createCustomerForOrder.

View File

@ -543,12 +543,15 @@ class RetailCrmOrder
$cachedCorporateIds = [];
foreach ($ordersPack as $lid => $lidOrdersList) {
$site = self::getCrmShopCodeByLid($lid, $arParams['optionsSitesList']);
foreach ($lidOrdersList as $key => $orderData) {
$lidOrdersList[$key] = self::addCorporateCustomerToOrder(
$orderData,
$api,
$resCustomersCorporate,
$cachedCorporateIds
$cachedCorporateIds,
$site
);
}
@ -605,8 +608,8 @@ class RetailCrmOrder
}
if ('Y' === RetailcrmConfigProvider::getCorporateClientStatus()) {
if (true === RetailCrmCorporateClient::isCorpTookExternalId((string) $user['ID'], $api)) {
RetailCrmCorporateClient::setPrefixForExternalId((string) $user['ID'], $api);
if (true === RetailCrmCorporateClient::isCorpTookExternalId((string) $user['ID'], $api, $site)) {
RetailCrmCorporateClient::setPrefixForExternalId((string) $user['ID'], $api, $site);
}
}
@ -665,7 +668,8 @@ class RetailCrmOrder
array $orderData,
ApiClient $api,
array $resCustomersCorporate,
array &$cachedCorporateIds
array &$cachedCorporateIds,
$site = null
): array {
$customerLegalName = $orderData['contragent']['legalName'];
@ -700,7 +704,8 @@ class RetailCrmOrder
);
} elseif (array_key_exists($customerLegalName, $resCustomersCorporate)) {
$createResponse = $api->customersCorporateCreate(
$resCustomersCorporate[$customerLegalName]
$resCustomersCorporate[$customerLegalName],
$site
);
if ($createResponse && $createResponse->isSuccessful()) {

View File

@ -170,13 +170,14 @@ class RetailCrmCorporateClient
*
* @return bool
*/
public static function isCorpTookExternalId(string $bitrixUserId, ApiClient $api): bool
public static function isCorpTookExternalId(string $bitrixUserId, ApiClient $api, $site = null): bool
{
$response = RCrmActions::apiMethod(
$api,
'customersCorporateGet',
__METHOD__,
$bitrixUserId
$bitrixUserId,
$site
);
if (false === $response) {
@ -194,7 +195,7 @@ class RetailCrmCorporateClient
* @param string $externalId
* @param \RetailCrm\ApiClient $api
*/
public static function setPrefixForExternalId(string $externalId, ApiClient $api)
public static function setPrefixForExternalId(string $externalId, ApiClient $api, $site = null)
{
$response = RCrmActions::apiMethod(
$api,
@ -203,7 +204,8 @@ class RetailCrmCorporateClient
[
'urlId' => $externalId,
'externalId' => self::CORP_PREFIX . $externalId
]
],
$site
);
if (false === $response) {

View File

@ -1 +1 @@
- Добавлен фильтр активности менеджеров
- Добавлена поддержка работы с корпоративными клиентами при мультисайтовости cms системы

View File

@ -1,6 +1,6 @@
<?php
$arModuleVersion = [
'VERSION' => '6.1.15',
'VERSION_DATE' => '2023-01-26 12:00:00'
'VERSION' => '6.1.16',
'VERSION_DATE' => '2023-02-16 12:00:00'
];

View File

@ -0,0 +1,46 @@
<?php
use RetailCrm\ApiClient;
use RetailCrm\Response\ApiResponse;
/**
* Class RetailCrmCorporateClientTest
*/
class RetailCrmCorporateClientTest extends \BitrixTestCase
{
public function setUp(): void
{
parent::setUp();
COption::SetOptionString('intaro.retailcrm', 'api_version', 'v5');
CModule::IncludeModule('intaro.retailcrm');
}
public function testCorpTookAndSetPrefix(): void
{
$apiClientMock = $this->getMockBuilder(ApiClient::class)
->disableOriginalConstructor()
->setMethods(['customersCorporateGet', 'customersCorporateEdit'])
->getMock()
;
$apiResponse = new ApiResponse('200', json_encode(['customerCorporate' => 'test']));
$apiClientMock
->method('customersCorporateGet')
->withAnyParameters()
->willReturn($apiResponse)
;
$response = \RetailCrmCorporateClient::isCorpTookExternalId('15', $apiClientMock, 'testSite');
$this->assertTrue($response);
$apiClientMock
->method('customersCorporateEdit')
->withAnyParameters()
->willReturn($apiResponse)
;
RetailCrmCorporateClient::setPrefixForExternalId(15, $apiClientMock, 'testSite');
}
}