2016-09-15 16:42:10 +03:00
|
|
|
<?php
|
2021-08-19 15:46:03 +03:00
|
|
|
|
2024-04-29 11:44:31 +03:00
|
|
|
/**
|
|
|
|
* @category RetailCRM
|
|
|
|
* @package RetailCRM
|
|
|
|
* @author RetailCRM <integration@retailcrm.ru>
|
|
|
|
* @license MIT
|
|
|
|
* @link http://retailcrm.ru
|
|
|
|
* @see http://retailcrm.ru/docs
|
|
|
|
*/
|
|
|
|
|
2023-12-12 16:51:15 +03:00
|
|
|
use Bitrix\Sale\PersonType;
|
2022-03-02 15:40:53 +03:00
|
|
|
use Intaro\RetailCrm\Component\ServiceLocator;
|
2021-09-08 10:19:29 +03:00
|
|
|
use Bitrix\Sale\Delivery\Services\EmptyDeliveryService;
|
|
|
|
use Bitrix\Sale\Internals\OrderPropsTable;
|
|
|
|
use Bitrix\Sale\Internals\StatusTable;
|
|
|
|
use Bitrix\Sale\PaySystem\Manager;
|
2023-12-12 16:51:15 +03:00
|
|
|
use Intaro\RetailCrm\Service\Utils;
|
2021-09-08 10:19:29 +03:00
|
|
|
use RetailCrm\Exception\CurlException;
|
|
|
|
use RetailCrm\Exception\InvalidJsonException;
|
2021-08-19 15:46:03 +03:00
|
|
|
use Intaro\RetailCrm\Service\ManagerService;
|
2023-12-19 17:13:31 +03:00
|
|
|
use Bitrix\Main\UserFieldTable;
|
|
|
|
use Bitrix\Main\UserFieldLangTable;
|
2023-12-12 16:51:15 +03:00
|
|
|
use Bitrix\Sale\Internals\SiteCurrencyTable;
|
2021-08-19 15:46:03 +03:00
|
|
|
|
2016-09-15 16:42:10 +03:00
|
|
|
IncludeModuleLangFile(__FILE__);
|
2022-03-02 15:40:53 +03:00
|
|
|
|
|
|
|
require_once __DIR__ . '/../../lib/component/servicelocator.php';
|
|
|
|
require_once __DIR__ . '/../../lib/service/utils.php';
|
|
|
|
|
2024-04-29 11:44:31 +03:00
|
|
|
/**
|
|
|
|
* class RCrmActions
|
|
|
|
*
|
|
|
|
* @category RetailCRM
|
|
|
|
* @package RetailCRM
|
|
|
|
*/
|
2016-09-15 16:42:10 +03:00
|
|
|
class RCrmActions
|
|
|
|
{
|
|
|
|
public static $MODULE_ID = 'intaro.retailcrm';
|
|
|
|
public static $CRM_ORDER_FAILED_IDS = 'order_failed_ids';
|
2017-09-04 11:36:04 +03:00
|
|
|
public static $CRM_API_VERSION = 'api_version';
|
2022-03-02 15:40:53 +03:00
|
|
|
|
2023-08-30 14:11:04 +03:00
|
|
|
public static function getCurrencySites(): array
|
|
|
|
{
|
|
|
|
$sites = self::getSitesList();
|
2023-12-12 16:51:15 +03:00
|
|
|
$baseCurrency = CCurrency::GetBaseCurrency();
|
2023-08-30 14:11:04 +03:00
|
|
|
$sitesCurrency = [];
|
|
|
|
|
|
|
|
foreach ($sites as $site) {
|
2023-12-12 16:51:15 +03:00
|
|
|
$siteCurrency = SiteCurrencyTable::getCurrency($site['LID']);
|
2023-08-30 14:11:04 +03:00
|
|
|
|
2023-12-12 16:51:15 +03:00
|
|
|
$sitesCurrency[$site['LID']] = !empty($siteCurrency['CURRENCY'])
|
|
|
|
? $siteCurrency['CURRENCY']
|
|
|
|
: $baseCurrency;
|
2023-08-30 14:11:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return $sitesCurrency;
|
|
|
|
}
|
|
|
|
|
2021-09-08 10:19:29 +03:00
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public static function getSitesList(): array
|
2016-10-04 17:57:39 +03:00
|
|
|
{
|
2021-09-08 10:19:29 +03:00
|
|
|
$arSites = [];
|
|
|
|
$rsSites = CSite::GetList($by, $sort, ['ACTIVE' => 'Y']);
|
2022-03-02 15:40:53 +03:00
|
|
|
|
2016-10-04 17:57:39 +03:00
|
|
|
while ($ar = $rsSites->Fetch()) {
|
2018-10-18 12:07:10 +03:00
|
|
|
$arSites[] = $ar;
|
2016-09-15 16:42:10 +03:00
|
|
|
}
|
2018-10-18 12:07:10 +03:00
|
|
|
|
2016-09-15 16:42:10 +03:00
|
|
|
return $arSites;
|
|
|
|
}
|
2018-10-18 12:07:10 +03:00
|
|
|
|
2016-10-04 17:57:39 +03:00
|
|
|
public static function OrderTypesList($arSites)
|
|
|
|
{
|
2023-12-12 16:51:15 +03:00
|
|
|
$orderTypesList = [];
|
|
|
|
|
2016-10-04 17:57:39 +03:00
|
|
|
foreach ($arSites as $site) {
|
2023-12-12 16:51:15 +03:00
|
|
|
$personTypes = PersonType::load($site['LID']);
|
|
|
|
$bitrixOrderTypesList = [];
|
|
|
|
|
2016-10-04 17:57:39 +03:00
|
|
|
foreach ($personTypes as $personType) {
|
|
|
|
if (!array_key_exists($personType['ID'], $orderTypesList)) {
|
2016-09-15 16:42:10 +03:00
|
|
|
$bitrixOrderTypesList[$personType['ID']] = $personType;
|
|
|
|
}
|
2023-12-12 16:51:15 +03:00
|
|
|
|
2016-09-15 16:42:10 +03:00
|
|
|
asort($bitrixOrderTypesList);
|
|
|
|
}
|
2023-12-12 16:51:15 +03:00
|
|
|
|
|
|
|
$orderTypesList += $bitrixOrderTypesList;
|
2016-09-15 16:42:10 +03:00
|
|
|
}
|
2018-10-18 12:07:10 +03:00
|
|
|
|
2016-09-15 16:42:10 +03:00
|
|
|
return $orderTypesList;
|
|
|
|
}
|
2018-10-18 12:07:10 +03:00
|
|
|
|
2016-10-04 17:57:39 +03:00
|
|
|
public static function DeliveryList()
|
|
|
|
{
|
2023-12-12 16:51:15 +03:00
|
|
|
$bitrixDeliveryTypesList = [];
|
2016-09-15 16:42:10 +03:00
|
|
|
$arDeliveryServiceAll = \Bitrix\Sale\Delivery\Services\Manager::getActiveList();
|
2021-09-08 10:19:29 +03:00
|
|
|
$noOrderId = EmptyDeliveryService::getEmptyDeliveryServiceId();
|
2023-12-12 16:51:15 +03:00
|
|
|
$groups = [];
|
|
|
|
|
2016-10-04 17:57:39 +03:00
|
|
|
foreach ($arDeliveryServiceAll as $arDeliveryService) {
|
2017-09-04 11:36:04 +03:00
|
|
|
if ($arDeliveryService['CLASS_NAME'] == '\Bitrix\Sale\Delivery\Services\Group') {
|
|
|
|
$groups[] = $arDeliveryService['ID'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
foreach ($arDeliveryServiceAll as $arDeliveryService) {
|
2018-10-18 12:07:10 +03:00
|
|
|
if ((($arDeliveryService['PARENT_ID'] == '0' || $arDeliveryService['PARENT_ID'] == null) ||
|
2020-04-24 13:18:18 +03:00
|
|
|
in_array($arDeliveryService['PARENT_ID'], $groups)) &&
|
|
|
|
$arDeliveryService['ID'] != $noOrderId &&
|
|
|
|
$arDeliveryService['CLASS_NAME'] != '\Bitrix\Sale\Delivery\Services\Group') {
|
2017-09-22 15:28:19 +03:00
|
|
|
if (in_array($arDeliveryService['PARENT_ID'], $groups)) {
|
|
|
|
$arDeliveryService['PARENT_ID'] = 0;
|
|
|
|
}
|
2016-09-15 16:42:10 +03:00
|
|
|
$bitrixDeliveryTypesList[] = $arDeliveryService;
|
|
|
|
}
|
|
|
|
}
|
2017-09-22 15:28:19 +03:00
|
|
|
|
2016-09-15 16:42:10 +03:00
|
|
|
return $bitrixDeliveryTypesList;
|
2017-09-22 15:28:19 +03:00
|
|
|
}
|
2018-10-18 12:07:10 +03:00
|
|
|
|
2016-10-04 17:57:39 +03:00
|
|
|
public static function PaymentList()
|
|
|
|
{
|
2023-12-12 16:51:15 +03:00
|
|
|
$bitrixPaymentTypesList = [];
|
|
|
|
$dbPaymentAll = Manager::getList(['select' => ['ID', 'NAME'], 'filter' => ['ACTIVE' => 'Y']]);
|
|
|
|
|
2016-10-04 17:57:39 +03:00
|
|
|
while ($payment = $dbPaymentAll->fetch()) {
|
2016-09-15 16:42:10 +03:00
|
|
|
$bitrixPaymentTypesList[] = $payment;
|
|
|
|
}
|
2018-10-18 12:07:10 +03:00
|
|
|
|
2016-09-15 16:42:10 +03:00
|
|
|
return $bitrixPaymentTypesList;
|
2018-10-18 12:07:10 +03:00
|
|
|
}
|
2017-09-04 11:36:04 +03:00
|
|
|
|
2016-10-04 17:57:39 +03:00
|
|
|
public static function StatusesList()
|
|
|
|
{
|
2023-12-12 16:51:15 +03:00
|
|
|
$bitrixPaymentStatusesList = [];
|
|
|
|
$obStatuses = StatusTable::getList([
|
|
|
|
'filter' => ['TYPE' => 'O', '=Bitrix\Sale\Internals\StatusLangTable:STATUS.LID' => LANGUAGE_ID],
|
|
|
|
'select' => ['ID', 'NAME' => 'Bitrix\Sale\Internals\StatusLangTable:STATUS.NAME'],
|
|
|
|
]);
|
|
|
|
|
2016-10-12 11:40:18 +03:00
|
|
|
while ($arStatus = $obStatuses->fetch()) {
|
2023-12-12 16:51:15 +03:00
|
|
|
$bitrixPaymentStatusesList[$arStatus['ID']] = ['ID' => $arStatus['ID'], 'NAME' => $arStatus['NAME']];
|
2016-09-15 16:42:10 +03:00
|
|
|
}
|
2018-10-18 12:07:10 +03:00
|
|
|
|
2016-09-15 16:42:10 +03:00
|
|
|
return $bitrixPaymentStatusesList;
|
2017-09-04 11:36:04 +03:00
|
|
|
}
|
|
|
|
|
2016-10-04 17:57:39 +03:00
|
|
|
public static function OrderPropsList()
|
|
|
|
{
|
2023-12-12 16:51:15 +03:00
|
|
|
$bitrixPropsList = [];
|
2024-01-09 10:44:17 +03:00
|
|
|
$arPropsAll = OrderPropsTable::getList([
|
|
|
|
'select' => ['*'],
|
|
|
|
'filter' => [
|
|
|
|
['CODE' => '_%'],
|
|
|
|
['!=TYPE' => 'LOCATION']
|
|
|
|
]
|
|
|
|
]);
|
|
|
|
|
|
|
|
while ($prop = $arPropsAll->Fetch()) {
|
|
|
|
$bitrixPropsList[$prop['PERSON_TYPE_ID']][] = $prop;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $bitrixPropsList;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getLocationProps()
|
|
|
|
{
|
|
|
|
$bitrixPropsList = [];
|
|
|
|
$arPropsAll = OrderPropsTable::getList([
|
|
|
|
'select' => ['*'],
|
|
|
|
'filter' => [
|
|
|
|
['CODE' => '_%'],
|
|
|
|
['TYPE' => 'LOCATION']
|
|
|
|
]
|
|
|
|
]);
|
2023-12-12 16:51:15 +03:00
|
|
|
|
2016-10-04 17:57:39 +03:00
|
|
|
while ($prop = $arPropsAll->Fetch()) {
|
2016-09-15 16:42:10 +03:00
|
|
|
$bitrixPropsList[$prop['PERSON_TYPE_ID']][] = $prop;
|
|
|
|
}
|
2018-10-18 12:07:10 +03:00
|
|
|
|
2016-09-15 16:42:10 +03:00
|
|
|
return $bitrixPropsList;
|
2018-10-18 12:07:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function PricesExportList()
|
2017-09-04 11:36:04 +03:00
|
|
|
{
|
2023-12-12 16:51:15 +03:00
|
|
|
$catalogExportPrices = [];
|
|
|
|
$dbPriceType = CCatalogGroup::GetList([], [], false, false, ['ID', 'NAME', 'NAME_LANG']);
|
2019-01-16 10:28:11 +03:00
|
|
|
|
2017-09-04 11:36:04 +03:00
|
|
|
while ($arPriceType = $dbPriceType->Fetch())
|
|
|
|
{
|
|
|
|
$catalogExportPrices[$arPriceType['ID']] = $arPriceType;
|
|
|
|
}
|
2018-10-18 12:07:10 +03:00
|
|
|
|
2017-09-04 11:36:04 +03:00
|
|
|
return $catalogExportPrices;
|
2018-10-18 12:07:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function StoresExportList()
|
2017-09-04 11:36:04 +03:00
|
|
|
{
|
2023-12-12 16:51:15 +03:00
|
|
|
$catalogExportStores = [];
|
|
|
|
$dbStores = CCatalogStore::GetList([], ['ACTIVE' => 'Y'], false, false, ['ID', 'TITLE']);
|
|
|
|
|
2017-09-04 11:36:04 +03:00
|
|
|
while ($stores = $dbStores->Fetch()) {
|
|
|
|
$catalogExportStores[] = $stores;
|
|
|
|
}
|
2018-10-18 12:07:10 +03:00
|
|
|
|
2017-09-04 11:36:04 +03:00
|
|
|
return $catalogExportStores;
|
2018-10-18 12:07:10 +03:00
|
|
|
}
|
|
|
|
|
2017-09-04 11:36:04 +03:00
|
|
|
public static function IblocksExportList()
|
|
|
|
{
|
2023-12-12 16:51:15 +03:00
|
|
|
$catalogExportIblocks = [];
|
|
|
|
$dbIblocks = CIBlock::GetList(['IBLOCK_TYPE' => 'ASC', 'NAME' => 'ASC'], ['CHECK_PERMISSIONS' => 'Y', 'MIN_PERMISSION' => 'W']);
|
|
|
|
|
2017-09-04 11:36:04 +03:00
|
|
|
while ($iblock = $dbIblocks->Fetch()) {
|
2021-09-08 10:19:29 +03:00
|
|
|
if ($arCatalog = CCatalog::GetByIDExt($iblock['ID'])) {
|
|
|
|
if($arCatalog['CATALOG_TYPE'] == 'D' || $arCatalog['CATALOG_TYPE'] == 'X' || $arCatalog['CATALOG_TYPE'] == 'P') {
|
2023-12-12 16:51:15 +03:00
|
|
|
$catalogExportIblocks[$iblock['ID']] = [
|
2017-09-04 11:36:04 +03:00
|
|
|
'ID' => $iblock['ID'],
|
|
|
|
'IBLOCK_TYPE_ID' => $iblock['IBLOCK_TYPE_ID'],
|
|
|
|
'LID' => $iblock['LID'],
|
|
|
|
'CODE' => $iblock['CODE'],
|
|
|
|
'NAME' => $iblock['NAME'],
|
2023-12-12 16:51:15 +03:00
|
|
|
];
|
2017-09-04 11:36:04 +03:00
|
|
|
|
2021-09-08 10:19:29 +03:00
|
|
|
if ($arCatalog['CATALOG_TYPE'] == 'X' || $arCatalog['CATALOG_TYPE'] == 'P') {
|
|
|
|
$iblockOffer = CCatalogSKU::GetInfoByProductIBlock($iblock['ID']);
|
2017-09-04 11:36:04 +03:00
|
|
|
$catalogExportIblocks[$iblock['ID']]['SKU'] = $iblockOffer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-10-18 12:07:10 +03:00
|
|
|
|
2017-09-04 11:36:04 +03:00
|
|
|
return $catalogExportIblocks;
|
|
|
|
}
|
2018-10-18 12:07:10 +03:00
|
|
|
|
2016-09-15 16:42:10 +03:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* w+ event in bitrix log
|
|
|
|
*/
|
|
|
|
|
2016-10-04 17:57:39 +03:00
|
|
|
public static function eventLog($auditType, $itemId, $description)
|
|
|
|
{
|
2022-03-02 15:40:53 +03:00
|
|
|
CEventLog::Add([
|
2021-09-08 10:19:29 +03:00
|
|
|
'SEVERITY' => 'SECURITY',
|
|
|
|
'AUDIT_TYPE_ID' => $auditType,
|
|
|
|
'MODULE_ID' => self::$MODULE_ID,
|
|
|
|
'ITEM_ID' => $itemId,
|
|
|
|
'DESCRIPTION' => $description,
|
2022-03-02 15:40:53 +03:00
|
|
|
]);
|
2016-09-15 16:42:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Agent function
|
|
|
|
*
|
|
|
|
* @return self name
|
|
|
|
*/
|
2016-10-04 17:57:39 +03:00
|
|
|
public static function uploadOrdersAgent()
|
|
|
|
{
|
2016-09-15 16:42:10 +03:00
|
|
|
RetailCrmOrder::uploadOrders();
|
|
|
|
$failedIds = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_ORDER_FAILED_IDS, 0));
|
2022-03-02 15:40:53 +03:00
|
|
|
|
2016-09-15 16:42:10 +03:00
|
|
|
if (is_array($failedIds) && !empty($failedIds)) {
|
|
|
|
RetailCrmOrder::uploadOrders(50, true);
|
|
|
|
}
|
|
|
|
|
2017-09-04 11:36:04 +03:00
|
|
|
return;
|
2016-09-15 16:42:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Agent function
|
|
|
|
*
|
|
|
|
* @return self name
|
2023-06-22 15:46:25 +03:00
|
|
|
*
|
|
|
|
* @throws \Throwable
|
2016-09-15 16:42:10 +03:00
|
|
|
*/
|
2016-10-04 17:57:39 +03:00
|
|
|
public static function orderAgent()
|
|
|
|
{
|
2021-08-19 15:46:03 +03:00
|
|
|
if (COption::GetOptionString('main', 'agents_use_crontab', 'N') !== 'N') {
|
2016-09-15 16:42:10 +03:00
|
|
|
define('NO_AGENT_CHECK', true);
|
|
|
|
}
|
|
|
|
|
2023-06-22 15:46:25 +03:00
|
|
|
try {
|
|
|
|
$service = ManagerService::getInstance();
|
|
|
|
$service->synchronizeManagers();
|
|
|
|
|
|
|
|
RetailCrmHistory::customerHistory();
|
|
|
|
RetailCrmHistory::orderHistory();
|
|
|
|
self::uploadOrdersAgent();
|
|
|
|
} catch (\Throwable $exception) {
|
2023-08-22 13:09:20 +03:00
|
|
|
Logger::getInstance()->write(
|
|
|
|
'Fail orderAgent:' . PHP_EOL .
|
2023-06-22 15:46:25 +03:00
|
|
|
$exception->getMessage() . PHP_EOL .
|
|
|
|
'File: ' . $exception->getFile() . PHP_EOL .
|
2023-08-22 13:09:20 +03:00
|
|
|
'Line: ' . $exception->getLine() . PHP_EOL,
|
|
|
|
'orderAgent'
|
2023-06-22 15:46:25 +03:00
|
|
|
);
|
|
|
|
}
|
2018-10-18 12:07:10 +03:00
|
|
|
|
2016-09-15 16:42:10 +03:00
|
|
|
return 'RCrmActions::orderAgent();';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* removes all empty fields from arrays
|
|
|
|
* working with nested arrs
|
|
|
|
*
|
|
|
|
* @param array $arr
|
2022-03-02 15:40:53 +03:00
|
|
|
*
|
2016-09-15 16:42:10 +03:00
|
|
|
* @return array
|
|
|
|
*/
|
2022-03-02 15:40:53 +03:00
|
|
|
public static function clearArr(array $arr): array
|
2016-10-04 17:57:39 +03:00
|
|
|
{
|
2023-12-12 16:51:15 +03:00
|
|
|
/** @var Utils $utils */
|
|
|
|
$utils = ServiceLocator::getOrCreate(Utils::class);
|
|
|
|
|
2022-03-02 15:40:53 +03:00
|
|
|
return $utils->clearArray($arr);
|
2016-09-15 16:42:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
2020-04-24 13:18:18 +03:00
|
|
|
* @param array|bool|\SplFixedArray|string $str in SITE_CHARSET
|
|
|
|
*
|
|
|
|
* @return array|bool|\SplFixedArray|string $str in utf-8
|
2016-09-15 16:42:10 +03:00
|
|
|
*/
|
2016-10-04 17:57:39 +03:00
|
|
|
public static function toJSON($str)
|
|
|
|
{
|
2023-12-12 16:51:15 +03:00
|
|
|
/** @var Utils $utils */
|
|
|
|
$utils = ServiceLocator::getOrCreate(Utils::class);
|
|
|
|
|
2022-03-02 15:40:53 +03:00
|
|
|
return $utils->toUTF8($str);
|
2016-09-15 16:42:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
2020-04-24 13:18:18 +03:00
|
|
|
* @param string|array|\SplFixedArray $str in utf-8
|
|
|
|
*
|
|
|
|
* @return array|bool|\SplFixedArray|string $str in SITE_CHARSET
|
2016-09-15 16:42:10 +03:00
|
|
|
*/
|
2016-10-04 17:57:39 +03:00
|
|
|
public static function fromJSON($str)
|
|
|
|
{
|
2022-04-13 16:59:27 +03:00
|
|
|
if ($str === null) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2023-12-12 16:51:15 +03:00
|
|
|
/** @var Utils $utils */
|
|
|
|
$utils = ServiceLocator::getOrCreate(Utils::class);
|
2023-10-13 12:49:09 +03:00
|
|
|
|
2022-03-02 15:40:53 +03:00
|
|
|
return $utils->fromUTF8($str);
|
2016-09-15 16:42:10 +03:00
|
|
|
}
|
|
|
|
|
2019-05-31 15:51:40 +03:00
|
|
|
/**
|
|
|
|
* Extracts payment ID or client ID from payment externalId
|
|
|
|
* Payment ID - pass nothing or 'id' as second argument
|
|
|
|
* Client ID - pass 'client_id' as second argument
|
|
|
|
*
|
|
|
|
* @param $externalId
|
|
|
|
* @param string $data
|
|
|
|
* @return bool|string
|
|
|
|
*/
|
|
|
|
public static function getFromPaymentExternalId($externalId, $data = 'id')
|
|
|
|
{
|
|
|
|
switch ($data) {
|
|
|
|
case 'id':
|
|
|
|
if (false === strpos($externalId, '_')) {
|
|
|
|
return $externalId;
|
|
|
|
} else {
|
|
|
|
return substr($externalId, 0, strpos($externalId, '_'));
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'client_id':
|
|
|
|
if (false === strpos($externalId, '_')) {
|
|
|
|
return '';
|
|
|
|
} else {
|
|
|
|
return substr($externalId, strpos($externalId, '_'), count($externalId));
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2019-07-03 13:11:20 +03:00
|
|
|
/**
|
|
|
|
* Returns true if provided externalId in new format (id_clientId)
|
|
|
|
*
|
|
|
|
* @param $externalId
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public static function isNewExternalId($externalId)
|
|
|
|
{
|
|
|
|
return !(false === strpos($externalId, '_'));
|
|
|
|
}
|
|
|
|
|
2019-05-31 15:51:40 +03:00
|
|
|
/**
|
|
|
|
* Generates payment external ID
|
|
|
|
*
|
|
|
|
* @param $id
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function generatePaymentExternalId($id)
|
|
|
|
{
|
|
|
|
return sprintf(
|
|
|
|
'%s_%s',
|
|
|
|
$id,
|
|
|
|
COption::GetOptionString(self::$MODULE_ID, 'client_id', 0)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-02-27 15:29:43 +03:00
|
|
|
/**
|
|
|
|
* Unserialize array
|
2018-07-16 16:01:19 +03:00
|
|
|
*
|
2018-02-27 15:29:43 +03:00
|
|
|
* @param string $string
|
2018-07-16 16:01:19 +03:00
|
|
|
*
|
|
|
|
* @return mixed
|
2018-02-27 15:29:43 +03:00
|
|
|
*/
|
|
|
|
public static function unserializeArrayRecursive($string)
|
|
|
|
{
|
2018-07-16 16:01:19 +03:00
|
|
|
if ($string === false || empty($string)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-02-27 15:29:43 +03:00
|
|
|
if (is_string($string)) {
|
|
|
|
$string = unserialize($string);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_array($string)) {
|
2018-03-22 16:11:04 +03:00
|
|
|
$string = self::unserializeArrayRecursive($string);
|
2018-02-27 15:29:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return $string;
|
|
|
|
}
|
|
|
|
|
2021-08-19 15:46:03 +03:00
|
|
|
/**
|
|
|
|
* @param string|null $fio
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public static function explodeFio(?string $fio): array
|
2016-10-04 17:57:39 +03:00
|
|
|
{
|
2021-08-19 15:46:03 +03:00
|
|
|
$result = [];
|
2016-12-13 14:01:48 +03:00
|
|
|
$fio = preg_replace('|[\s]+|s', ' ', trim($fio));
|
2021-08-19 15:46:03 +03:00
|
|
|
|
2017-09-04 11:36:04 +03:00
|
|
|
if (empty($fio)) {
|
|
|
|
return $result;
|
|
|
|
} else {
|
2021-09-08 10:19:29 +03:00
|
|
|
$newFio = explode(' ', $fio, 3);
|
2017-09-04 11:36:04 +03:00
|
|
|
}
|
2018-10-18 12:07:10 +03:00
|
|
|
|
2016-09-15 16:42:10 +03:00
|
|
|
switch (count($newFio)) {
|
|
|
|
default:
|
|
|
|
case 0:
|
2021-08-19 15:46:03 +03:00
|
|
|
$result['firstName'] = $fio;
|
2016-09-15 16:42:10 +03:00
|
|
|
break;
|
|
|
|
case 1:
|
2021-08-19 15:46:03 +03:00
|
|
|
$result['firstName'] = $newFio[0];
|
2016-09-15 16:42:10 +03:00
|
|
|
break;
|
|
|
|
case 2:
|
2021-08-19 15:46:03 +03:00
|
|
|
$result = [
|
2016-09-15 16:42:10 +03:00
|
|
|
'lastName' => $newFio[0],
|
2021-08-19 15:46:03 +03:00
|
|
|
'firstName' => $newFio[1],
|
|
|
|
];
|
2016-09-15 16:42:10 +03:00
|
|
|
break;
|
|
|
|
case 3:
|
2021-08-19 15:46:03 +03:00
|
|
|
$result = [
|
2016-09-15 16:42:10 +03:00
|
|
|
'lastName' => $newFio[0],
|
|
|
|
'firstName' => $newFio[1],
|
2021-08-19 15:46:03 +03:00
|
|
|
'patronymic' => $newFio[2],
|
|
|
|
];
|
2016-09-15 16:42:10 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
2023-12-19 17:13:31 +03:00
|
|
|
public static function customOrderPropList()
|
|
|
|
{
|
|
|
|
$typeMatched = [
|
|
|
|
'STRING' => 'STRING',
|
|
|
|
'NUMBER' => 'NUMERIC',
|
|
|
|
'Y/N' => 'BOOLEAN',
|
|
|
|
'DATE' => 'DATE'
|
|
|
|
];
|
|
|
|
|
|
|
|
//Базовые свойства заказа и используемые свойства в функционале модуля
|
|
|
|
$bannedCodeList = [
|
|
|
|
'FIO',
|
|
|
|
'EMAIL',
|
|
|
|
'PHONE',
|
|
|
|
'ZIP',
|
|
|
|
'CITY',
|
|
|
|
'LOCATION',
|
|
|
|
'ADDRESS',
|
|
|
|
'COMPANY',
|
|
|
|
'COMPANY_ADR',
|
|
|
|
'INN',
|
|
|
|
'KPP',
|
|
|
|
'CONTACT_PERSON',
|
|
|
|
'FAX',
|
|
|
|
'LP_BONUS_INFO',
|
|
|
|
'LP_DISCOUNT_INFO',
|
|
|
|
''
|
|
|
|
];
|
|
|
|
|
|
|
|
$listPersons = PersonType::getList([
|
|
|
|
'select' => ['ID', 'NAME'],
|
|
|
|
'filter' => ['ENTITY_REGISTRY_TYPE' => 'ORDER']
|
|
|
|
])->fetchAll();
|
|
|
|
|
|
|
|
$persons = [];
|
|
|
|
|
|
|
|
foreach ($listPersons as $person) {
|
|
|
|
$persons[$person['ID']] = $person['NAME'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$propsList = OrderPropsTable::getList([
|
|
|
|
'select' => ['ID', 'CODE', 'NAME', 'PERSON_TYPE_ID', 'TYPE'],
|
|
|
|
'filter' => [
|
|
|
|
['!=CODE' => $bannedCodeList],
|
|
|
|
['?TYPE' => 'STRING | NUMBER | Y/N | DATE'],
|
|
|
|
['MULTIPLE' => 'N'],
|
|
|
|
['ACTIVE' => 'Y']
|
|
|
|
]
|
|
|
|
])->fetchAll();
|
|
|
|
|
|
|
|
$resultList = [];
|
|
|
|
|
|
|
|
foreach ($propsList as $prop) {
|
|
|
|
$type = $typeMatched[$prop['TYPE']] ?? $prop['TYPE'];
|
|
|
|
$key = $prop['ID'] . '#' . $prop['CODE'];
|
|
|
|
$resultList[$type . '_TYPE'][$key] = $prop['NAME'] . ' (' . $persons[$prop['PERSON_TYPE_ID']] . ')';
|
|
|
|
}
|
|
|
|
|
|
|
|
ksort($resultList);
|
|
|
|
|
|
|
|
return $resultList;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function customUserFieldList()
|
|
|
|
{
|
|
|
|
$typeMatched = [
|
|
|
|
'string' => 'STRING',
|
|
|
|
'double' => 'NUMERIC',
|
|
|
|
'boolean' => 'BOOLEAN',
|
|
|
|
'date' => 'DATE',
|
|
|
|
'integer' => 'INTEGER'
|
|
|
|
];
|
|
|
|
|
|
|
|
$userFields = UserFieldTable::getList([
|
|
|
|
'select' => ['ID', 'FIELD_NAME', 'USER_TYPE_ID'],
|
|
|
|
'filter' => [
|
|
|
|
['ENTITY_ID' => 'USER'],
|
|
|
|
['?FIELD_NAME' => '~%INTARO%'],
|
|
|
|
['!=FIELD_NAME' => 'UF_SUBSCRIBE_USER_EMAIL'],
|
|
|
|
['!=USER_TYPE_ID' => 'datetime'],
|
|
|
|
['?USER_TYPE_ID' => 'string | date | integer | double | boolean'],
|
|
|
|
['MULTIPLE' => 'N'],
|
|
|
|
]
|
|
|
|
])->fetchAll();
|
|
|
|
|
|
|
|
$resultList = [];
|
|
|
|
|
|
|
|
foreach ($userFields as $userField) {
|
|
|
|
$label = UserFieldLangTable::getList([
|
|
|
|
'select' => ['EDIT_FORM_LABEL'],
|
|
|
|
'filter' => [
|
|
|
|
["USER_FIELD_ID" => $userField['ID']],
|
|
|
|
['LANGUAGE_ID' => LANGUAGE_ID]
|
|
|
|
]
|
|
|
|
])->fetch();
|
|
|
|
|
|
|
|
$type = $typeMatched[$userField['USER_TYPE_ID']] ?? $userField['USER_TYPE_ID'];
|
|
|
|
$resultList[$type . '_TYPE'][$userField['FIELD_NAME']] = $label['EDIT_FORM_LABEL'];
|
|
|
|
}
|
|
|
|
|
|
|
|
ksort($resultList);
|
|
|
|
|
|
|
|
return $resultList;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getTypeUserField()
|
|
|
|
{
|
|
|
|
$userFields = UserFieldTable::getList([
|
|
|
|
'select' => ['FIELD_NAME', 'USER_TYPE_ID'],
|
|
|
|
'filter' => [
|
|
|
|
['ENTITY_ID' => 'USER'],
|
|
|
|
['?FIELD_NAME' => '~%INTARO%'],
|
|
|
|
['!=FIELD_NAME' => 'UF_SUBSCRIBE_USER_EMAIL'],
|
|
|
|
['?USER_TYPE_ID' => 'string | date | datetime | integer | double | boolean'],
|
|
|
|
['MULTIPLE' => 'N'],
|
|
|
|
]
|
|
|
|
])->fetchAll();
|
|
|
|
|
|
|
|
$result = [];
|
|
|
|
|
|
|
|
foreach ($userFields as $userField) {
|
|
|
|
$result[$userField['FIELD_NAME']] = $userField['USER_TYPE_ID'];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function convertCmsFieldToCrmValue($value, $type)
|
|
|
|
{
|
|
|
|
$result = $value;
|
|
|
|
|
|
|
|
switch ($type) {
|
|
|
|
case 'boolean':
|
|
|
|
$result = $value === '1' ? 1 : 0;
|
|
|
|
break;
|
|
|
|
case 'Y/N':
|
|
|
|
$result = $result === 'Y' ? 1 : 0;
|
|
|
|
break;
|
|
|
|
case 'STRING':
|
|
|
|
case 'string':
|
|
|
|
$result = strlen($value) <= 500 ? $value : '';
|
|
|
|
break;
|
|
|
|
case 'datetime':
|
|
|
|
$result = date('Y-m-d', strtotime($value));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function convertCrmValueToCmsField($crmValue, $type)
|
|
|
|
{
|
|
|
|
$result = $crmValue;
|
|
|
|
|
|
|
|
switch ($type) {
|
|
|
|
case 'Y/N':
|
|
|
|
case 'boolean':
|
|
|
|
$result = $crmValue == 1 ? 'Y' : 'N';
|
|
|
|
break;
|
|
|
|
case 'DATE':
|
|
|
|
case 'date':
|
|
|
|
if (empty($crmValue)) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
$result = date('d.m.Y', strtotime($crmValue));
|
|
|
|
} catch (\Exception $exception) {
|
|
|
|
$result = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
case 'STRING':
|
|
|
|
case 'string':
|
|
|
|
case 'text':
|
|
|
|
$result = strlen($crmValue) <= 500 ? $crmValue : '';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
2023-10-24 12:53:02 +03:00
|
|
|
public static function sendConfiguration($api, $active = true)
|
2018-10-18 12:07:10 +03:00
|
|
|
{
|
|
|
|
$scheme = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
|
|
|
|
$baseUrl = $scheme . $_SERVER['HTTP_HOST'];
|
|
|
|
$integrationCode = 'bitrix';
|
|
|
|
$logo = 'https://s3.eu-central-1.amazonaws.com/retailcrm-billing/images/5af47fe682bf2-1c-bitrix-logo.svg';
|
|
|
|
$accountUrl = $baseUrl . '/bitrix/admin';
|
|
|
|
|
|
|
|
$clientId = COption::GetOptionString(self::$MODULE_ID, 'client_id', 0);
|
|
|
|
|
|
|
|
if (!$clientId) {
|
|
|
|
$clientId = uniqid();
|
2023-10-24 12:53:02 +03:00
|
|
|
|
2018-10-18 12:07:10 +03:00
|
|
|
COption::SetOptionString(self::$MODULE_ID, 'client_id', $clientId);
|
|
|
|
}
|
|
|
|
|
|
|
|
$code = $integrationCode . '-' . $clientId;
|
|
|
|
|
2023-10-24 12:53:02 +03:00
|
|
|
$configuration = [
|
2023-09-01 14:06:23 +03:00
|
|
|
'clientId' => $clientId,
|
|
|
|
'code' => $code,
|
|
|
|
'integrationCode' => $integrationCode,
|
|
|
|
'active' => $active,
|
|
|
|
'name' => GetMessage('API_MODULE_NAME'),
|
|
|
|
'logo' => $logo,
|
|
|
|
'baseUrl' => $baseUrl,
|
|
|
|
'accountUrl' => $accountUrl
|
2023-10-24 12:53:02 +03:00
|
|
|
];
|
2018-10-18 12:07:10 +03:00
|
|
|
|
2023-09-01 14:06:23 +03:00
|
|
|
self::apiMethod($api, 'integrationModulesEdit', __METHOD__, $configuration);
|
2018-10-18 12:07:10 +03:00
|
|
|
}
|
|
|
|
|
2016-10-04 17:57:39 +03:00
|
|
|
public static function apiMethod($api, $methodApi, $method, $params, $site = null)
|
|
|
|
{
|
|
|
|
switch ($methodApi) {
|
2018-10-18 12:07:10 +03:00
|
|
|
case 'ordersPaymentDelete':
|
2017-09-04 11:36:04 +03:00
|
|
|
case 'ordersHistory':
|
2018-10-18 12:07:10 +03:00
|
|
|
case 'customerHistory':
|
2017-09-04 11:36:04 +03:00
|
|
|
case 'ordersFixExternalIds':
|
|
|
|
case 'customersFixExternalIds':
|
2020-04-24 13:18:18 +03:00
|
|
|
case 'customersCorporateContacts':
|
|
|
|
case 'customersList':
|
|
|
|
case 'customersCorporateList':
|
2021-07-08 16:29:34 +03:00
|
|
|
return self::proxy($api, $methodApi, $method, [$params]);
|
2017-09-04 11:36:04 +03:00
|
|
|
case 'orderGet':
|
2021-07-08 16:29:34 +03:00
|
|
|
return self::proxy($api, 'ordersGet', $method, [$params, 'id', $site]);
|
2018-10-18 12:07:10 +03:00
|
|
|
|
2016-09-15 16:42:10 +03:00
|
|
|
case 'ordersGet':
|
|
|
|
case 'ordersEdit':
|
|
|
|
case 'customersGet':
|
|
|
|
case 'customersEdit':
|
2020-08-25 10:30:16 +03:00
|
|
|
case 'customersCorporateGet':
|
2021-07-08 16:29:34 +03:00
|
|
|
return self::proxy($api, $methodApi, $method, [$params, 'externalId', $site]);
|
2020-08-25 10:30:16 +03:00
|
|
|
case 'customersCorporateGetById':
|
2021-07-08 16:29:34 +03:00
|
|
|
return self::proxy($api, 'customersCorporateGet', $method, [$params, 'id', $site]);
|
2020-04-24 13:18:18 +03:00
|
|
|
case 'customersGetById':
|
2021-07-08 16:29:34 +03:00
|
|
|
return self::proxy($api, 'customersGet', $method, [$params, 'id', $site]);
|
2018-10-18 12:07:10 +03:00
|
|
|
|
2017-10-24 11:41:11 +03:00
|
|
|
case 'paymentEditById':
|
2021-07-08 16:29:34 +03:00
|
|
|
return self::proxy($api, 'ordersPaymentEdit', $method, [$params, 'id', $site]);
|
2018-10-18 12:07:10 +03:00
|
|
|
|
2017-10-24 11:41:11 +03:00
|
|
|
case 'paymentEditByExternalId':
|
2021-07-08 16:29:34 +03:00
|
|
|
return self::proxy($api, 'ordersPaymentEdit', $method, [$params, 'externalId', $site]);
|
|
|
|
case 'customersCorporateEdit':
|
|
|
|
return self::proxy($api, 'customersCorporateEdit', $method, [$params, 'externalId', $site]);
|
2023-04-11 11:57:06 +03:00
|
|
|
case 'cartGet':
|
|
|
|
return self::proxy($api, $methodApi, $method, [$params, $site, 'externalId']);
|
|
|
|
case 'cartSet':
|
|
|
|
case 'cartClear':
|
|
|
|
return self::proxy($api, $methodApi, $method, [$params, $site]);
|
2016-09-15 16:42:10 +03:00
|
|
|
default:
|
2023-12-12 16:51:15 +03:00
|
|
|
return self::proxy($api, $methodApi, $method, [$params, $site]);
|
2017-10-24 11:41:11 +03:00
|
|
|
}
|
2017-09-04 11:36:04 +03:00
|
|
|
}
|
2017-11-13 11:05:11 +03:00
|
|
|
|
2018-07-16 16:01:19 +03:00
|
|
|
private static function proxy($api, $methodApi, $method, $params) {
|
2017-09-04 11:36:04 +03:00
|
|
|
$version = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_VERSION, 0);
|
|
|
|
try {
|
2023-12-12 16:51:15 +03:00
|
|
|
$result = call_user_func_array([$api, $methodApi], $params);
|
2016-09-15 16:42:10 +03:00
|
|
|
|
2020-04-24 13:18:18 +03:00
|
|
|
if (!$result) {
|
|
|
|
$err = new RuntimeException(
|
2021-09-08 10:19:29 +03:00
|
|
|
$methodApi . ': Got null instead of valid result!'
|
2020-04-24 13:18:18 +03:00
|
|
|
);
|
|
|
|
Logger::getInstance()->write(sprintf(
|
|
|
|
'%s%s%s',
|
|
|
|
$err->getMessage(),
|
|
|
|
PHP_EOL,
|
|
|
|
$err->getTraceAsString()
|
|
|
|
), 'apiErrors');
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-09-04 11:36:04 +03:00
|
|
|
if ($result->getStatusCode() !== 200 && $result->getStatusCode() !== 201) {
|
2020-04-24 13:18:18 +03:00
|
|
|
if ($methodApi == 'ordersGet'
|
|
|
|
|| $methodApi == 'customersGet'
|
2020-08-25 10:30:16 +03:00
|
|
|
|| $methodApi == 'customersCorporateGet'
|
2020-04-24 13:18:18 +03:00
|
|
|
) {
|
2023-12-12 16:51:15 +03:00
|
|
|
Logger::getInstance()->write([
|
2017-09-04 11:36:04 +03:00
|
|
|
'api' => $version,
|
|
|
|
'methodApi' => $methodApi,
|
|
|
|
'errorMsg' => !empty($result['errorMsg']) ? $result['errorMsg'] : '',
|
|
|
|
'errors' => !empty($result['errors']) ? $result['errors'] : '',
|
|
|
|
'params' => $params
|
2023-12-12 16:51:15 +03:00
|
|
|
], 'apiErrors');
|
2017-09-04 11:36:04 +03:00
|
|
|
} elseif ($methodApi == 'customersUpload' || $methodApi == 'ordersUpload') {
|
2023-12-12 16:51:15 +03:00
|
|
|
Logger::getInstance()->write([
|
2017-09-04 11:36:04 +03:00
|
|
|
'api' => $version,
|
|
|
|
'methodApi' => $methodApi,
|
|
|
|
'errorMsg' => !empty($result['errorMsg']) ? $result['errorMsg'] : '',
|
|
|
|
'errors' => !empty($result['errors']) ? $result['errors'] : '',
|
|
|
|
'params' => $params
|
2023-12-12 16:51:15 +03:00
|
|
|
], 'uploadApiErrors');
|
2023-08-29 17:40:10 +03:00
|
|
|
} elseif ($methodApi == 'cartGet') {
|
|
|
|
Logger::getInstance()->write(
|
|
|
|
[
|
|
|
|
'api' => $version,
|
|
|
|
'methodApi' => $methodApi,
|
|
|
|
'errorMsg' => !empty($result['errorMsg']) ? $result['errorMsg'] : '',
|
|
|
|
'errors' => !empty($result['errors']) ? $result['errors'] : '',
|
|
|
|
'params' => $params,
|
|
|
|
],
|
|
|
|
'apiErrors'
|
|
|
|
);
|
2017-09-04 11:36:04 +03:00
|
|
|
} else {
|
2020-04-24 13:18:18 +03:00
|
|
|
self::eventLog(
|
|
|
|
__CLASS__ . '::' . $method,
|
|
|
|
'RetailCrm\ApiClient::' . $methodApi,
|
|
|
|
!empty($result['errorMsg']) ? $result['errorMsg'] : ''
|
|
|
|
);
|
2023-08-29 17:40:10 +03:00
|
|
|
|
2023-12-12 16:51:15 +03:00
|
|
|
Logger::getInstance()->write([
|
2017-09-04 11:36:04 +03:00
|
|
|
'api' => $version,
|
|
|
|
'methodApi' => $methodApi,
|
|
|
|
'errorMsg' => !empty($result['errorMsg']) ? $result['errorMsg'] : '',
|
|
|
|
'errors' => !empty($result['errors']) ? $result['errors'] : '',
|
2020-07-22 15:11:27 +03:00
|
|
|
'params' => $params,
|
2023-12-12 16:51:15 +03:00
|
|
|
], 'apiErrors');
|
2016-09-15 16:42:10 +03:00
|
|
|
}
|
2017-11-13 11:05:11 +03:00
|
|
|
|
2017-09-04 11:36:04 +03:00
|
|
|
if (function_exists('retailCrmApiResult')) {
|
|
|
|
retailCrmApiResult($methodApi, false, $result->getStatusCode());
|
|
|
|
}
|
2017-11-13 11:05:11 +03:00
|
|
|
|
2017-09-04 11:36:04 +03:00
|
|
|
if ($result->getStatusCode() == 460) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2021-09-08 10:19:29 +03:00
|
|
|
} catch (CurlException $e) {
|
2020-04-24 13:18:18 +03:00
|
|
|
static::logException(
|
|
|
|
$method,
|
|
|
|
$methodApi,
|
|
|
|
'CurlException',
|
|
|
|
'CurlException',
|
|
|
|
$e,
|
|
|
|
$version,
|
|
|
|
$params
|
2017-09-04 11:36:04 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
} catch (InvalidArgumentException $e) {
|
2020-04-24 13:18:18 +03:00
|
|
|
static::logException(
|
|
|
|
$method,
|
|
|
|
$methodApi,
|
|
|
|
'InvalidArgumentException',
|
|
|
|
'ArgumentException',
|
|
|
|
$e,
|
|
|
|
$version,
|
|
|
|
$params
|
2017-09-04 11:36:04 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
return false;
|
2021-09-08 10:19:29 +03:00
|
|
|
} catch (InvalidJsonException $e) {
|
2020-04-24 13:18:18 +03:00
|
|
|
static::logException(
|
|
|
|
$method,
|
|
|
|
$methodApi,
|
|
|
|
'InvalidJsonException',
|
|
|
|
'ArgumentException',
|
|
|
|
$e,
|
|
|
|
$version,
|
|
|
|
$params
|
2018-07-16 16:01:19 +03:00
|
|
|
);
|
2017-09-04 11:36:04 +03:00
|
|
|
}
|
2017-11-13 11:05:11 +03:00
|
|
|
|
2017-09-04 11:36:04 +03:00
|
|
|
if (function_exists('retailCrmApiResult')) {
|
2020-04-24 13:18:18 +03:00
|
|
|
retailCrmApiResult($methodApi, true, isset($result) ? $result->getStatusCode() : 0);
|
2017-09-04 11:36:04 +03:00
|
|
|
}
|
2017-11-13 11:05:11 +03:00
|
|
|
|
2018-07-16 16:01:19 +03:00
|
|
|
return isset($result) ? $result : false;
|
2016-09-15 16:42:10 +03:00
|
|
|
}
|
2020-04-24 13:18:18 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Log exception into log file and event log
|
|
|
|
*
|
|
|
|
* @param string $method
|
|
|
|
* @param string $methodApi
|
|
|
|
* @param string $exceptionName
|
|
|
|
* @param string $apiResultExceptionName
|
|
|
|
* @param \Exception|\Error|\Throwable $exception
|
|
|
|
* @param string $version
|
|
|
|
* @param array $params
|
|
|
|
*/
|
|
|
|
protected static function logException(
|
|
|
|
$method,
|
|
|
|
$methodApi,
|
|
|
|
$exceptionName,
|
|
|
|
$apiResultExceptionName,
|
|
|
|
$exception,
|
|
|
|
$version,
|
|
|
|
$params
|
|
|
|
) {
|
|
|
|
self::eventLog(
|
|
|
|
__CLASS__ . '::' . $method, 'RetailCrm\ApiClient::' . $methodApi . '::' . $exceptionName,
|
|
|
|
$exception->getCode() . ': ' . $exception->getMessage()
|
|
|
|
);
|
|
|
|
|
2023-12-12 16:51:15 +03:00
|
|
|
Logger::getInstance()->write([
|
2020-04-24 13:18:18 +03:00
|
|
|
'api' => $version,
|
|
|
|
'methodApi' => $methodApi,
|
|
|
|
'errorMsg' => $exception->getMessage(),
|
|
|
|
'errors' => $exception->getCode(),
|
|
|
|
'params' => $params
|
2023-12-12 16:51:15 +03:00
|
|
|
], 'apiErrors');
|
2020-04-24 13:18:18 +03:00
|
|
|
|
|
|
|
if (function_exists('retailCrmApiResult')) {
|
|
|
|
retailCrmApiResult($methodApi, false, $apiResultExceptionName);
|
|
|
|
}
|
|
|
|
}
|
2016-09-15 16:42:10 +03:00
|
|
|
}
|