From 555d7e25137a1d3e0125c0af8a6c3a4a7c3161c1 Mon Sep 17 00:00:00 2001
From: Kocmonavtik <61938582+Kocmonavtik@users.noreply.github.com>
Date: Wed, 7 Jun 2023 14:39:34 +0300
Subject: [PATCH] =?UTF-8?q?ref=20#90085=20=D0=9F=D1=80=D0=BE=D0=B2=D0=B5?=
=?UTF-8?q?=D1=80=D0=BA=D0=B0=20=D0=BD=D0=B0=20=D0=B4=D0=BE=D1=81=D1=82?=
=?UTF-8?q?=D1=83=D0=BF=D0=BD=D0=BE=D1=81=D1=82=D1=8C=20=D1=82=D0=B8=D0=BF?=
=?UTF-8?q?=D0=B0=20=D0=BE=D0=BF=D0=BB=D0=B0=D1=82=20=D0=B8=20=D0=B4=D0=BE?=
=?UTF-8?q?=D1=81=D1=82=D0=B0=D0=B2=D0=BE=D0=BA=20=D0=B4=D0=BB=D1=8F=20?=
=?UTF-8?q?=D1=82=D0=B5=D0=BA=D1=83=D1=89=D0=B5=D0=B3=D0=BE=20=D0=BC=D0=B0?=
=?UTF-8?q?=D0=B3=D0=B0=D0=B7=D0=B8=D0=BD=D0=B0=20=D0=B4=D0=BB=D1=8F=20?=
=?UTF-8?q?=D0=BD=D0=B0=D1=81=D1=82=D1=80=D0=BE=D0=B9=D0=BA=D0=B8=20=D0=BC?=
=?UTF-8?q?=D0=BE=D0=B4=D1=83=D0=BB=D1=8F=20(#295)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
CHANGELOG.md | 5 ++
.../general/services/RetailCrmService.php | 30 ++++++++
intaro.retailcrm/description.ru | 2 +-
intaro.retailcrm/install/index.php | 25 ++++---
intaro.retailcrm/install/step2.php | 43 +++++++-----
intaro.retailcrm/install/version.php | 4 +-
intaro.retailcrm/options.php | 70 +++++++++++--------
.../general/services/RetailCrmServiceTest.php | 14 ++++
tests/datasets/DataService.php | 42 +++++++++++
9 files changed, 178 insertions(+), 57 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index efd54dff..0ca02f90 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,6 @@
+## 2023-06-02 v.6.3.10
+- Добавлено ограничение по магазинам для типов доставок и оплат
+
## 2023-06-01 v.6.3.9
- Исправление ошибок генерации ICML каталога при установке модуля
@@ -10,6 +13,8 @@
## 2023-05-19 v.6.3.6
- В настройки добавлена опция деактивации модуля
+## 2023-05-18 v.6.3.5
+- Добавлен функционал обновления номера телефона, адреса и других полей заказа, связанных с курьерской доставкой
## 2023-04-26 v.6.3.4
- Оптимизирован алгоритм получения истории заказов и клиентов
diff --git a/intaro.retailcrm/classes/general/services/RetailCrmService.php b/intaro.retailcrm/classes/general/services/RetailCrmService.php
index 68ef1b87..d889cffa 100644
--- a/intaro.retailcrm/classes/general/services/RetailCrmService.php
+++ b/intaro.retailcrm/classes/general/services/RetailCrmService.php
@@ -124,4 +124,34 @@ class RetailCrmService
true
);
}
+
+ /**
+ * @param array|null $availableSites
+ * @param array|null $types
+ *
+ * @return array
+ */
+ public static function getAvailableTypes(?array $availableSites, ?array $types)
+ {
+ $result = [];
+
+ foreach ($types as $type) {
+ if ($type['active'] !== true) {
+ continue;
+ }
+
+ if (empty($type['sites'])) {
+ $result[] = $type;
+ } else {
+ foreach ($type['sites'] as $site) {
+ if (!empty($availableSites[$site])) {
+ $result[] = $type;
+ break;
+ }
+ }
+ }
+ }
+
+ return $result;
+ }
}
diff --git a/intaro.retailcrm/description.ru b/intaro.retailcrm/description.ru
index 490f0d30..6510969c 100644
--- a/intaro.retailcrm/description.ru
+++ b/intaro.retailcrm/description.ru
@@ -1 +1 @@
-- Исправление ошибок генерации ICML каталога при установке модуля
\ No newline at end of file
+- Добавлено ограничение по магазинам для типов доставок и оплат
\ No newline at end of file
diff --git a/intaro.retailcrm/install/index.php b/intaro.retailcrm/install/index.php
index 16c0d213..539abd35 100644
--- a/intaro.retailcrm/install/index.php
+++ b/intaro.retailcrm/install/index.php
@@ -455,14 +455,25 @@ class intaro_retailcrm extends CModule
return false;
}
- $delivTypes = [];
- foreach ($arResult['deliveryTypesList'] as $delivType) {
- if ($delivType['active'] === true) {
- $delivTypes[$delivType['code']] = $delivType;
- }
+ $this->loadDeps();
+
+ $availableSites = RetailcrmConfigProvider::getSitesList();
+
+ if (!empty($availableSites)) {
+ $availableSites = array_flip($availableSites);
+ } else {
+ $site = RetailcrmConfigProvider::getSitesAvailable();
+ $availableSites[$site] = $site;
}
- $this->loadDeps();
+ $arResult['deliveryTypesList'] = RetailCrmService::getAvailableTypes(
+ $availableSites,
+ $arResult['deliveryTypesList']
+ );
+ $arResult['paymentTypesList'] = RetailCrmService::getAvailableTypes(
+ $availableSites,
+ $arResult['paymentTypesList']
+ );
RetailcrmConfigProvider::setIntegrationDelivery(
RetailCrmService::selectIntegrationDeliveries($arResult['deliveryTypesList'])
@@ -472,8 +483,6 @@ class intaro_retailcrm extends CModule
RetailCrmService::selectIntegrationPayments($arResult['paymentTypesList'])
);
- $arResult['deliveryTypesList'] = $delivTypes;
-
//bitrix personTypes
$arResult['bitrixOrderTypesList'] = RCrmActions::OrderTypesList($arResult['arSites']);
diff --git a/intaro.retailcrm/install/step2.php b/intaro.retailcrm/install/step2.php
index 8c7546a9..ee59b0c9 100644
--- a/intaro.retailcrm/install/step2.php
+++ b/intaro.retailcrm/install/step2.php
@@ -24,6 +24,15 @@ $RETAIL_CRM_API = new ApiClient($api_host, $api_key);
COption::SetOptionString($MODULE_ID, $CRM_API_HOST_OPTION, $api_host);
COption::SetOptionString($MODULE_ID, $CRM_API_KEY_OPTION, $api_key);
+$availableSites = RetailcrmConfigProvider::getSitesList();
+
+if (!empty($availableSites)) {
+ $availableSites = array_flip($availableSites);
+} else {
+ $site = RetailcrmConfigProvider::getSitesAvailable();
+ $availableSites[$site] = $site;
+}
+
if (count($arResult['arSites']) === 1) {
COption::SetOptionString($MODULE_ID, $CRM_SITES_LIST, serialize([]));
}
@@ -38,7 +47,10 @@ if (!isset($arResult['ORDER_TYPES'])) {
if (!isset($arResult['paymentTypesList'])) {
$arResult['bitrixPaymentTypesList'] = RCrmActions::PaymentList();
- $arResult['paymentTypesList'] = $RETAIL_CRM_API->paymentTypesList()->paymentTypes;
+ $arResult['paymentTypesList'] = RetailCrmService::getAvailableTypes(
+ $availableSites,
+ $RETAIL_CRM_API->paymentTypesList()->paymentTypes
+ );
$arResult['PAYMENT_TYPES'] = unserialize(COption::GetOptionString($MODULE_ID, $CRM_PAYMENT_TYPES, 0));
}
@@ -60,7 +72,10 @@ if (!isset($arResult['paymentStatusesList'])) {
if (!isset($arResult['bitrixDeliveryTypesList'])) {
$arResult['bitrixDeliveryTypesList'] = RCrmActions::DeliveryList();
- $arResult['deliveryTypesList'] = $RETAIL_CRM_API->deliveryTypesList()->deliveryTypes;
+ $arResult['deliveryTypesList'] = RetailCrmService::getAvailableTypes(
+ $availableSites,
+ $RETAIL_CRM_API->deliveryTypesList()->deliveryTypes
+ );
$arResult['DELIVERY_TYPES'] = unserialize(COption::GetOptionString($MODULE_ID, $CRM_DELIVERY_TYPES_ARR, 0));
}
@@ -226,12 +241,10 @@ if (isset($arResult['PAYMENT'])) {
@@ -250,14 +263,12 @@ if (isset($arResult['PAYMENT'])) {
diff --git a/intaro.retailcrm/install/version.php b/intaro.retailcrm/install/version.php
index d688f421..c5731a26 100644
--- a/intaro.retailcrm/install/version.php
+++ b/intaro.retailcrm/install/version.php
@@ -1,6 +1,6 @@
'6.3.9',
- 'VERSION_DATE' => '2023-06-01 14:00:00'
+ 'VERSION' => '6.3.10',
+ 'VERSION_DATE' => '2023-06-02 11:00:00'
];
diff --git a/intaro.retailcrm/options.php b/intaro.retailcrm/options.php
index 3a79e06e..b69cb452 100644
--- a/intaro.retailcrm/options.php
+++ b/intaro.retailcrm/options.php
@@ -220,6 +220,15 @@ if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && (strtolower($_SERVER['HTTP_X_RE
die(json_encode($res));
}
+$availableSites = RetailcrmConfigProvider::getSitesList();
+
+if (!empty($availableSites)) {
+ $availableSites = array_flip($availableSites);
+} else {
+ $site = RetailcrmConfigProvider::getSitesAvailable();
+ $availableSites[$site] = $site;
+}
+
//update connection settings
if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) {
$api_host = htmlspecialchars(trim($_POST['api_host']));
@@ -618,8 +627,14 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) {
}
try {
- $arResult['paymentTypesList'] = $api->paymentTypesList()->paymentTypes;
- $arResult['deliveryTypesList'] = $api->deliveryTypesList()->deliveryTypes;
+ $arResult['paymentTypesList'] = RetailCrmService::getAvailableTypes(
+ $availableSites,
+ $api->paymentTypesList()->paymentTypes
+ );
+ $arResult['deliveryTypesList'] = RetailCrmService::getAvailableTypes(
+ $availableSites,
+ $api->deliveryTypesList()->deliveryTypes
+ );
} catch (\RetailCrm\Exception\CurlException $e) {
RCrmActions::eventLog(
'intaro.retailcrm/options.php', 'RetailCrm\ApiClient::*List::CurlException',
@@ -942,21 +957,20 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) {
echo CAdminMessage::ShowMessage(GetMessage('ERR_JSON'));
}
- $deliveryTypes = [];
- $deliveryIntegrationCode = [];
- foreach ($arResult['deliveryTypesList'] as $deliveryType) {
- if ($deliveryType['active'] === true) {
- $deliveryTypes[$deliveryType['code']] = $deliveryType;
- $deliveryIntegrationCode[$deliveryType['code']] = $deliveryType['integrationCode'];
- }
- }
-
- $arResult['deliveryTypesList'] = $deliveryTypes;
- COption::SetOptionString(
- $mid,
- RetailcrmConstants::CRM_INTEGRATION_DELIVERY,
- serialize(RCrmActions::clearArr(is_array($deliveryIntegrationCode) ? $deliveryIntegrationCode : []))
+ $arResult['paymentTypesList'] = RetailCrmService::getAvailableTypes(
+ $availableSites,
+ $api->paymentTypesList()->paymentTypes
);
+ $arResult['deliveryTypesList'] = RetailCrmService::getAvailableTypes(
+ $availableSites,
+ $api->deliveryTypesList()->deliveryTypes
+ );
+
+ $integrationPayments = RetailCrmService::selectIntegrationPayments($arResult['paymentTypesList']);
+ $integrationDeliveries = RetailCrmService::selectIntegrationDeliveries($arResult['deliveryTypesList']);
+
+ RetailcrmConfigProvider::setIntegrationPaymentTypes($integrationPayments);
+ RetailcrmConfigProvider::setIntegrationDelivery($integrationDeliveries);
//bitrix orderTypesList -- personTypes
$arResult['bitrixOrderTypesList'] = RCrmActions::OrderTypesList($arResult['arSites']);
@@ -1470,13 +1484,11 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) {
@@ -1501,13 +1513,11 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) {
diff --git a/tests/classes/general/services/RetailCrmServiceTest.php b/tests/classes/general/services/RetailCrmServiceTest.php
index 3f0730dd..0394d32f 100644
--- a/tests/classes/general/services/RetailCrmServiceTest.php
+++ b/tests/classes/general/services/RetailCrmServiceTest.php
@@ -50,6 +50,20 @@ class RetailCrmServiceTest extends PHPUnit\Framework\TestCase
$this->assertEquals($expected, RetailCrmService::selectIntegrationPayments($data));
}
+ public function testGetAvailableTypes(): void
+ {
+ $data = DataService::availableSitesAndTypesData();
+ $sites = $data['sites'];
+ $types = $data['types'];
+
+ $result = RetailCrmService::getAvailableTypes($sites, $types);
+
+ $this->assertCount(3, $result);
+ $this->assertEquals('test1', $result[0]['code']);
+ $this->assertEquals('test4', $result[1]['code']);
+ $this->assertEquals('test6', $result[2]['code']);
+ }
+
public function selectIntegrationDeliveriesProvider()
{
return [[
diff --git a/tests/datasets/DataService.php b/tests/datasets/DataService.php
index 69bab807..2cef2bdd 100644
--- a/tests/datasets/DataService.php
+++ b/tests/datasets/DataService.php
@@ -42,4 +42,46 @@ class DataService
'shipmentStore' => 'test',
];
}
+
+ public static function availableSitesAndTypesData()
+ {
+ return [
+ 'sites' => [
+ 'bitrix' => 's1',
+ 'bitrix2' => 's2'
+ ],
+ 'types' => [
+ 'test1' => [
+ 'code' => 'test1',
+ 'active' => true,
+ 'sites' => []
+ ],
+ 'test2' => [
+ 'code' => 'test2',
+ 'active' => false,
+ 'sites' => []
+ ],
+ 'test3' => [
+ 'code' => 'test3',
+ 'active' => true,
+ 'sites' => ['crm', 'crm1']
+ ],
+ 'test4' => [
+ 'code' => 'test4',
+ 'active' => true,
+ 'sites' => ['bitrix', 'crm']
+ ],
+ 'test5' => [
+ 'code' => 'test5',
+ 'active' => false,
+ 'sites' => ['bitrix', 'bitrix2']
+ ],
+ 'test6' => [
+ 'code' => 'test6',
+ 'active' => true,
+ 'sites' => ['bitrix', 'bitrix2']
+ ]
+ ]
+ ];
+ }
}