1
0
mirror of synced 2024-11-21 21:06:09 +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 ## 2023-01-10 v.6.1.15
- Добавлен фильтр активности менеджеров - Добавлен фильтр активности менеджеров

View File

@ -170,9 +170,9 @@ class RetailCrmEvent
if ( if (
('Y' === $optionCorpClient) ('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. //TODO эта управляющая конструкция по функционалу дублирует RetailCrmOrder::createCustomerForOrder.

View File

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

View File

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

View File

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

View File

@ -1,6 +1,6 @@
<?php <?php
$arModuleVersion = [ $arModuleVersion = [
'VERSION' => '6.1.15', 'VERSION' => '6.1.16',
'VERSION_DATE' => '2023-01-26 12:00:00' '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');
}
}