diff --git a/CHANGELOG.md b/CHANGELOG.md index 30dd36e6..806b3a6e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 2023-02-16 v.6.1.16 +- Добавление передачи магазина для корпоративных клиентов + ## 2023-01-10 v.6.1.15 - Добавлен фильтр активности менеджеров diff --git a/intaro.retailcrm/classes/general/events/RetailCrmEvent.php b/intaro.retailcrm/classes/general/events/RetailCrmEvent.php index bc262e13..f77bd23b 100644 --- a/intaro.retailcrm/classes/general/events/RetailCrmEvent.php +++ b/intaro.retailcrm/classes/general/events/RetailCrmEvent.php @@ -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. diff --git a/intaro.retailcrm/classes/general/order/RetailCrmOrder_v5.php b/intaro.retailcrm/classes/general/order/RetailCrmOrder_v5.php index e77c7270..23a2eeb1 100644 --- a/intaro.retailcrm/classes/general/order/RetailCrmOrder_v5.php +++ b/intaro.retailcrm/classes/general/order/RetailCrmOrder_v5.php @@ -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()) { diff --git a/intaro.retailcrm/classes/general/user/RetailCrmCorporateClient.php b/intaro.retailcrm/classes/general/user/RetailCrmCorporateClient.php index a2d584e3..1e37b1c4 100644 --- a/intaro.retailcrm/classes/general/user/RetailCrmCorporateClient.php +++ b/intaro.retailcrm/classes/general/user/RetailCrmCorporateClient.php @@ -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) { diff --git a/intaro.retailcrm/description.ru b/intaro.retailcrm/description.ru index e7554ac1..5b903449 100644 --- a/intaro.retailcrm/description.ru +++ b/intaro.retailcrm/description.ru @@ -1 +1 @@ -- Добавлен фильтр активности менеджеров +- Добавлена поддержка работы с корпоративными клиентами при мультисайтовости cms системы diff --git a/intaro.retailcrm/install/version.php b/intaro.retailcrm/install/version.php index 009f5447..b31f7c70 100644 --- a/intaro.retailcrm/install/version.php +++ b/intaro.retailcrm/install/version.php @@ -1,6 +1,6 @@ '6.1.15', - 'VERSION_DATE' => '2023-01-26 12:00:00' + 'VERSION' => '6.1.16', + 'VERSION_DATE' => '2023-02-16 12:00:00' ]; diff --git a/tests/classes/general/user/RetailCrmCorporateClientTest.php b/tests/classes/general/user/RetailCrmCorporateClientTest.php new file mode 100644 index 00000000..083dc126 --- /dev/null +++ b/tests/classes/general/user/RetailCrmCorporateClientTest.php @@ -0,0 +1,46 @@ +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'); + } +} \ No newline at end of file