From 6cd01dd5728ddefff24a07e7cec5bc9d3504c3ba Mon Sep 17 00:00:00 2001 From: Kocmonavtik <61938582+Kocmonavtik@users.noreply.github.com> Date: Thu, 2 Mar 2023 16:20:57 +0300 Subject: [PATCH] =?UTF-8?q?ref=20#87785=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B4?= =?UTF-8?q?=D0=B0=D1=87=D0=B8=20=D1=81=D0=B0=D0=B9=D1=82=D0=B0=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20=D0=BA=D0=BE=D1=80=D0=BF=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=B8=D0=B2=D0=BD=D1=8B=D1=85=20=D0=BA=D0=BB=D0=B8=D0=B5=D0=BD?= =?UTF-8?q?=D1=82=D0=BE=D0=B2=20(#277)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 3 ++ .../classes/general/events/RetailCrmEvent.php | 4 +- .../general/order/RetailCrmOrder_v5.php | 15 ++++-- .../general/user/RetailCrmCorporateClient.php | 10 ++-- intaro.retailcrm/description.ru | 2 +- intaro.retailcrm/install/version.php | 4 +- .../user/RetailCrmCorporateClientTest.php | 46 +++++++++++++++++++ 7 files changed, 70 insertions(+), 14 deletions(-) create mode 100644 tests/classes/general/user/RetailCrmCorporateClientTest.php 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