This commit is contained in:
parent
d47852dc31
commit
992162c01e
@ -1,4 +1,7 @@
|
|||||||
## 2023-10-25 v.6.4.11
|
## 2023-12-12 v.6.4.12
|
||||||
|
- Исправлена критическая ошибка при переходе в настройки модуля
|
||||||
|
|
||||||
|
## 2023-12-08 v.6.4.11
|
||||||
- Исправлена ошибка при передаче подписки на рекламно-информационные рассылки
|
- Исправлена ошибка при передаче подписки на рекламно-информационные рассылки
|
||||||
|
|
||||||
## 2023-10-25 v.6.4.10
|
## 2023-10-25 v.6.4.10
|
||||||
|
@ -1,13 +1,16 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use Bitrix\Sale\PersonType;
|
||||||
use Intaro\RetailCrm\Component\ServiceLocator;
|
use Intaro\RetailCrm\Component\ServiceLocator;
|
||||||
use Bitrix\Sale\Delivery\Services\EmptyDeliveryService;
|
use Bitrix\Sale\Delivery\Services\EmptyDeliveryService;
|
||||||
use Bitrix\Sale\Internals\OrderPropsTable;
|
use Bitrix\Sale\Internals\OrderPropsTable;
|
||||||
use Bitrix\Sale\Internals\StatusTable;
|
use Bitrix\Sale\Internals\StatusTable;
|
||||||
use Bitrix\Sale\PaySystem\Manager;
|
use Bitrix\Sale\PaySystem\Manager;
|
||||||
|
use Intaro\RetailCrm\Service\Utils;
|
||||||
use RetailCrm\Exception\CurlException;
|
use RetailCrm\Exception\CurlException;
|
||||||
use RetailCrm\Exception\InvalidJsonException;
|
use RetailCrm\Exception\InvalidJsonException;
|
||||||
use Intaro\RetailCrm\Service\ManagerService;
|
use Intaro\RetailCrm\Service\ManagerService;
|
||||||
|
use Bitrix\Sale\Internals\SiteCurrencyTable;
|
||||||
|
|
||||||
IncludeModuleLangFile(__FILE__);
|
IncludeModuleLangFile(__FILE__);
|
||||||
|
|
||||||
@ -19,33 +22,19 @@ class RCrmActions
|
|||||||
public static $MODULE_ID = 'intaro.retailcrm';
|
public static $MODULE_ID = 'intaro.retailcrm';
|
||||||
public static $CRM_ORDER_FAILED_IDS = 'order_failed_ids';
|
public static $CRM_ORDER_FAILED_IDS = 'order_failed_ids';
|
||||||
public static $CRM_API_VERSION = 'api_version';
|
public static $CRM_API_VERSION = 'api_version';
|
||||||
public const CANCEL_PROPERTY_CODE = 'INTAROCRM_IS_CANCELED';
|
|
||||||
|
|
||||||
public static function getCurrencySites(): array
|
public static function getCurrencySites(): array
|
||||||
{
|
{
|
||||||
global $DB;
|
|
||||||
|
|
||||||
$sites = self::getSitesList();
|
$sites = self::getSitesList();
|
||||||
$sitesLID = [];
|
$baseCurrency = CCurrency::GetBaseCurrency();
|
||||||
$sitesCurrency = [];
|
$sitesCurrency = [];
|
||||||
|
|
||||||
foreach ($sites as $site) {
|
foreach ($sites as $site) {
|
||||||
$sitesLID[] = $site['LID'];
|
$siteCurrency = SiteCurrencyTable::getCurrency($site['LID']);
|
||||||
}
|
|
||||||
|
|
||||||
$currencies = $DB->Query(
|
$sitesCurrency[$site['LID']] = !empty($siteCurrency['CURRENCY'])
|
||||||
"SELECT DISTINCT site.SMN_SITE_ID, hook_data.VALUE
|
? $siteCurrency['CURRENCY']
|
||||||
FROM `b_landing_site` site
|
: $baseCurrency;
|
||||||
LEFT JOIN `b_landing_hook_data` hook_data on site.ID = hook_data.ENTITY_ID
|
|
||||||
WHERE site.SMN_SITE_ID IN ('" . implode("', '", $sitesLID) . "')
|
|
||||||
AND hook_data.CODE = 'CURRENCY_ID';
|
|
||||||
"
|
|
||||||
);
|
|
||||||
|
|
||||||
while ($currencySite = $currencies->Fetch()) {
|
|
||||||
if (!empty($currencySite['SMN_SITE_ID'])) {
|
|
||||||
$sitesCurrency[$currencySite['SMN_SITE_ID']] = $currencySite['VALUE'];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $sitesCurrency;
|
return $sitesCurrency;
|
||||||
@ -68,17 +57,21 @@ class RCrmActions
|
|||||||
|
|
||||||
public static function OrderTypesList($arSites)
|
public static function OrderTypesList($arSites)
|
||||||
{
|
{
|
||||||
$orderTypesList = array();
|
$orderTypesList = [];
|
||||||
|
|
||||||
foreach ($arSites as $site) {
|
foreach ($arSites as $site) {
|
||||||
$personTypes = \Bitrix\Sale\PersonType::load($site['LID']);
|
$personTypes = PersonType::load($site['LID']);
|
||||||
$bitrixOrderTypesList = array();
|
$bitrixOrderTypesList = [];
|
||||||
|
|
||||||
foreach ($personTypes as $personType) {
|
foreach ($personTypes as $personType) {
|
||||||
if (!array_key_exists($personType['ID'], $orderTypesList)) {
|
if (!array_key_exists($personType['ID'], $orderTypesList)) {
|
||||||
$bitrixOrderTypesList[$personType['ID']] = $personType;
|
$bitrixOrderTypesList[$personType['ID']] = $personType;
|
||||||
}
|
}
|
||||||
|
|
||||||
asort($bitrixOrderTypesList);
|
asort($bitrixOrderTypesList);
|
||||||
}
|
}
|
||||||
$orderTypesList = $orderTypesList + $bitrixOrderTypesList;
|
|
||||||
|
$orderTypesList += $bitrixOrderTypesList;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $orderTypesList;
|
return $orderTypesList;
|
||||||
@ -86,10 +79,11 @@ class RCrmActions
|
|||||||
|
|
||||||
public static function DeliveryList()
|
public static function DeliveryList()
|
||||||
{
|
{
|
||||||
$bitrixDeliveryTypesList = array();
|
$bitrixDeliveryTypesList = [];
|
||||||
$arDeliveryServiceAll = \Bitrix\Sale\Delivery\Services\Manager::getActiveList();
|
$arDeliveryServiceAll = \Bitrix\Sale\Delivery\Services\Manager::getActiveList();
|
||||||
$noOrderId = EmptyDeliveryService::getEmptyDeliveryServiceId();
|
$noOrderId = EmptyDeliveryService::getEmptyDeliveryServiceId();
|
||||||
$groups = array();
|
$groups = [];
|
||||||
|
|
||||||
foreach ($arDeliveryServiceAll as $arDeliveryService) {
|
foreach ($arDeliveryServiceAll as $arDeliveryService) {
|
||||||
if ($arDeliveryService['CLASS_NAME'] == '\Bitrix\Sale\Delivery\Services\Group') {
|
if ($arDeliveryService['CLASS_NAME'] == '\Bitrix\Sale\Delivery\Services\Group') {
|
||||||
$groups[] = $arDeliveryService['ID'];
|
$groups[] = $arDeliveryService['ID'];
|
||||||
@ -112,11 +106,9 @@ class RCrmActions
|
|||||||
|
|
||||||
public static function PaymentList()
|
public static function PaymentList()
|
||||||
{
|
{
|
||||||
$bitrixPaymentTypesList = array();
|
$bitrixPaymentTypesList = [];
|
||||||
$dbPaymentAll = Manager::getList(array(
|
$dbPaymentAll = Manager::getList(['select' => ['ID', 'NAME'], 'filter' => ['ACTIVE' => 'Y']]);
|
||||||
'select' => array('ID', 'NAME'),
|
|
||||||
'filter' => array('ACTIVE' => 'Y')
|
|
||||||
));
|
|
||||||
while ($payment = $dbPaymentAll->fetch()) {
|
while ($payment = $dbPaymentAll->fetch()) {
|
||||||
$bitrixPaymentTypesList[] = $payment;
|
$bitrixPaymentTypesList[] = $payment;
|
||||||
}
|
}
|
||||||
@ -126,16 +118,14 @@ class RCrmActions
|
|||||||
|
|
||||||
public static function StatusesList()
|
public static function StatusesList()
|
||||||
{
|
{
|
||||||
$bitrixPaymentStatusesList = array();
|
$bitrixPaymentStatusesList = [];
|
||||||
$obStatuses = StatusTable::getList(array(
|
$obStatuses = StatusTable::getList([
|
||||||
'filter' => array('TYPE' => 'O', '=Bitrix\Sale\Internals\StatusLangTable:STATUS.LID' => LANGUAGE_ID),
|
'filter' => ['TYPE' => 'O', '=Bitrix\Sale\Internals\StatusLangTable:STATUS.LID' => LANGUAGE_ID],
|
||||||
'select' => array('ID', 'NAME' => 'Bitrix\Sale\Internals\StatusLangTable:STATUS.NAME')
|
'select' => ['ID', 'NAME' => 'Bitrix\Sale\Internals\StatusLangTable:STATUS.NAME'],
|
||||||
));
|
]);
|
||||||
|
|
||||||
while ($arStatus = $obStatuses->fetch()) {
|
while ($arStatus = $obStatuses->fetch()) {
|
||||||
$bitrixPaymentStatusesList[$arStatus['ID']] = array(
|
$bitrixPaymentStatusesList[$arStatus['ID']] = ['ID' => $arStatus['ID'], 'NAME' => $arStatus['NAME']];
|
||||||
'ID' => $arStatus['ID'],
|
|
||||||
'NAME' => $arStatus['NAME'],
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $bitrixPaymentStatusesList;
|
return $bitrixPaymentStatusesList;
|
||||||
@ -143,11 +133,9 @@ class RCrmActions
|
|||||||
|
|
||||||
public static function OrderPropsList()
|
public static function OrderPropsList()
|
||||||
{
|
{
|
||||||
$bitrixPropsList = array();
|
$bitrixPropsList = [];
|
||||||
$arPropsAll = OrderPropsTable::getList(array(
|
$arPropsAll = OrderPropsTable::getList(['select' => ['*'], 'filter' => ['CODE' => '_%']]);
|
||||||
'select' => array('*'),
|
|
||||||
'filter' => array('CODE' => '_%')
|
|
||||||
));
|
|
||||||
while ($prop = $arPropsAll->Fetch()) {
|
while ($prop = $arPropsAll->Fetch()) {
|
||||||
$bitrixPropsList[$prop['PERSON_TYPE_ID']][] = $prop;
|
$bitrixPropsList[$prop['PERSON_TYPE_ID']][] = $prop;
|
||||||
}
|
}
|
||||||
@ -157,14 +145,8 @@ class RCrmActions
|
|||||||
|
|
||||||
public static function PricesExportList()
|
public static function PricesExportList()
|
||||||
{
|
{
|
||||||
$catalogExportPrices = array();
|
$catalogExportPrices = [];
|
||||||
$dbPriceType = CCatalogGroup::GetList(
|
$dbPriceType = CCatalogGroup::GetList([], [], false, false, ['ID', 'NAME', 'NAME_LANG']);
|
||||||
array(),
|
|
||||||
array(),
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
array('ID', 'NAME', 'NAME_LANG')
|
|
||||||
);
|
|
||||||
|
|
||||||
while ($arPriceType = $dbPriceType->Fetch())
|
while ($arPriceType = $dbPriceType->Fetch())
|
||||||
{
|
{
|
||||||
@ -176,8 +158,9 @@ class RCrmActions
|
|||||||
|
|
||||||
public static function StoresExportList()
|
public static function StoresExportList()
|
||||||
{
|
{
|
||||||
$catalogExportStores = array();
|
$catalogExportStores = [];
|
||||||
$dbStores = CCatalogStore::GetList(array(), array('ACTIVE' => 'Y'), false, false, array('ID', 'TITLE'));
|
$dbStores = CCatalogStore::GetList([], ['ACTIVE' => 'Y'], false, false, ['ID', 'TITLE']);
|
||||||
|
|
||||||
while ($stores = $dbStores->Fetch()) {
|
while ($stores = $dbStores->Fetch()) {
|
||||||
$catalogExportStores[] = $stores;
|
$catalogExportStores[] = $stores;
|
||||||
}
|
}
|
||||||
@ -187,18 +170,19 @@ class RCrmActions
|
|||||||
|
|
||||||
public static function IblocksExportList()
|
public static function IblocksExportList()
|
||||||
{
|
{
|
||||||
$catalogExportIblocks = array();
|
$catalogExportIblocks = [];
|
||||||
$dbIblocks = CIBlock::GetList(array('IBLOCK_TYPE' => 'ASC', 'NAME' => 'ASC'), array('CHECK_PERMISSIONS' => 'Y', 'MIN_PERMISSION' => 'W'));
|
$dbIblocks = CIBlock::GetList(['IBLOCK_TYPE' => 'ASC', 'NAME' => 'ASC'], ['CHECK_PERMISSIONS' => 'Y', 'MIN_PERMISSION' => 'W']);
|
||||||
|
|
||||||
while ($iblock = $dbIblocks->Fetch()) {
|
while ($iblock = $dbIblocks->Fetch()) {
|
||||||
if ($arCatalog = CCatalog::GetByIDExt($iblock['ID'])) {
|
if ($arCatalog = CCatalog::GetByIDExt($iblock['ID'])) {
|
||||||
if($arCatalog['CATALOG_TYPE'] == 'D' || $arCatalog['CATALOG_TYPE'] == 'X' || $arCatalog['CATALOG_TYPE'] == 'P') {
|
if($arCatalog['CATALOG_TYPE'] == 'D' || $arCatalog['CATALOG_TYPE'] == 'X' || $arCatalog['CATALOG_TYPE'] == 'P') {
|
||||||
$catalogExportIblocks[$iblock['ID']] = array(
|
$catalogExportIblocks[$iblock['ID']] = [
|
||||||
'ID' => $iblock['ID'],
|
'ID' => $iblock['ID'],
|
||||||
'IBLOCK_TYPE_ID' => $iblock['IBLOCK_TYPE_ID'],
|
'IBLOCK_TYPE_ID' => $iblock['IBLOCK_TYPE_ID'],
|
||||||
'LID' => $iblock['LID'],
|
'LID' => $iblock['LID'],
|
||||||
'CODE' => $iblock['CODE'],
|
'CODE' => $iblock['CODE'],
|
||||||
'NAME' => $iblock['NAME'],
|
'NAME' => $iblock['NAME'],
|
||||||
);
|
];
|
||||||
|
|
||||||
if ($arCatalog['CATALOG_TYPE'] == 'X' || $arCatalog['CATALOG_TYPE'] == 'P') {
|
if ($arCatalog['CATALOG_TYPE'] == 'X' || $arCatalog['CATALOG_TYPE'] == 'P') {
|
||||||
$iblockOffer = CCatalogSKU::GetInfoByProductIBlock($iblock['ID']);
|
$iblockOffer = CCatalogSKU::GetInfoByProductIBlock($iblock['ID']);
|
||||||
@ -289,8 +273,9 @@ class RCrmActions
|
|||||||
*/
|
*/
|
||||||
public static function clearArr(array $arr): array
|
public static function clearArr(array $arr): array
|
||||||
{
|
{
|
||||||
/** @var \Intaro\RetailCrm\Service\Utils $utils */
|
/** @var Utils $utils */
|
||||||
$utils = ServiceLocator::getOrCreate(\Intaro\RetailCrm\Service\Utils::class);
|
$utils = ServiceLocator::getOrCreate(Utils::class);
|
||||||
|
|
||||||
return $utils->clearArray($arr);
|
return $utils->clearArray($arr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -302,8 +287,9 @@ class RCrmActions
|
|||||||
*/
|
*/
|
||||||
public static function toJSON($str)
|
public static function toJSON($str)
|
||||||
{
|
{
|
||||||
/** @var \Intaro\RetailCrm\Service\Utils $utils */
|
/** @var Utils $utils */
|
||||||
$utils = ServiceLocator::getOrCreate(\Intaro\RetailCrm\Service\Utils::class);
|
$utils = ServiceLocator::getOrCreate(Utils::class);
|
||||||
|
|
||||||
return $utils->toUTF8($str);
|
return $utils->toUTF8($str);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -319,8 +305,8 @@ class RCrmActions
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var \Intaro\RetailCrm\Service\Utils $utils */
|
/** @var Utils $utils */
|
||||||
$utils = ServiceLocator::getOrCreate(\Intaro\RetailCrm\Service\Utils::class);
|
$utils = ServiceLocator::getOrCreate(Utils::class);
|
||||||
|
|
||||||
return $utils->fromUTF8($str);
|
return $utils->fromUTF8($str);
|
||||||
}
|
}
|
||||||
@ -523,14 +509,14 @@ class RCrmActions
|
|||||||
case 'cartClear':
|
case 'cartClear':
|
||||||
return self::proxy($api, $methodApi, $method, [$params, $site]);
|
return self::proxy($api, $methodApi, $method, [$params, $site]);
|
||||||
default:
|
default:
|
||||||
return self::proxy($api, $methodApi, $method, array($params, $site));
|
return self::proxy($api, $methodApi, $method, [$params, $site]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function proxy($api, $methodApi, $method, $params) {
|
private static function proxy($api, $methodApi, $method, $params) {
|
||||||
$version = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_VERSION, 0);
|
$version = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_VERSION, 0);
|
||||||
try {
|
try {
|
||||||
$result = call_user_func_array(array($api, $methodApi), $params);
|
$result = call_user_func_array([$api, $methodApi], $params);
|
||||||
|
|
||||||
if (!$result) {
|
if (!$result) {
|
||||||
$err = new RuntimeException(
|
$err = new RuntimeException(
|
||||||
@ -551,21 +537,21 @@ class RCrmActions
|
|||||||
|| $methodApi == 'customersGet'
|
|| $methodApi == 'customersGet'
|
||||||
|| $methodApi == 'customersCorporateGet'
|
|| $methodApi == 'customersCorporateGet'
|
||||||
) {
|
) {
|
||||||
Logger::getInstance()->write(array(
|
Logger::getInstance()->write([
|
||||||
'api' => $version,
|
'api' => $version,
|
||||||
'methodApi' => $methodApi,
|
'methodApi' => $methodApi,
|
||||||
'errorMsg' => !empty($result['errorMsg']) ? $result['errorMsg'] : '',
|
'errorMsg' => !empty($result['errorMsg']) ? $result['errorMsg'] : '',
|
||||||
'errors' => !empty($result['errors']) ? $result['errors'] : '',
|
'errors' => !empty($result['errors']) ? $result['errors'] : '',
|
||||||
'params' => $params
|
'params' => $params
|
||||||
), 'apiErrors');
|
], 'apiErrors');
|
||||||
} elseif ($methodApi == 'customersUpload' || $methodApi == 'ordersUpload') {
|
} elseif ($methodApi == 'customersUpload' || $methodApi == 'ordersUpload') {
|
||||||
Logger::getInstance()->write(array(
|
Logger::getInstance()->write([
|
||||||
'api' => $version,
|
'api' => $version,
|
||||||
'methodApi' => $methodApi,
|
'methodApi' => $methodApi,
|
||||||
'errorMsg' => !empty($result['errorMsg']) ? $result['errorMsg'] : '',
|
'errorMsg' => !empty($result['errorMsg']) ? $result['errorMsg'] : '',
|
||||||
'errors' => !empty($result['errors']) ? $result['errors'] : '',
|
'errors' => !empty($result['errors']) ? $result['errors'] : '',
|
||||||
'params' => $params
|
'params' => $params
|
||||||
), 'uploadApiErrors');
|
], 'uploadApiErrors');
|
||||||
} elseif ($methodApi == 'cartGet') {
|
} elseif ($methodApi == 'cartGet') {
|
||||||
Logger::getInstance()->write(
|
Logger::getInstance()->write(
|
||||||
[
|
[
|
||||||
@ -584,13 +570,13 @@ class RCrmActions
|
|||||||
!empty($result['errorMsg']) ? $result['errorMsg'] : ''
|
!empty($result['errorMsg']) ? $result['errorMsg'] : ''
|
||||||
);
|
);
|
||||||
|
|
||||||
Logger::getInstance()->write(array(
|
Logger::getInstance()->write([
|
||||||
'api' => $version,
|
'api' => $version,
|
||||||
'methodApi' => $methodApi,
|
'methodApi' => $methodApi,
|
||||||
'errorMsg' => !empty($result['errorMsg']) ? $result['errorMsg'] : '',
|
'errorMsg' => !empty($result['errorMsg']) ? $result['errorMsg'] : '',
|
||||||
'errors' => !empty($result['errors']) ? $result['errors'] : '',
|
'errors' => !empty($result['errors']) ? $result['errors'] : '',
|
||||||
'params' => $params,
|
'params' => $params,
|
||||||
), 'apiErrors');
|
], 'apiErrors');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (function_exists('retailCrmApiResult')) {
|
if (function_exists('retailCrmApiResult')) {
|
||||||
@ -671,13 +657,13 @@ class RCrmActions
|
|||||||
$exception->getCode() . ': ' . $exception->getMessage()
|
$exception->getCode() . ': ' . $exception->getMessage()
|
||||||
);
|
);
|
||||||
|
|
||||||
Logger::getInstance()->write(array(
|
Logger::getInstance()->write([
|
||||||
'api' => $version,
|
'api' => $version,
|
||||||
'methodApi' => $methodApi,
|
'methodApi' => $methodApi,
|
||||||
'errorMsg' => $exception->getMessage(),
|
'errorMsg' => $exception->getMessage(),
|
||||||
'errors' => $exception->getCode(),
|
'errors' => $exception->getCode(),
|
||||||
'params' => $params
|
'params' => $params
|
||||||
), 'apiErrors');
|
], 'apiErrors');
|
||||||
|
|
||||||
if (function_exists('retailCrmApiResult')) {
|
if (function_exists('retailCrmApiResult')) {
|
||||||
retailCrmApiResult($methodApi, false, $apiResultExceptionName);
|
retailCrmApiResult($methodApi, false, $apiResultExceptionName);
|
||||||
|
@ -51,7 +51,6 @@ class RetailCrmHistory
|
|||||||
public static $CRM_DISCOUNT_ROUND = 'discount_round';
|
public static $CRM_DISCOUNT_ROUND = 'discount_round';
|
||||||
|
|
||||||
const PAGE_LIMIT = 25;
|
const PAGE_LIMIT = 25;
|
||||||
const CANCEL_PROPERTY_CODE = 'INTAROCRM_IS_CANCELED';
|
|
||||||
|
|
||||||
public static function customerHistory()
|
public static function customerHistory()
|
||||||
{
|
{
|
||||||
|
@ -431,11 +431,11 @@ class RetailCrmOrder
|
|||||||
$arUser = UserTable::getById($arOrder['USER_ID'])->fetch();
|
$arUser = UserTable::getById($arOrder['USER_ID'])->fetch();
|
||||||
$fioCrm = [$order['firstName'] ?? null, $order['lastName'] ?? null, $order['patronymic'] ?? null];
|
$fioCrm = [$order['firstName'] ?? null, $order['lastName'] ?? null, $order['patronymic'] ?? null];
|
||||||
|
|
||||||
if (in_array($arUser['NAME'], $fioCrm)) {
|
if ($arUser['NAME'] !== '' && in_array($arUser['NAME'], $fioCrm)) {
|
||||||
$order['firstName'] = $arUser['NAME'];
|
$order['firstName'] = $arUser['NAME'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in_array($arUser['LAST_NAME'], $fioCrm)) {
|
if ($arUser['LAST_NAME'] !== '' && in_array($arUser['LAST_NAME'], $fioCrm)) {
|
||||||
$order['lastName'] = $arUser['LAST_NAME'];
|
$order['lastName'] = $arUser['LAST_NAME'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1 +1 @@
|
|||||||
- Исправлена ошибка при передаче подписки на рекламно-информационные рассылки
|
- Исправлена критическая ошибка при переходе в настройки модуля
|
||||||
|
@ -15,6 +15,7 @@ use Bitrix\Sale\EventActions;
|
|||||||
use Bitrix\Sale\Internals\OrderTable;
|
use Bitrix\Sale\Internals\OrderTable;
|
||||||
use Intaro\RetailCrm\Component\ConfigProvider;
|
use Intaro\RetailCrm\Component\ConfigProvider;
|
||||||
use Intaro\RetailCrm\Component\Installer\InstallerTrait;
|
use Intaro\RetailCrm\Component\Installer\InstallerTrait;
|
||||||
|
use Intaro\RetailCrm\Service\CurrencyService;
|
||||||
use Intaro\RetailCrm\Service\OrderLoyaltyDataService;
|
use Intaro\RetailCrm\Service\OrderLoyaltyDataService;
|
||||||
use Intaro\RetailCrm\Vendor\Symfony\Component\Process\PhpExecutableFinder;
|
use Intaro\RetailCrm\Vendor\Symfony\Component\Process\PhpExecutableFinder;
|
||||||
use RetailCrm\ApiClient;
|
use RetailCrm\ApiClient;
|
||||||
@ -242,6 +243,7 @@ class intaro_retailcrm extends CModule
|
|||||||
include($this->INSTALL_PATH . '/../lib/component/constants.php');
|
include($this->INSTALL_PATH . '/../lib/component/constants.php');
|
||||||
include($this->INSTALL_PATH . '/../lib/repository/agreementrepository.php');
|
include($this->INSTALL_PATH . '/../lib/repository/agreementrepository.php');
|
||||||
include($this->INSTALL_PATH . '/../lib/service/orderloyaltydataservice.php');
|
include($this->INSTALL_PATH . '/../lib/service/orderloyaltydataservice.php');
|
||||||
|
include($this->INSTALL_PATH . '/../lib/service/currencyservice.php');
|
||||||
include($this->INSTALL_PATH . '/../lib/component/factory/clientfactory.php');
|
include($this->INSTALL_PATH . '/../lib/component/factory/clientfactory.php');
|
||||||
include($this->INSTALL_PATH . '/../lib/component/apiclient/clientadapter.php');
|
include($this->INSTALL_PATH . '/../lib/component/apiclient/clientadapter.php');
|
||||||
|
|
||||||
@ -311,9 +313,11 @@ class intaro_retailcrm extends CModule
|
|||||||
|
|
||||||
// form correct url
|
// form correct url
|
||||||
$api_host = parse_url($api_host);
|
$api_host = parse_url($api_host);
|
||||||
|
|
||||||
if ($api_host['scheme'] !== 'https') {
|
if ($api_host['scheme'] !== 'https') {
|
||||||
$api_host['scheme'] = 'https';
|
$api_host['scheme'] = 'https';
|
||||||
}
|
}
|
||||||
|
|
||||||
$api_host = $api_host['scheme'] . '://' . $api_host['host'];
|
$api_host = $api_host['scheme'] . '://' . $api_host['host'];
|
||||||
|
|
||||||
if (!$api_host || !$api_key) {
|
if (!$api_host || !$api_key) {
|
||||||
@ -374,15 +378,14 @@ class intaro_retailcrm extends CModule
|
|||||||
$api_key = COption::GetOptionString($this->MODULE_ID, $this->CRM_API_KEY_OPTION, 0);
|
$api_key = COption::GetOptionString($this->MODULE_ID, $this->CRM_API_KEY_OPTION, 0);
|
||||||
|
|
||||||
foreach ($arResult['arSites'] as $site) {
|
foreach ($arResult['arSites'] as $site) {
|
||||||
|
$siteCode[$site['LID']] = null;
|
||||||
|
|
||||||
if ($_POST['sites-id-' . $site['LID']] && !empty($_POST['sites-id-' . $site['LID']])) {
|
if ($_POST['sites-id-' . $site['LID']] && !empty($_POST['sites-id-' . $site['LID']])) {
|
||||||
$siteCode[$site['LID']] = htmlspecialchars(trim($_POST['sites-id-' . $site['LID']]));
|
$siteCode[$site['LID']] = htmlspecialchars(trim($_POST['sites-id-' . $site['LID']]));
|
||||||
} else {
|
|
||||||
$siteCode[$site['LID']] = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$arResult['arCurrencySites'] = RCrmActions::getCurrencySites();
|
$arResult['arCurrencySites'] = RCrmActions::getCurrencySites();
|
||||||
$bitrixBaseCurrency = CCurrency::GetBaseCurrency();
|
|
||||||
$result = $this->getReferenceShops($api_host, $api_key);
|
$result = $this->getReferenceShops($api_host, $api_key);
|
||||||
|
|
||||||
if (isset($result['errCode'])) {
|
if (isset($result['errCode'])) {
|
||||||
@ -392,26 +395,18 @@ class intaro_retailcrm extends CModule
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach ($arResult['arSites'] as $bitrixSite) {
|
foreach ($arResult['arSites'] as $bitrixSite) {
|
||||||
$currentCurrency = $bitrixBaseCurrency;
|
$LID = $bitrixSite['LID'] ?? null;
|
||||||
$LID = $bitrixSite['LID'];
|
$cmsCurrency = $arResult['arCurrencySites'][$LID] ?? null;
|
||||||
|
$crmCurrency = $arResult['sitesList'][$siteCode[$LID]]['currency'] ?? null;
|
||||||
|
|
||||||
if (isset($arResult['arCurrencySites'][$LID])) {
|
$arResult['errCode'] = CurrencyService::validateCurrency($cmsCurrency, $crmCurrency);
|
||||||
$currentCurrency = $arResult['arCurrencySites'][$LID];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
isset($arResult['sitesList'][$siteCode[$LID]])
|
|
||||||
&& $currentCurrency !== $arResult['sitesList'][$siteCode[$LID]]['currency'])
|
|
||||||
{
|
|
||||||
$arResult['errCode'] = 'ERR_CURRENCY_SITES';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count($arResult['arSites']) != count($siteCode)) {
|
if (count($arResult['arSites']) != count($siteCode)) {
|
||||||
$arResult['errCode'] = 'ERR_FIELDS_API_HOST';
|
$arResult['errCode'] = 'ERR_FIELDS_API_HOST';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($arResult['errCode'])) {
|
if (!empty($arResult['errCode'])) {
|
||||||
$APPLICATION->IncludeAdminFile(
|
$APPLICATION->IncludeAdminFile(
|
||||||
GetMessage('MODULE_INSTALL_TITLE'), $this->INSTALL_PATH . '/step11.php'
|
GetMessage('MODULE_INSTALL_TITLE'), $this->INSTALL_PATH . '/step11.php'
|
||||||
);
|
);
|
||||||
@ -1458,11 +1453,11 @@ class intaro_retailcrm extends CModule
|
|||||||
global $APPLICATION;
|
global $APPLICATION;
|
||||||
|
|
||||||
$client = new Client($api_host . '/api/'.self::V5, ['apiKey' => $api_key]);
|
$client = new Client($api_host . '/api/'.self::V5, ['apiKey' => $api_key]);
|
||||||
|
$result = [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$result = $client->makeRequest('/reference/sites', 'GET');
|
$siteResponse = $client->makeRequest('/reference/sites', 'GET');
|
||||||
$bitrixSites = RCrmActions::getSitesList();
|
$bitrixSites = RCrmActions::getSitesList();
|
||||||
$bitrixBaseCurrency = CCurrency::GetBaseCurrency();
|
|
||||||
$currencySites = RCrmActions::getCurrencySites();
|
$currencySites = RCrmActions::getCurrencySites();
|
||||||
} catch (CurlException $e) {
|
} catch (CurlException $e) {
|
||||||
RCrmActions::eventLog(
|
RCrmActions::eventLog(
|
||||||
@ -1470,47 +1465,44 @@ class intaro_retailcrm extends CModule
|
|||||||
$e->getCode() . ': ' . $e->getMessage()
|
$e->getCode() . ': ' . $e->getMessage()
|
||||||
);
|
);
|
||||||
|
|
||||||
$res['errCode'] = 'ERR_' . $e->getCode();
|
$result['errCode'] = 'ERR_' . $e->getCode();
|
||||||
|
|
||||||
return $res;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Проверка, что был получен корректный ответ
|
// Проверка, что был получен корректный ответ
|
||||||
if (isset($result) && $result->getStatusCode() == 200) {
|
if (isset($siteResponse) && $siteResponse->getStatusCode() === 200) {
|
||||||
//Проверка количества магазинов, доступных по апи
|
$sites = $siteResponse->sites ?? null;
|
||||||
if (count($bitrixSites) === 1 && count($result->sites) > 1) {
|
|
||||||
$res['errCode'] = 'ERR_COUNT_SITES';
|
if ($sites === null) {
|
||||||
|
$result['errCode'] = 'UNKNOWN_ERROR';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($res['errCode']) && count($bitrixSites) === 1 ) {
|
//Проверка количества магазинов, доступных по API
|
||||||
$currentCurrency = $bitrixBaseCurrency;
|
if (count($bitrixSites) === 1 && count($sites) > 1) {
|
||||||
$LID = $bitrixSites[0]['LID'];
|
$result['errCode'] = 'ERR_COUNT_SITES';
|
||||||
|
|
||||||
if (isset($currencySites[$LID])) {
|
|
||||||
$currentCurrency = $currencySites[$LID];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$crmSite = reset($result->sites);
|
if (!isset($result['errCode']) && count($bitrixSites) === 1 ) {
|
||||||
|
$LID = $bitrixSites[0]['LID'] ?? null;
|
||||||
|
$cmsCurrency = $currencySites[$LID] ?? null;
|
||||||
|
|
||||||
if ($currentCurrency !== $crmSite['currency']) {
|
$crmSiteData = reset($sites);
|
||||||
$res['errCode'] = 'ERR_CURRENCY_SITES';
|
$crmCurrency = $crmSiteData['currency'] ?? null;
|
||||||
}
|
|
||||||
|
$result['errCode'] = CurrencyService::validateCurrency($cmsCurrency, $crmCurrency);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($res)) {
|
if (empty($result['errCode'])) {
|
||||||
ConfigProvider::setApiVersion(self::V5);
|
ConfigProvider::setApiVersion(self::V5);
|
||||||
|
|
||||||
$res['sitesList'] = $APPLICATION->ConvertCharsetArray(
|
$result['sitesList'] = $APPLICATION->ConvertCharsetArray($sites, 'utf-8', SITE_CHARSET);
|
||||||
$result->sites,
|
|
||||||
'utf-8',
|
|
||||||
SITE_CHARSET
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$res['errCode'] = 'ERR_METHOD_NOT_FOUND';
|
$result['errCode'] = 'ERR_METHOD_NOT_FOUND';
|
||||||
}
|
}
|
||||||
|
|
||||||
return $res;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
$arModuleVersion = [
|
$arModuleVersion = [
|
||||||
'VERSION' => '6.4.11',
|
'VERSION' => '6.4.12',
|
||||||
'VERSION_DATE' => '2023-12-08 13:00:00'
|
'VERSION_DATE' => '2023-12-12 17:00:00'
|
||||||
];
|
];
|
||||||
|
@ -17,3 +17,4 @@ $MESS ['ERR_ARTICLE_IBLOCK'] = 'Articles are not set';
|
|||||||
$MESS ['DATE_TIMEZONE_ERR'] = 'Timezone is not specified in php settings.';
|
$MESS ['DATE_TIMEZONE_ERR'] = 'Timezone is not specified in php settings.';
|
||||||
$MESS ['SALE_VERSION_ERR'] = '\'Online-store\' module version must be higher than 16.';
|
$MESS ['SALE_VERSION_ERR'] = '\'Online-store\' module version must be higher than 16.';
|
||||||
$MESS['UF_SUBSCRIBE_USER_EMAIL_TITLE'] = 'Agree to receive promotional newsletters';
|
$MESS['UF_SUBSCRIBE_USER_EMAIL_TITLE'] = 'Agree to receive promotional newsletters';
|
||||||
|
$MESS ['CRM_SITES_ERROR'] = 'Failed to get list of CRM stores, please try another API key or contact RetailCRM support.';
|
||||||
|
@ -19,3 +19,5 @@ $MESS ['ERR_COUNT_SITES'] = 'The API Key you entered relates to more than one st
|
|||||||
Change the access settings for the API key, it should work with only one store in CRM';
|
Change the access settings for the API key, it should work with only one store in CRM';
|
||||||
$MESS ['ERR_CURRENCY_SITES'] = 'The currency of the site differs from the currency of the store in CRM.
|
$MESS ['ERR_CURRENCY_SITES'] = 'The currency of the site differs from the currency of the store in CRM.
|
||||||
For the integration to work correctly, the currencies in CRM and CMS must match';
|
For the integration to work correctly, the currencies in CRM and CMS must match';
|
||||||
|
$MESS ['ERR_CMS_CURRENCY'] = 'Failed to get Bitrix site currency';
|
||||||
|
$MESS ['ERR_CRM_CURRENCY'] = 'Failed to get CRM store currency';
|
||||||
|
@ -12,3 +12,5 @@ $MESS ['INFO_1'] = 'Set the correspondence between 1C-Bitrix and RetailCRM store
|
|||||||
$MESS ['INFO_2'] = 'All your stores in RetailCRM must have a common API key!';
|
$MESS ['INFO_2'] = 'All your stores in RetailCRM must have a common API key!';
|
||||||
$MESS ['ERR_CURRENCY_SITES'] = 'The currency of the site differs from the currency of the store in CRM.
|
$MESS ['ERR_CURRENCY_SITES'] = 'The currency of the site differs from the currency of the store in CRM.
|
||||||
For the integration to work correctly, the currencies in CRM and CMS must match';
|
For the integration to work correctly, the currencies in CRM and CMS must match';
|
||||||
|
$MESS ['ERR_CMS_CURRENCY'] = 'Failed to get Bitrix site currency';
|
||||||
|
$MESS ['ERR_CRM_CURRENCY'] = 'Failed to get CRM store currency';
|
||||||
|
@ -105,7 +105,10 @@ $MESS ['INTEGRATIONS'] = ' (integration)';
|
|||||||
$MESS ['ERR_COUNT_SITES'] = 'The API Key you entered relates to more than one store.
|
$MESS ['ERR_COUNT_SITES'] = 'The API Key you entered relates to more than one store.
|
||||||
Change the access settings for the API key, it should work with only one store in CRM';
|
Change the access settings for the API key, it should work with only one store in CRM';
|
||||||
$MESS ['ERR_CURRENCY_SITES'] = 'The currency of the site differs from the currency of the store in CRM.
|
$MESS ['ERR_CURRENCY_SITES'] = 'The currency of the site differs from the currency of the store in CRM.
|
||||||
For the integration to work correctly, the currencies in CRM and CMS must match';
|
For the integration to work correctly, the currencies in CRM and CMS must match #NAME#';
|
||||||
|
$MESS ['ERR_CMS_CURRENCY'] = 'Failed to get Bitrix site currency';
|
||||||
|
$MESS ['ERR_CRM_CURRENCY'] = 'Failed to get CRM store currency';
|
||||||
|
$MESS ['CRM_STORE'] = 'CRM store: ';
|
||||||
|
|
||||||
$MESS ['ACTIVITY_SETTINGS'] = 'Module activity settings';
|
$MESS ['ACTIVITY_SETTINGS'] = 'Module activity settings';
|
||||||
$MESS ['DEACTIVATE_MODULE'] = 'Deactivate the module';
|
$MESS ['DEACTIVATE_MODULE'] = 'Deactivate the module';
|
||||||
|
@ -16,6 +16,7 @@ $MESS ['DATE_TIMEZONE_ERR'] = 'Не указана временная зона
|
|||||||
$MESS ['SALE_VERSION_ERR'] = 'Версия модуля \'Интернет-магазин\' должна быть выше 16.';
|
$MESS ['SALE_VERSION_ERR'] = 'Версия модуля \'Интернет-магазин\' должна быть выше 16.';
|
||||||
$MESS ['AGREEMENT_LOYALTY_PROGRAM_TEXT'] = 'Вставить текст Правил программы лояльности';
|
$MESS ['AGREEMENT_LOYALTY_PROGRAM_TEXT'] = 'Вставить текст Правил программы лояльности';
|
||||||
$MESS ['AGREEMENT_PERSONAL_DATA_TEXT'] = 'Вставить текст соглашения на обработку персональных данных';
|
$MESS ['AGREEMENT_PERSONAL_DATA_TEXT'] = 'Вставить текст соглашения на обработку персональных данных';
|
||||||
|
$MESS ['CRM_SITES_ERROR'] = 'Не удалось получить список магазинов CRM, попробуйте другой ключ API или обратитесь в службу поддержки RetailCRM.';
|
||||||
|
|
||||||
$MESS ['RETAIL_MODULE_NAME'] = 'RetailCRM';
|
$MESS ['RETAIL_MODULE_NAME'] = 'RetailCRM';
|
||||||
$MESS ['MODULE_DESCRIPTION'] = 'Модуль интеграции с RetailCRM - специализированной CRM для e-commerce';
|
$MESS ['MODULE_DESCRIPTION'] = 'Модуль интеграции с RetailCRM - специализированной CRM для e-commerce';
|
||||||
|
@ -15,7 +15,8 @@ $MESS ['ERR_COUNT_SITES'] = 'Введенный вами API Ключ относ
|
|||||||
Измените настройки доступа для API ключа, он должен работать только с одним магазином в CRM';
|
Измените настройки доступа для API ключа, он должен работать только с одним магазином в CRM';
|
||||||
$MESS ['ERR_CURRENCY_SITES'] = 'Валюта сайта отличается от валюты магазина в CRM.
|
$MESS ['ERR_CURRENCY_SITES'] = 'Валюта сайта отличается от валюты магазина в CRM.
|
||||||
Для корректной работы интеграции, валюты в CRM и CMS должны совпадать';
|
Для корректной работы интеграции, валюты в CRM и CMS должны совпадать';
|
||||||
//$MESS ['URL_NOT_FOUND'] = 'В настройках одного или нескольких сайтов не заполнено поле "URL сервера".';
|
$MESS ['ERR_CMS_CURRENCY'] = 'Не удалось получить валюту сайта Bitrix';
|
||||||
|
$MESS ['ERR_CRM_CURRENCY'] = 'Не удалось получить валюту магазина CRM';
|
||||||
$MESS ['INFO_1'] = 'Введите адрес экземпляра RetailCRM (например, https://demo.retailcrm.ru) и API-ключ.';
|
$MESS ['INFO_1'] = 'Введите адрес экземпляра RetailCRM (например, https://demo.retailcrm.ru) и API-ключ.';
|
||||||
$MESS ['INFO_2'] = 'API-ключ можно сгенерировать при регистрации магазина в RetailCRM (Администрирование > Интеграция).';
|
$MESS ['INFO_2'] = 'API-ключ можно сгенерировать при регистрации магазина в RetailCRM (Администрирование > Интеграция).';
|
||||||
$MESS ['INFO_3'] = 'Код сайта в 1С-Битрикс должен совпадать с кодом сайта в RetailCRM (Администрирование > Магазины).';
|
$MESS ['INFO_3'] = 'Код сайта в 1С-Битрикс должен совпадать с кодом сайта в RetailCRM (Администрирование > Магазины).';
|
||||||
|
@ -12,3 +12,5 @@ $MESS ['INFO_1'] = 'Задайте соответствия между Ваши
|
|||||||
$MESS ['INFO_2'] = 'У всех Ваших магазинов в RetailCRM должен быть общий API-ключ!';
|
$MESS ['INFO_2'] = 'У всех Ваших магазинов в RetailCRM должен быть общий API-ключ!';
|
||||||
$MESS ['ERR_CURRENCY_SITES'] = 'Валюта сайта отличается от валюты магазина в CRM.
|
$MESS ['ERR_CURRENCY_SITES'] = 'Валюта сайта отличается от валюты магазина в CRM.
|
||||||
Для корректной работы интеграции, валюты в CRM и CMS должны совпадать';
|
Для корректной работы интеграции, валюты в CRM и CMS должны совпадать';
|
||||||
|
$MESS ['ERR_CMS_CURRENCY'] = 'Не удалось получить валюту сайта Bitrix';
|
||||||
|
$MESS ['ERR_CRM_CURRENCY'] = 'Не удалось получить валюту магазина CRM';
|
||||||
|
@ -31,6 +31,9 @@ $MESS ['ERR_COUNT_SITES'] = 'Введенный вами API Ключ относ
|
|||||||
Измените настройки доступа для API ключа, он должен работать только с одним магазином в CRM';
|
Измените настройки доступа для API ключа, он должен работать только с одним магазином в CRM';
|
||||||
$MESS ['ERR_CURRENCY_SITES'] = 'Валюта сайта отличается от валюты магазина в CRM.
|
$MESS ['ERR_CURRENCY_SITES'] = 'Валюта сайта отличается от валюты магазина в CRM.
|
||||||
Для корректной работы интеграции, валюты в CRM и CMS должны совпадать';
|
Для корректной работы интеграции, валюты в CRM и CMS должны совпадать';
|
||||||
|
$MESS ['ERR_CMS_CURRENCY'] = 'Не удалось получить валюту сайта Bitrix';
|
||||||
|
$MESS ['ERR_CRM_CURRENCY'] = 'Не удалось получить валюту магазина CRM';
|
||||||
|
$MESS ['CRM_STORE'] = 'CRM магазин: ';
|
||||||
|
|
||||||
$MESS ['ICRM_OPTIONS_SUBMIT_TITLE'] = 'Сохранить настройки';
|
$MESS ['ICRM_OPTIONS_SUBMIT_TITLE'] = 'Сохранить настройки';
|
||||||
$MESS ['ICRM_OPTIONS_SUBMIT_VALUE'] = 'Сохранить';
|
$MESS ['ICRM_OPTIONS_SUBMIT_VALUE'] = 'Сохранить';
|
||||||
|
@ -73,7 +73,6 @@ class Constants
|
|||||||
public const CRM_ORDER_HISTORY_DATE = 'order_history_date';
|
public const CRM_ORDER_HISTORY_DATE = 'order_history_date';
|
||||||
public const CRM_CATALOG_BASE_PRICE = 'catalog_base_price';
|
public const CRM_CATALOG_BASE_PRICE = 'catalog_base_price';
|
||||||
public const CRM_ORDER_DIMENSIONS = 'order_dimensions';
|
public const CRM_ORDER_DIMENSIONS = 'order_dimensions';
|
||||||
public const CANCEL_PROPERTY_CODE = 'INTAROCRM_IS_CANCELED';
|
|
||||||
public const CRM_INTEGRATION_DELIVERY = 'integration_delivery';
|
public const CRM_INTEGRATION_DELIVERY = 'integration_delivery';
|
||||||
public const CRM_SHIPMENT_DEDUCTED = 'shipment_deducted';
|
public const CRM_SHIPMENT_DEDUCTED = 'shipment_deducted';
|
||||||
public const CORPORATE_CONTRAGENT_TYPE = 'legal-entity';
|
public const CORPORATE_CONTRAGENT_TYPE = 'legal-entity';
|
||||||
|
22
intaro.retailcrm/lib/service/currencyservice.php
Normal file
22
intaro.retailcrm/lib/service/currencyservice.php
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Intaro\RetailCrm\Service;
|
||||||
|
|
||||||
|
|
||||||
|
class CurrencyService
|
||||||
|
{
|
||||||
|
public static function validateCurrency($cmsCurrency, $crmCurrency): string
|
||||||
|
{
|
||||||
|
$errorCode = '';
|
||||||
|
|
||||||
|
if ($cmsCurrency === null) {
|
||||||
|
$errorCode = 'ERR_CMS_CURRENCY';
|
||||||
|
} elseif ($crmCurrency === null) {
|
||||||
|
$errorCode = 'ERR_CRM_CURRENCY';
|
||||||
|
} elseif ($cmsCurrency !== $crmCurrency) {
|
||||||
|
$errorCode = 'ERR_CURRENCY_SITES';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $errorCode;
|
||||||
|
}
|
||||||
|
}
|
@ -13,9 +13,10 @@ use Intaro\RetailCrm\Component\Constants;
|
|||||||
use Intaro\RetailCrm\Component\Handlers\EventsHandlers;
|
use Intaro\RetailCrm\Component\Handlers\EventsHandlers;
|
||||||
use Intaro\RetailCrm\Repository\AgreementRepository;
|
use Intaro\RetailCrm\Repository\AgreementRepository;
|
||||||
use Intaro\RetailCrm\Repository\TemplateRepository;
|
use Intaro\RetailCrm\Repository\TemplateRepository;
|
||||||
|
use Intaro\RetailCrm\Service\CurrencyService;
|
||||||
use Intaro\RetailCrm\Service\OrderLoyaltyDataService;
|
use Intaro\RetailCrm\Service\OrderLoyaltyDataService;
|
||||||
|
use Intaro\RetailCrm\Service\Utils as RetailCrmUtils;
|
||||||
use RetailCrm\Exception\CurlException;
|
use RetailCrm\Exception\CurlException;
|
||||||
use \Intaro\RetailCrm\Service\Utils as RetailcrmUtils;
|
|
||||||
|
|
||||||
IncludeModuleLangFile(__FILE__);
|
IncludeModuleLangFile(__FILE__);
|
||||||
$mid = 'intaro.retailcrm';
|
$mid = 'intaro.retailcrm';
|
||||||
@ -605,7 +606,7 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) {
|
|||||||
|
|
||||||
if (isset($_POST['loyalty_toggle']) && $_POST['loyalty_toggle'] === 'on') {
|
if (isset($_POST['loyalty_toggle']) && $_POST['loyalty_toggle'] === 'on') {
|
||||||
try {
|
try {
|
||||||
$hlName = RetailcrmUtils::getHlClassByName(Constants::HL_LOYALTY_CODE);
|
$hlName = RetailCrmUtils::getHlClassByName(Constants::HL_LOYALTY_CODE);
|
||||||
|
|
||||||
if (empty($hlName)) {
|
if (empty($hlName)) {
|
||||||
OrderLoyaltyDataService::createLoyaltyHlBlock();
|
OrderLoyaltyDataService::createLoyaltyHlBlock();
|
||||||
@ -1066,10 +1067,12 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) {
|
|||||||
|
|
||||||
$version = COption::GetOptionString($mid, $CRM_API_VERSION, 0);
|
$version = COption::GetOptionString($mid, $CRM_API_VERSION, 0);
|
||||||
|
|
||||||
//currency
|
|
||||||
$baseCurrency = \Bitrix\Currency\CurrencyManager::getBaseCurrency();
|
// Old functional
|
||||||
$currencyOption = COption::GetOptionString($mid, $CRM_CURRENCY, 0) ?: $baseCurrency;
|
$currencyOption = COption::GetOptionString($mid, $CRM_CURRENCY, 0) ?: CCurrency::GetBaseCurrency();
|
||||||
$currencyList = \Bitrix\Currency\CurrencyManager::getCurrencyList();
|
|
||||||
|
//Validate currency
|
||||||
|
$currencyList = CurrencyManager::getCurrencyList();
|
||||||
|
|
||||||
$errorsText = [];
|
$errorsText = [];
|
||||||
|
|
||||||
@ -1088,29 +1091,26 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$currentCurrency = $baseCurrency;
|
$cmsCurrency = $arResult['arCurrencySites'][$LID] ?? null;
|
||||||
|
$crmCurrency = $arResult['sitesList'][$crmCode]['currency'] ?? null;
|
||||||
|
$crmSiteName = $arResult['sitesList'][$crmCode]['name'] ?? null;
|
||||||
|
|
||||||
if (isset($arResult['arCurrencySites'][$LID])) {
|
$errorCode = CurrencyService::validateCurrency($cmsCurrency, $crmCurrency);
|
||||||
$currentCurrency = $arResult['arCurrencySites'][$LID];
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($currentCurrency !== $arResult['sitesList'][$crmCode]['currency']) {
|
if ($errorCode === 'ERR_CMS_CURRENCY') {
|
||||||
$errorsText[] = GetMessage('ERR_CURRENCY_SITES') . ' (' . $arResult['sitesList'][$crmCode]['name'] . ')';
|
$errorsText[] = GetMessage($errorCode) . ' (' . $LID . ')';
|
||||||
|
} elseif($errorCode !== '') {
|
||||||
|
$errorsText[] = GetMessage($errorCode) . ' (' . GetMessage('CRM_STORE') . $crmSiteName . ')';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$currentCurrency = $baseCurrency;
|
$LID = $arResult['arSites'][0]['LID'] ?? null;
|
||||||
$LID = $arResult['arSites'][0]['LID'];
|
$cmsCurrency = $arResult['arCurrencySites'][$LID] ?? null;
|
||||||
|
|
||||||
if (isset($arResult['arCurrencySites'][$LID])) {
|
$crmSiteData = reset($arResult['sitesList']);
|
||||||
$currentCurrency = $arResult['arCurrencySites'][$LID];
|
$crmCurrency = $crmSiteData['currency'] ?? null;
|
||||||
}
|
|
||||||
|
|
||||||
$crmSite = reset($arResult['sitesList']);
|
$errorsText[] = GetMessage(CurrencyService::validateCurrency($cmsCurrency, $crmCurrency));
|
||||||
|
|
||||||
if ($currentCurrency !== $crmSite['currency']) {
|
|
||||||
$errorsText[] = GetMessage('ERR_CURRENCY_SITES') . ' (' . $crmSite['name'] . ')';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
17
tests/lib/service/CurrencyServiceTest.php
Normal file
17
tests/lib/service/CurrencyServiceTest.php
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Intaro\RetailCrm\Service\CurrencyService;
|
||||||
|
|
||||||
|
class CurrencyServiceTest extends BitrixTestCase
|
||||||
|
{
|
||||||
|
public function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
}
|
||||||
|
public function testValidateCurrency()
|
||||||
|
{
|
||||||
|
self::assertNotEquals('', CurrencyService::validateCurrency('RUB', 'USD'));
|
||||||
|
self::assertNotEquals('', CurrencyService::validateCurrency('USD', 'RUB'));
|
||||||
|
self::assertEquals('', CurrencyService::validateCurrency('RUB', 'RUB'));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user