1
0
mirror of synced 2025-01-19 01:11:40 +03:00

multisite order export bug (#208)

This commit is contained in:
Сергей Чазов 2021-09-08 10:19:29 +03:00 committed by GitHub
parent 30ef0ebf8a
commit 9354bca0b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 475 additions and 433 deletions

View File

@ -1,5 +1,11 @@
<?php <?php
use Bitrix\Sale\Delivery\Services\EmptyDeliveryService;
use Bitrix\Sale\Internals\OrderPropsTable;
use Bitrix\Sale\Internals\StatusTable;
use Bitrix\Sale\PaySystem\Manager;
use RetailCrm\Exception\CurlException;
use RetailCrm\Exception\InvalidJsonException;
use Intaro\RetailCrm\Service\ManagerService; use Intaro\RetailCrm\Service\ManagerService;
IncludeModuleLangFile(__FILE__); IncludeModuleLangFile(__FILE__);
@ -8,13 +14,16 @@ 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';
const CANCEL_PROPERTY_CODE = 'INTAROCRM_IS_CANCELED'; /**
* @return array
public static function SitesList() */
public static function getSitesList(): array
{ {
$arSites = array(); $arSites = [];
$rsSites = CSite::GetList($by, $sort, array('ACTIVE' => 'Y')); $rsSites = CSite::GetList($by, $sort, ['ACTIVE' => 'Y']);
while ($ar = $rsSites->Fetch()) { while ($ar = $rsSites->Fetch()) {
$arSites[] = $ar; $arSites[] = $ar;
} }
@ -44,7 +53,7 @@ class RCrmActions
{ {
$bitrixDeliveryTypesList = array(); $bitrixDeliveryTypesList = array();
$arDeliveryServiceAll = \Bitrix\Sale\Delivery\Services\Manager::getActiveList(); $arDeliveryServiceAll = \Bitrix\Sale\Delivery\Services\Manager::getActiveList();
$noOrderId = \Bitrix\Sale\Delivery\Services\EmptyDeliveryService::getEmptyDeliveryServiceId(); $noOrderId = EmptyDeliveryService::getEmptyDeliveryServiceId();
$groups = array(); $groups = array();
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') {
@ -69,7 +78,7 @@ class RCrmActions
public static function PaymentList() public static function PaymentList()
{ {
$bitrixPaymentTypesList = array(); $bitrixPaymentTypesList = array();
$dbPaymentAll = \Bitrix\Sale\PaySystem\Manager::getList(array( $dbPaymentAll = Manager::getList(array(
'select' => array('ID', 'NAME'), 'select' => array('ID', 'NAME'),
'filter' => array('ACTIVE' => 'Y') 'filter' => array('ACTIVE' => 'Y')
)); ));
@ -83,9 +92,9 @@ class RCrmActions
public static function StatusesList() public static function StatusesList()
{ {
$bitrixPaymentStatusesList = array(); $bitrixPaymentStatusesList = array();
$obStatuses = \Bitrix\Sale\Internals\StatusTable::getList(array( $obStatuses = StatusTable::getList(array(
'filter' => array('TYPE' => 'O', '=Bitrix\Sale\Internals\StatusLangTable:STATUS.LID' => LANGUAGE_ID), 'filter' => array('TYPE' => 'O', '=Bitrix\Sale\Internals\StatusLangTable:STATUS.LID' => LANGUAGE_ID),
'select' => array('ID', "NAME" => 'Bitrix\Sale\Internals\StatusLangTable:STATUS.NAME') 'select' => array('ID', 'NAME' => 'Bitrix\Sale\Internals\StatusLangTable:STATUS.NAME')
)); ));
while ($arStatus = $obStatuses->fetch()) { while ($arStatus = $obStatuses->fetch()) {
$bitrixPaymentStatusesList[$arStatus['ID']] = array( $bitrixPaymentStatusesList[$arStatus['ID']] = array(
@ -100,7 +109,7 @@ class RCrmActions
public static function OrderPropsList() public static function OrderPropsList()
{ {
$bitrixPropsList = array(); $bitrixPropsList = array();
$arPropsAll = \Bitrix\Sale\Internals\OrderPropsTable::getList(array( $arPropsAll = OrderPropsTable::getList(array(
'select' => array('*'), 'select' => array('*'),
'filter' => array('CODE' => '_%') 'filter' => array('CODE' => '_%')
)); ));
@ -133,7 +142,7 @@ class RCrmActions
public static function StoresExportList() public static function StoresExportList()
{ {
$catalogExportStores = array(); $catalogExportStores = array();
$dbStores = CCatalogStore::GetList(array(), array("ACTIVE" => "Y"), false, false, array('ID', 'TITLE')); $dbStores = CCatalogStore::GetList(array(), array('ACTIVE' => 'Y'), false, false, array('ID', 'TITLE'));
while ($stores = $dbStores->Fetch()) { while ($stores = $dbStores->Fetch()) {
$catalogExportStores[] = $stores; $catalogExportStores[] = $stores;
} }
@ -144,10 +153,10 @@ class RCrmActions
public static function IblocksExportList() public static function IblocksExportList()
{ {
$catalogExportIblocks = array(); $catalogExportIblocks = array();
$dbIblocks = CIBlock::GetList(array("IBLOCK_TYPE" => "ASC", "NAME" => "ASC"), array('CHECK_PERMISSIONS' => 'Y','MIN_PERMISSION' => 'W')); $dbIblocks = CIBlock::GetList(array('IBLOCK_TYPE' => 'ASC', 'NAME' => 'ASC'), array('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']] = array(
'ID' => $iblock['ID'], 'ID' => $iblock['ID'],
'IBLOCK_TYPE_ID' => $iblock['IBLOCK_TYPE_ID'], 'IBLOCK_TYPE_ID' => $iblock['IBLOCK_TYPE_ID'],
@ -156,8 +165,8 @@ class RCrmActions
'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']);
$catalogExportIblocks[$iblock['ID']]['SKU'] = $iblockOffer; $catalogExportIblocks[$iblock['ID']]['SKU'] = $iblockOffer;
} }
} }
@ -175,11 +184,11 @@ class RCrmActions
public static function eventLog($auditType, $itemId, $description) public static function eventLog($auditType, $itemId, $description)
{ {
CEventLog::Add(array( CEventLog::Add(array(
"SEVERITY" => "SECURITY", 'SEVERITY' => 'SECURITY',
"AUDIT_TYPE_ID" => $auditType, 'AUDIT_TYPE_ID' => $auditType,
"MODULE_ID" => self::$MODULE_ID, 'MODULE_ID' => self::$MODULE_ID,
"ITEM_ID" => $itemId, 'ITEM_ID' => $itemId,
"DESCRIPTION" => $description, 'DESCRIPTION' => $description,
)); ));
} }
@ -373,7 +382,7 @@ class RCrmActions
if (empty($fio)) { if (empty($fio)) {
return $result; return $result;
} else { } else {
$newFio = explode(" ", $fio, 3); $newFio = explode(' ', $fio, 3);
} }
switch (count($newFio)) { switch (count($newFio)) {
@ -490,7 +499,7 @@ class RCrmActions
if (!$result) { if (!$result) {
$err = new RuntimeException( $err = new RuntimeException(
$methodApi . ": Got null instead of valid result!" $methodApi . ': Got null instead of valid result!'
); );
Logger::getInstance()->write(sprintf( Logger::getInstance()->write(sprintf(
'%s%s%s', '%s%s%s',
@ -548,7 +557,7 @@ class RCrmActions
return false; return false;
} }
} catch (\RetailCrm\Exception\CurlException $e) { } catch (CurlException $e) {
static::logException( static::logException(
$method, $method,
$methodApi, $methodApi,
@ -572,7 +581,7 @@ class RCrmActions
); );
return false; return false;
} catch (\RetailCrm\Exception\InvalidJsonException $e) { } catch (InvalidJsonException $e) {
static::logException( static::logException(
$method, $method,
$methodApi, $methodApi,

View File

@ -1,6 +1,8 @@
<?php <?php
use Intaro\RetailCrm\Service\ManagerService; use Intaro\RetailCrm\Service\ManagerService;
use Bitrix\Sale\Payment;
use RetailCrm\ApiClient;
/** /**
* Class RetailCrmEvent * Class RetailCrmEvent
@ -10,21 +12,12 @@ class RetailCrmEvent
protected static $MODULE_ID = 'intaro.retailcrm'; protected static $MODULE_ID = 'intaro.retailcrm';
protected static $CRM_API_HOST_OPTION = 'api_host'; protected static $CRM_API_HOST_OPTION = 'api_host';
protected static $CRM_API_KEY_OPTION = 'api_key'; protected static $CRM_API_KEY_OPTION = 'api_key';
protected static $CRM_ORDER_TYPES_ARR = 'order_types_arr';
protected static $CRM_DELIVERY_TYPES_ARR = 'deliv_types_arr';
protected static $CRM_PAYMENT_TYPES = 'pay_types_arr'; protected static $CRM_PAYMENT_TYPES = 'pay_types_arr';
protected static $CRM_PAYMENT_STATUSES = 'pay_statuses_arr'; protected static $CRM_PAYMENT_STATUSES = 'pay_statuses_arr';
protected static $CRM_PAYMENT = 'payment_arr'; //order payment Y/N protected static $CRM_PAYMENT = 'payment_arr'; //order payment Y/N
protected static $CRM_ORDER_LAST_ID = 'order_last_id';
protected static $CRM_ORDER_PROPS = 'order_props';
protected static $CRM_LEGAL_DETAILS = 'legal_details';
protected static $CRM_CUSTOM_FIELDS = 'custom_fields'; protected static $CRM_CUSTOM_FIELDS = 'custom_fields';
protected static $CRM_CONTRAGENT_TYPE = 'contragent_type'; protected static $CRM_CONTRAGENT_TYPE = 'contragent_type';
protected static $CRM_ORDER_FAILED_IDS = 'order_failed_ids';
protected static $CRM_SITES_LIST = 'sites_list'; protected static $CRM_SITES_LIST = 'sites_list';
protected static $CRM_CC = 'cc';
protected static $CRM_CORP_NAME = 'nickName-corporate';
protected static $CRM_CORP_ADRES = 'adres-corporate';
/** /**
* @param $arFields * @param $arFields
@ -32,7 +25,7 @@ class RetailCrmEvent
* @return bool * @return bool
* @throws InvalidArgumentException * @throws InvalidArgumentException
*/ */
function OnAfterUserUpdate($arFields) public function OnAfterUserUpdate($arFields)
{ {
if (isset($GLOBALS['RETAIL_CRM_HISTORY']) && $GLOBALS['RETAIL_CRM_HISTORY']) { if (isset($GLOBALS['RETAIL_CRM_HISTORY']) && $GLOBALS['RETAIL_CRM_HISTORY']) {
return false; return false;
@ -59,7 +52,7 @@ class RetailCrmEvent
* @param mixed $ID - Order id * @param mixed $ID - Order id
* @param mixed $arFields - Order arFields * @param mixed $arFields - Order arFields
*/ */
function onUpdateOrder($ID, $arFields) public function onUpdateOrder($ID, $arFields)
{ {
if (isset($GLOBALS['RETAIL_CRM_HISTORY']) && $GLOBALS['RETAIL_CRM_HISTORY']) { if (isset($GLOBALS['RETAIL_CRM_HISTORY']) && $GLOBALS['RETAIL_CRM_HISTORY']) {
$GLOBALS['RETAILCRM_ORDER_OLD_EVENT'] = false; $GLOBALS['RETAILCRM_ORDER_OLD_EVENT'] = false;
@ -68,7 +61,7 @@ class RetailCrmEvent
$GLOBALS['RETAILCRM_ORDER_OLD_EVENT'] = true; $GLOBALS['RETAILCRM_ORDER_OLD_EVENT'] = true;
if (($arFields['CANCELED'] == 'Y') if (($arFields['CANCELED'] === 'Y')
&& (sizeof($arFields['BASKET_ITEMS']) == 0) && (sizeof($arFields['BASKET_ITEMS']) == 0)
&& (sizeof($arFields['ORDER_PROP']) == 0) && (sizeof($arFields['ORDER_PROP']) == 0)
) { ) {
@ -83,7 +76,7 @@ class RetailCrmEvent
* *
* @param object $event - Order object * @param object $event - Order object
*/ */
function orderDelete($event) public function orderDelete($event)
{ {
$GLOBALS['RETAILCRM_ORDER_DELETE'] = true; $GLOBALS['RETAILCRM_ORDER_DELETE'] = true;
@ -98,7 +91,7 @@ class RetailCrmEvent
* @throws \Bitrix\Main\SystemException * @throws \Bitrix\Main\SystemException
* @throws \Bitrix\Main\ArgumentException * @throws \Bitrix\Main\ArgumentException
*/ */
function orderSave($event) public function orderSave($event)
{ {
if (true == $GLOBALS['ORDER_DELETE_USER_ADMIN']) { if (true == $GLOBALS['ORDER_DELETE_USER_ADMIN']) {
return false; return false;
@ -120,13 +113,13 @@ class RetailCrmEvent
return false; return false;
} }
if (!CModule::IncludeModule("sale")) { if (!CModule::IncludeModule('sale')) {
RCrmActions::eventLog('RetailCrmEvent::orderSave', 'sale', 'module not found'); RCrmActions::eventLog('RetailCrmEvent::orderSave', 'sale', 'module not found');
return false; return false;
} }
if (!CModule::IncludeModule("catalog")) { if (!CModule::IncludeModule('catalog')) {
RCrmActions::eventLog('RetailCrmEvent::orderSave', 'catalog', 'module not found'); RCrmActions::eventLog('RetailCrmEvent::orderSave', 'catalog', 'module not found');
return false; return false;
@ -136,12 +129,13 @@ class RetailCrmEvent
if (method_exists($event, 'getId')) { if (method_exists($event, 'getId')) {
$obOrder = $event; $obOrder = $event;
} elseif (method_exists($event, 'getParameter')) { } elseif (method_exists($event, 'getParameter')) {
$obOrder = $event->getParameter("ENTITY"); $obOrder = $event->getParameter('ENTITY');
} else { } else {
RCrmActions::eventLog('RetailCrmEvent::orderSave', 'events', 'event error'); RCrmActions::eventLog('RetailCrmEvent::orderSave', 'events', 'event error');
return false; return false;
} }
$arOrder = RetailCrmOrder::orderObjToArr($obOrder); $arOrder = RetailCrmOrder::orderObjToArr($obOrder);
$api = new RetailCrm\ApiClient(RetailcrmConfigProvider::getApiUrl(), RetailcrmConfigProvider::getApiKey()); $api = new RetailCrm\ApiClient(RetailcrmConfigProvider::getApiUrl(), RetailcrmConfigProvider::getApiKey());
@ -161,7 +155,7 @@ class RetailCrmEvent
//corp cliente swich //corp cliente swich
$optionCorpClient = RetailcrmConfigProvider::getCorporateClientStatus(); $optionCorpClient = RetailcrmConfigProvider::getCorporateClientStatus();
$arParams = RCrmActions::clearArr(array( $arParams = RCrmActions::clearArr([
'optionsOrderTypes' => $optionsOrderTypes, 'optionsOrderTypes' => $optionsOrderTypes,
'optionsDelivTypes' => $optionsDelivTypes, 'optionsDelivTypes' => $optionsDelivTypes,
'optionsPayTypes' => $optionsPayTypes, 'optionsPayTypes' => $optionsPayTypes,
@ -171,8 +165,8 @@ class RetailCrmEvent
'optionsLegalDetails' => $optionsLegalDetails, 'optionsLegalDetails' => $optionsLegalDetails,
'optionsContragentType' => $optionsContragentType, 'optionsContragentType' => $optionsContragentType,
'optionsSitesList' => $optionsSitesList, 'optionsSitesList' => $optionsSitesList,
'optionsCustomFields' => $optionsCustomFields 'optionsCustomFields' => $optionsCustomFields,
)); ]);
//many sites? //many sites?
if ($optionsSitesList) { if ($optionsSitesList) {
@ -195,7 +189,6 @@ class RetailCrmEvent
} }
$orderCompany = null; $orderCompany = null;
if ('Y' === $optionCorpClient) { if ('Y' === $optionCorpClient) {
if (true === RetailCrmCorporateClient::isCorpTookExternalId((string) $arOrder['USER_ID'], $api)) { if (true === RetailCrmCorporateClient::isCorpTookExternalId((string) $arOrder['USER_ID'], $api)) {
RetailCrmCorporateClient::setPrefixForExternalId((string) $arOrder['USER_ID'], $api); RetailCrmCorporateClient::setPrefixForExternalId((string) $arOrder['USER_ID'], $api);
@ -204,22 +197,22 @@ class RetailCrmEvent
//TODO эта управляющая конструкция по функционалу дублирует RetailCrmOrder::createCustomerForOrder. //TODO эта управляющая конструкция по функционалу дублирует RetailCrmOrder::createCustomerForOrder.
// Необходимо устранить дублирование, вынеся логику в обособленный класс-сервис // Необходимо устранить дублирование, вынеся логику в обособленный класс-сервис
if ("Y" === $optionCorpClient && $optionsContragentType[$arOrder['PERSON_TYPE_ID']] == 'legal-entity') { if ('Y' === $optionCorpClient && $optionsContragentType[$arOrder['PERSON_TYPE_ID']] === 'legal-entity') {
//corparate cliente //corparate cliente
$nickName = ''; $nickName = '';
$address = ''; $address = '';
$corpAddress = ''; $corpAddress = '';
$contragent = array(); $contragent = [];
$userCorp = array(); $userCorp = [];
$corpName = RetailcrmConfigProvider::getCorporateClientName(); $corpName = RetailcrmConfigProvider::getCorporateClientName();
$corpAddress = RetailcrmConfigProvider::getCorporateClientAddress(); $corpAddress = RetailcrmConfigProvider::getCorporateClientAddress();
foreach ($arOrder['PROPS']['properties'] as $prop) { foreach ($arOrder['PROPS']['properties'] as $prop) {
if ($prop['CODE'] == $corpName) { if ($prop['CODE'] === $corpName) {
$nickName = $prop['VALUE'][0]; $nickName = $prop['VALUE'][0];
} }
if ($prop['CODE'] == $corpAddress) { if ($prop['CODE'] === $corpAddress) {
$address = $prop['VALUE'][0]; $address = $prop['VALUE'][0];
} }
@ -235,7 +228,7 @@ class RetailCrmEvent
} }
$customersCorporate = false; $customersCorporate = false;
$response = $api->customersCorporateList(array('companyName' => $nickName)); $response = $api->customersCorporateList(['companyName' => $nickName]);
if ($response && $response->getStatusCode() == 200) { if ($response && $response->getStatusCode() == 200) {
$customersCorporate = $response['customersCorporate']; $customersCorporate = $response['customersCorporate'];
@ -245,7 +238,7 @@ class RetailCrmEvent
$userCorp['customerCorporate'] = $singleCorp; $userCorp['customerCorporate'] = $singleCorp;
$companiesResponse = $api->customersCorporateCompanies( $companiesResponse = $api->customersCorporateCompanies(
$singleCorp['id'], $singleCorp['id'],
array(), [],
null, null,
null, null,
'id', 'id',
@ -256,7 +249,7 @@ class RetailCrmEvent
$orderCompany = array_reduce( $orderCompany = array_reduce(
$companiesResponse['companies'], $companiesResponse['companies'],
function ($carry, $item) use ($nickName) { function ($carry, $item) use ($nickName) {
if (is_array($item) && $item['name'] == $nickName) { if (is_array($item) && $item['name'] === $nickName) {
$carry = $item; $carry = $item;
} }
@ -286,7 +279,7 @@ class RetailCrmEvent
$arUser['PERSONAL_STREET'] = $address; $arUser['PERSONAL_STREET'] = $address;
} }
$resultUser = RetailCrmUser::customerSend($arUser, $api, "individual", true, $site); $resultUser = RetailCrmUser::customerSend($arUser, $api, 'individual', true, $site);
if (!$resultUser) { if (!$resultUser) {
RCrmActions::eventLog( RCrmActions::eventLog(
@ -298,7 +291,7 @@ class RetailCrmEvent
return false; return false;
} }
$userCrm = array('customer' => array('externalId' => $arOrder['USER_ID'])); $userCrm = ['customer' => ['externalId' => $arOrder['USER_ID']]];
} }
if (!isset($userCorp['customerCorporate'])) { if (!isset($userCorp['customerCorporate'])) {
@ -320,56 +313,56 @@ class RetailCrmEvent
} }
$arParams['customerCorporate'] = $resultUserCorp; $arParams['customerCorporate'] = $resultUserCorp;
$arParams['orderCompany'] = isset($resultUserCorp['mainCompany']) ? $resultUserCorp['mainCompany'] : null; $arParams['orderCompany'] = $resultUserCorp['mainCompany'] ?? null;
$customerCorporateAddress = array(); $customerCorporateAddress = [];
$customerCorporateCompany = array(); $customerCorporateCompany = [];
$addressResult = null; $addressResult = null;
$companyResult = null; $companyResult = null;
if (!empty($address)) { if (!empty($address)) {
//TODO address builder add //TODO address builder add
$customerCorporateAddress = array( $customerCorporateAddress = [
'name' => $nickName, 'name' => $nickName,
'isMain' => true, 'isMain' => true,
'text' => $address 'text' => $address,
); ];
$addressResult = $api->customersCorporateAddressesCreate($resultUserCorp['id'], $customerCorporateAddress, 'id', $site); $addressResult = $api->customersCorporateAddressesCreate($resultUserCorp['id'], $customerCorporateAddress, 'id', $site);
} }
$customerCorporateCompany = array( $customerCorporateCompany = [
'name' => $nickName, 'name' => $nickName,
'isMain' => true, 'isMain' => true,
'contragent' => $contragent 'contragent' => $contragent,
); ];
if (!empty($addressResult)) { if (!empty($addressResult)) {
$customerCorporateCompany['address'] = array( $customerCorporateCompany['address'] = [
'id' => $addressResult['id'] 'id' => $addressResult['id'],
); ];
} }
$companyResult = $api->customersCorporateCompaniesCreate($resultUserCorp['id'], $customerCorporateCompany, 'id', $site); $companyResult = $api->customersCorporateCompaniesCreate($resultUserCorp['id'], $customerCorporateCompany, 'id', $site);
$customerCorporateContact = array( $customerCorporateContact = [
'isMain' => true, 'isMain' => true,
'customer' => array( 'customer' => [
'externalId' => $arOrder['USER_ID'], 'externalId' => $arOrder['USER_ID'],
'site' => $site 'site' => $site,
) ],
); ];
if (!empty($companyResult)) { if (!empty($companyResult)) {
$orderCompany = array( $orderCompany = [
'id' => $companyResult['id'] 'id' => $companyResult['id'],
); ];
$customerCorporateContact['companies'] = array( $customerCorporateContact['companies'] = [
array( [
'company' => $orderCompany 'company' => $orderCompany,
) ],
); ];
} }
$api->customersCorporateContactsCreate( $api->customersCorporateContactsCreate(
@ -381,7 +374,7 @@ class RetailCrmEvent
$arParams['orderCompany'] = array_merge( $arParams['orderCompany'] = array_merge(
$customerCorporateCompany, $customerCorporateCompany,
array('id' => $companyResult['id']) ['id' => $companyResult['id']]
); );
} else { } else {
RetailCrmCorporateClient::addCustomersCorporateAddresses( RetailCrmCorporateClient::addCustomersCorporateAddresses(
@ -413,12 +406,10 @@ class RetailCrmEvent
} }
} }
} }
if (isset($arOrder['RESPONSIBLE_ID']) && !empty($arOrder['RESPONSIBLE_ID'])) { if (isset($arOrder['RESPONSIBLE_ID']) && !empty($arOrder['RESPONSIBLE_ID'])) {
$managerService = ManagerService::getInstance(); $managerService = ManagerService::getInstance();
$arParams['managerId'] = $managerService->getManagerCrmId($arOrder['RESPONSIBLE_ID']); $arParams['managerId'] = $managerService->getManagerCrmId($arOrder['RESPONSIBLE_ID']);
} }
//order //order
$resultOrder = RetailCrmOrder::orderSend($arOrder, $api, $arParams, true, $site, $methodApi); $resultOrder = RetailCrmOrder::orderSend($arOrder, $api, $arParams, true, $site, $methodApi);
@ -438,7 +429,7 @@ class RetailCrmEvent
* @throws InvalidArgumentException * @throws InvalidArgumentException
* *
*/ */
function paymentSave($event) public function paymentSave(Payment $event)
{ {
$apiVersion = COption::GetOptionString(self::$MODULE_ID, 'api_version', 0); $apiVersion = COption::GetOptionString(self::$MODULE_ID, 'api_version', 0);
@ -446,7 +437,7 @@ class RetailCrmEvent
$order = $event->getCollection()->getOrder(); $order = $event->getCollection()->getOrder();
if ((isset($GLOBALS['RETAIL_CRM_HISTORY']) && $GLOBALS['RETAIL_CRM_HISTORY']) if ((isset($GLOBALS['RETAIL_CRM_HISTORY']) && $GLOBALS['RETAIL_CRM_HISTORY'])
|| $apiVersion != 'v5' || $apiVersion !== 'v5'
|| $order->isNew() || $order->isNew()
) { ) {
return false; return false;
@ -457,7 +448,7 @@ class RetailCrmEvent
$optionsPayStatuses = RetailcrmConfigProvider::getPayment(); $optionsPayStatuses = RetailcrmConfigProvider::getPayment();
$integrationPaymentTypes = RetailcrmConfigProvider::getIntegrationPaymentTypes(); $integrationPaymentTypes = RetailcrmConfigProvider::getIntegrationPaymentTypes();
$arPayment = array( $arPayment = [
'ID' => $event->getId(), 'ID' => $event->getId(),
'ORDER_ID' => $event->getField('ORDER_ID'), 'ORDER_ID' => $event->getField('ORDER_ID'),
'PAID' => $event->getField('PAID'), 'PAID' => $event->getField('PAID'),
@ -465,7 +456,7 @@ class RetailCrmEvent
'SUM' => $event->getField('SUM'), 'SUM' => $event->getField('SUM'),
'LID' => $order->getSiteId(), 'LID' => $order->getSiteId(),
'DATE_PAID' => $event->getField('DATE_PAID'), 'DATE_PAID' => $event->getField('DATE_PAID'),
); ];
if ($optionsSitesList) { if ($optionsSitesList) {
if (array_key_exists($arPayment['LID'], $optionsSitesList) && $optionsSitesList[$arPayment['LID']] !== null) { if (array_key_exists($arPayment['LID'], $optionsSitesList) && $optionsSitesList[$arPayment['LID']] !== null) {
@ -498,9 +489,9 @@ class RetailCrmEvent
} }
if (!empty($arPayment['PAY_SYSTEM_ID']) && isset($optionsPaymentTypes[$arPayment['PAY_SYSTEM_ID']])) { if (!empty($arPayment['PAY_SYSTEM_ID']) && isset($optionsPaymentTypes[$arPayment['PAY_SYSTEM_ID']])) {
$paymentToCrm = array( $paymentToCrm = [
'type' => $optionsPaymentTypes[$arPayment['PAY_SYSTEM_ID']] 'type' => $optionsPaymentTypes[$arPayment['PAY_SYSTEM_ID']],
); ];
if (!empty($arPayment['ID'])) { if (!empty($arPayment['ID'])) {
$paymentToCrm['externalId'] = RCrmActions::generatePaymentExternalId($arPayment['ID']); $paymentToCrm['externalId'] = RCrmActions::generatePaymentExternalId($arPayment['ID']);
@ -508,7 +499,7 @@ class RetailCrmEvent
if (!empty($arPayment['DATE_PAID'])) { if (!empty($arPayment['DATE_PAID'])) {
if (is_object($arPayment['DATE_PAID'])) { if (is_object($arPayment['DATE_PAID'])) {
$culture = new Bitrix\Main\Context\Culture(array("FORMAT_DATETIME" => "YYYY-MM-DD HH:MI:SS")); $culture = new Bitrix\Main\Context\Culture(['FORMAT_DATETIME' => 'YYYY-MM-DD HH:MI:SS']);
$paymentToCrm['paidAt'] = $arPayment['DATE_PAID']->toString($culture); $paymentToCrm['paidAt'] = $arPayment['DATE_PAID']->toString($culture);
} elseif (is_string($arPayment['DATE_PAID'])) { } elseif (is_string($arPayment['DATE_PAID'])) {
$paymentToCrm['paidAt'] = $arPayment['DATE_PAID']; $paymentToCrm['paidAt'] = $arPayment['DATE_PAID'];
@ -538,7 +529,7 @@ class RetailCrmEvent
} elseif (array_key_exists($arPayment['ID'], $paymentsExternalIds)) { } elseif (array_key_exists($arPayment['ID'], $paymentsExternalIds)) {
$paymentData = $paymentsExternalIds[$arPayment['ID']]; $paymentData = $paymentsExternalIds[$arPayment['ID']];
} else { } else {
$paymentData = array(); $paymentData = [];
} }
if (empty($paymentData)) { if (empty($paymentData)) {
@ -573,7 +564,7 @@ class RetailCrmEvent
* *
* @throws InvalidArgumentException * @throws InvalidArgumentException
*/ */
function paymentDelete($event) public function paymentDelete(Payment $event): void
{ {
$apiVersion = COption::GetOptionString(self::$MODULE_ID, 'api_version', 0); $apiVersion = COption::GetOptionString(self::$MODULE_ID, 'api_version', 0);
@ -584,13 +575,13 @@ class RetailCrmEvent
return; return;
} }
$optionsSitesList = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_SITES_LIST, 0)); $optionsSitesList = RetailcrmConfigProvider::getSitesList();
$arPayment = array( $arPayment = [
'ID' => $event->getId(), 'ID' => $event->getId(),
'ORDER_ID' => $event->getField('ORDER_ID'), 'ORDER_ID' => $event->getField('ORDER_ID'),
'LID' => $event->getCollection()->getOrder()->getSiteId() 'LID' => $event->getCollection()->getOrder()->getSiteId(),
); ];
if ($optionsSitesList) { if ($optionsSitesList) {
if (array_key_exists($arPayment['LID'], $optionsSitesList) && $optionsSitesList[$arPayment['LID']] !== null) { if (array_key_exists($arPayment['LID'], $optionsSitesList) && $optionsSitesList[$arPayment['LID']] !== null) {
@ -604,7 +595,7 @@ class RetailCrmEvent
$api_host = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_HOST_OPTION, 0); $api_host = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_HOST_OPTION, 0);
$api_key = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_KEY_OPTION, 0); $api_key = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_KEY_OPTION, 0);
$api = new RetailCrm\ApiClient($api_host, $api_key); $api = new ApiClient($api_host, $api_key);
$orderCrm = RCrmActions::apiMethod($api, 'ordersGet', __METHOD__, $arPayment['ORDER_ID'], $site); $orderCrm = RCrmActions::apiMethod($api, 'ordersGet', __METHOD__, $arPayment['ORDER_ID'], $site);
if (isset($orderCrm['order']['payments']) && $orderCrm['order']['payments']) { if (isset($orderCrm['order']['payments']) && $orderCrm['order']['payments']) {

View File

@ -236,7 +236,6 @@ class RetailCrmHistory
$optionsPayStatuses = array_flip(RetailcrmConfigProvider::getPaymentStatuses()); // --statuses $optionsPayStatuses = array_flip(RetailcrmConfigProvider::getPaymentStatuses()); // --statuses
$optionsOrderProps = RetailcrmConfigProvider::getOrderProps(); $optionsOrderProps = RetailcrmConfigProvider::getOrderProps();
$optionsLegalDetails = RetailcrmConfigProvider::getLegalDetails(); $optionsLegalDetails = RetailcrmConfigProvider::getLegalDetails();
$optionsSitesList = RetailcrmConfigProvider::getSitesList();
$optionsOrderNumbers = RetailcrmConfigProvider::getOrderNumbers(); $optionsOrderNumbers = RetailcrmConfigProvider::getOrderNumbers();
$optionsCanselOrder = RetailcrmConfigProvider::getCancellableOrderPaymentStatuses(); $optionsCanselOrder = RetailcrmConfigProvider::getCancellableOrderPaymentStatuses();
$currency = RetailcrmConfigProvider::getCurrencyOrDefault(); $currency = RetailcrmConfigProvider::getCurrencyOrDefault();
@ -298,11 +297,7 @@ class RetailCrmHistory
continue; continue;
} }
if ($optionsSitesList) { $site = self::getSite($order['site']);
$site = array_search($order['site'], $optionsSitesList);
} else {
$site = CSite::GetDefSite();
}
if (empty($site)) { if (empty($site)) {
RCrmActions::eventLog( RCrmActions::eventLog(
@ -538,19 +533,9 @@ class RetailCrmHistory
continue; continue;
} }
if (array_key_exists('managerId', $order)) { $site = self::getSite($order['site']);
$service = ManagerService::getInstance();
$newOrder->setField('RESPONSIBLE_ID', $service->getManagerBitrixId($order['managerId'])); if (null === $site) {
}
if ($optionsSitesList) {
$site = array_search($order['site'], $optionsSitesList);
} else {
$site = CSite::GetDefSite();
}
if (empty($site)) {
RCrmActions::eventLog( RCrmActions::eventLog(
'RetailCrmHistory::orderHistory', 'RetailCrmHistory::orderHistory',
'Bitrix\Sale\Order::edit', 'Bitrix\Sale\Order::edit',
@ -1245,6 +1230,26 @@ class RetailCrmHistory
return false; return false;
} }
/**
* @param string $shopCode
*
* @return string|null
*/
public static function getSite(string $shopCode): ?string
{
$optionsSitesList = RetailcrmConfigProvider::getSitesList();
if ($optionsSitesList) {
$searchResult = array_search($shopCode, $optionsSitesList, true);
return is_string($searchResult) ? $searchResult : null;
}
$defaultSite = CSite::GetDefSite();
return is_string($defaultSite) ? $defaultSite : null;
}
/** /**
* @param $array * @param $array
* @param $value * @param $value

View File

@ -5,9 +5,9 @@ use Bitrix\Main\Context\Culture;
use Bitrix\Main\UserTable; use Bitrix\Main\UserTable;
use Bitrix\Sale\Delivery\Services\Manager; use Bitrix\Sale\Delivery\Services\Manager;
use Bitrix\Sale\Internals\Fields; use Bitrix\Sale\Internals\Fields;
use Bitrix\Sale\Internals\OrderTable;
use Bitrix\Sale\Location\LocationTable; use Bitrix\Sale\Location\LocationTable;
use Bitrix\Sale\Order; use Bitrix\Sale\Order;
use Bitrix\Sale\OrderTable;
use RetailCrm\ApiClient; use RetailCrm\ApiClient;
use Intaro\RetailCrm\Service\ManagerService; use Intaro\RetailCrm\Service\ManagerService;
use RetailCrm\Response\ApiResponse; use RetailCrm\Response\ApiResponse;
@ -20,7 +20,6 @@ IncludeModuleLangFile(__FILE__);
class RetailCrmOrder class RetailCrmOrder
{ {
/** /**
*
* Creates order or returns order for mass upload * Creates order or returns order for mass upload
* *
* @param array $arOrder * @param array $arOrder
@ -93,7 +92,7 @@ class RetailCrmOrder
$order['contragent']['contragentType'] = $arParams['optionsContragentType'][$arOrder['PERSON_TYPE_ID']]; $order['contragent']['contragentType'] = $arParams['optionsContragentType'][$arOrder['PERSON_TYPE_ID']];
if ($methodApi == 'ordersEdit') { if ($methodApi === 'ordersEdit') {
$order['discountManualAmount'] = 0; $order['discountManualAmount'] = 0;
$order['discountManualPercent'] = 0; $order['discountManualPercent'] = 0;
} }
@ -109,10 +108,10 @@ class RetailCrmOrder
) { ) {
$order['customFields'][$search] = $prop['VALUE'][0];//custom properties $order['customFields'][$search] = $prop['VALUE'][0];//custom properties
} elseif ($search = array_search($prop['CODE'], $arParams['optionsOrderProps'][$arOrder['PERSON_TYPE_ID']])) {//other } elseif ($search = array_search($prop['CODE'], $arParams['optionsOrderProps'][$arOrder['PERSON_TYPE_ID']])) {//other
if (in_array($search, array('fio', 'phone', 'email'))) {//fio, phone, email if (in_array($search, ['fio', 'phone', 'email'])) {//fio, phone, email
if ($search == 'fio') { if ($search === 'fio') {
$order = array_merge($order, RCrmActions::explodeFio($prop['VALUE'][0]));//add fio fields $order = array_merge($order, RCrmActions::explodeFio($prop['VALUE'][0]));//add fio fields
} elseif ($search == 'email' && mb_strlen($prop['VALUE'][0]) > 100) { } elseif ($search === 'email' && mb_strlen($prop['VALUE'][0]) > 100) {
continue; continue;
} else { } else {
// ignoring a property with a non-set group if the field value is already set // ignoring a property with a non-set group if the field value is already set
@ -123,7 +122,7 @@ class RetailCrmOrder
$order[$search] = $prop['VALUE'][0];//phone, email $order[$search] = $prop['VALUE'][0];//phone, email
} }
} else {//address } else {//address
if ($prop['TYPE'] == 'LOCATION' && isset($prop['VALUE'][0]) && $prop['VALUE'][0] != '') { if ($prop['TYPE'] === 'LOCATION' && isset($prop['VALUE'][0]) && $prop['VALUE'][0] != '') {
$arLoc = LocationTable::getByCode($prop['VALUE'][0])->fetch(); $arLoc = LocationTable::getByCode($prop['VALUE'][0])->fetch();
if ($arLoc) { if ($arLoc) {
$server = Context::getCurrent()->getServer()->getDocumentRoot(); $server = Context::getCurrent()->getServer()->getDocumentRoot();
@ -136,14 +135,14 @@ class RetailCrmOrder
} }
} }
$location = \Bitrix\Sale\Location\Name\LocationTable::getList([ $location = LocationTable::getList([
'filter' => ['=LOCATION_ID' => $arLoc['CITY_ID'], 'LANGUAGE_ID' => 'ru'], 'filter' => ['=LOCATION_ID' => $arLoc['CITY_ID'], 'LANGUAGE_ID' => 'ru']
])->fetch(); ])->fetch();
if (count($countrys) > 0) { if (count($countrys) > 0) {
$countryOrder = \Bitrix\Sale\Location\Name\LocationTable::getList(array( $countryOrder = LocationTable::getList([
'filter' => array('=LOCATION_ID' => $arLoc['COUNTRY_ID'], 'LANGUAGE_ID' => 'ru') 'filter' => ['=LOCATION_ID' => $arLoc['COUNTRY_ID'], 'LANGUAGE_ID' => 'ru']
))->fetch(); ])->fetch();
if(isset($countrys[$countryOrder['NAME']])){ if(isset($countrys[$countryOrder['NAME']])){
$order['countryIso'] = $countrys[$countryOrder['NAME']]; $order['countryIso'] = $countrys[$countryOrder['NAME']];
} }
@ -162,6 +161,7 @@ class RetailCrmOrder
//deliverys //deliverys
if (array_key_exists($arOrder['DELIVERYS'][0]['id'], $arParams['optionsDelivTypes'])) { if (array_key_exists($arOrder['DELIVERYS'][0]['id'], $arParams['optionsDelivTypes'])) {
$order['delivery']['code'] = $arParams['optionsDelivTypes'][$arOrder['DELIVERYS'][0]['id']]; $order['delivery']['code'] = $arParams['optionsDelivTypes'][$arOrder['DELIVERYS'][0]['id']];
if (isset($arOrder['DELIVERYS'][0]['service']) && $arOrder['DELIVERYS'][0]['service'] != '') { if (isset($arOrder['DELIVERYS'][0]['service']) && $arOrder['DELIVERYS'][0]['service'] != '') {
$order['delivery']['service']['code'] = $arOrder['DELIVERYS'][0]['service']; $order['delivery']['service']['code'] = $arOrder['DELIVERYS'][0]['service'];
} }
@ -172,7 +172,7 @@ class RetailCrmOrder
$height = 0; $height = 0;
$length = 0; $length = 0;
if ('ordersEdit' == $methodApi) { if ('ordersEdit' === $methodApi) {
$response = RCrmActions::apiMethod($api, 'ordersGet', __METHOD__, $order['externalId']); $response = RCrmActions::apiMethod($api, 'ordersGet', __METHOD__, $order['externalId']);
if (isset($response['order'])) { if (isset($response['order'])) {
foreach ($response['order']['items'] as $k => $item) { foreach ($response['order']['items'] as $k => $item) {
@ -185,31 +185,32 @@ class RetailCrmOrder
//basket //basket
foreach ($arOrder['BASKET'] as $position => $product) { foreach ($arOrder['BASKET'] as $position => $product) {
$itemId = null; $itemId = null;
$externalId = $position . "_" . $product['PRODUCT_ID']; $externalId = $position . '_' . $product['PRODUCT_ID'];
if (isset($orderItems[$externalId])) { //update if (isset($orderItems[$externalId])) { //update
$externalIds = $orderItems[$externalId]['externalIds']; $externalIds = $orderItems[$externalId]['externalIds'];
$itemId = $orderItems[$externalId]['id']; $itemId = $orderItems[$externalId]['id'];
$key = array_search("bitrix", array_column($externalIds, 'code')); $key = array_search('bitrix', array_column($externalIds, 'code'));
if ($externalIds[$key]['code'] == "bitrix") {
$externalIds[$key] = array( if ($externalIds[$key]['code'] === 'bitrix') {
$externalIds[$key] = [
'code' => 'bitrix', 'code' => 'bitrix',
'value' => $externalId, 'value' => $externalId,
); ];
} else { } else {
$externalIds[] = array( $externalIds[] = [
'code' => 'bitrix', 'code' => 'bitrix',
'value' => $externalId, 'value' => $externalId,
); ];
} }
} else { //create } else { //create
$externalIds = array( $externalIds = [
array( [
'code' => 'bitrix', 'code' => 'bitrix',
'value' => $externalId, 'value' => $externalId,
) ]
); ];
} }
$item = [ $item = [
@ -226,16 +227,17 @@ class RetailCrmOrder
$item['id'] = $itemId; $item['id'] = $itemId;
} }
$pp = CCatalogProduct::GetByID($product['PRODUCT_ID']); $catalogProduct = CCatalogProduct::GetByID($product['PRODUCT_ID']);
if (is_null($pp['PURCHASING_PRICE']) == false) {
if ($pp['PURCHASING_CURRENCY'] && $currency != $pp['PURCHASING_CURRENCY']) { if (is_null($catalogProduct['PURCHASING_PRICE']) === false) {
if ($catalogProduct['PURCHASING_CURRENCY'] && $currency != $catalogProduct['PURCHASING_CURRENCY']) {
$purchasePrice = CCurrencyRates::ConvertCurrency( $purchasePrice = CCurrencyRates::ConvertCurrency(
(double) $pp['PURCHASING_PRICE'], (double) $catalogProduct['PURCHASING_PRICE'],
$pp['PURCHASING_CURRENCY'], $catalogProduct['PURCHASING_CURRENCY'],
$currency $currency
); );
} else { } else {
$purchasePrice = $pp['PURCHASING_PRICE']; $purchasePrice = $catalogProduct['PURCHASING_PRICE'];
} }
$item['purchasePrice'] = $purchasePrice; $item['purchasePrice'] = $purchasePrice;
@ -253,7 +255,7 @@ class RetailCrmOrder
$order['items'][] = $item; $order['items'][] = $item;
if ($send && $dimensionsSetting == 'Y') { if ($send && $dimensionsSetting === 'Y') {
$dimensions = RCrmActions::unserializeArrayRecursive($product['DIMENSIONS']); $dimensions = RCrmActions::unserializeArrayRecursive($product['DIMENSIONS']);
if ($dimensions !== false) { if ($dimensions !== false) {
@ -265,7 +267,7 @@ class RetailCrmOrder
} }
} }
if ($send && $dimensionsSetting == 'Y') { if ($send && $dimensionsSetting === 'Y') {
$order['width'] = $width; $order['width'] = $width;
$order['height'] = $height; $order['height'] = $height;
$order['length'] = $length; $order['length'] = $length;
@ -278,9 +280,9 @@ class RetailCrmOrder
foreach ($arOrder['PAYMENTS'] as $payment) { foreach ($arOrder['PAYMENTS'] as $payment) {
if (!empty($payment['PAY_SYSTEM_ID']) && isset($arParams['optionsPayTypes'][$payment['PAY_SYSTEM_ID']])) { if (!empty($payment['PAY_SYSTEM_ID']) && isset($arParams['optionsPayTypes'][$payment['PAY_SYSTEM_ID']])) {
$pm = array( $pm = [
'type' => $arParams['optionsPayTypes'][$payment['PAY_SYSTEM_ID']] 'type' => $arParams['optionsPayTypes'][$payment['PAY_SYSTEM_ID']]
); ];
if (!empty($payment['ID'])) { if (!empty($payment['ID'])) {
$pm['externalId'] = RCrmActions::generatePaymentExternalId($payment['ID']); $pm['externalId'] = RCrmActions::generatePaymentExternalId($payment['ID']);
@ -290,11 +292,12 @@ class RetailCrmOrder
$pm['paidAt'] = new \DateTime($payment['DATE_PAID']); $pm['paidAt'] = new \DateTime($payment['DATE_PAID']);
} }
if (!empty($arParams['optionsPayment'][$payment['PAID']])) { if (
if (array_search($arParams['optionsPayTypes'][$payment['PAY_SYSTEM_ID']], $integrationPayment) === false) { !empty($arParams['optionsPayment'][$payment['PAID']])
&& !in_array($arParams['optionsPayTypes'][$payment['PAY_SYSTEM_ID']], $integrationPayment)
) {
$pm['status'] = $arParams['optionsPayment'][$payment['PAID']]; $pm['status'] = $arParams['optionsPayment'][$payment['PAID']];
} }
}
if (RetailcrmConfigProvider::shouldSendPaymentAmount()) { if (RetailcrmConfigProvider::shouldSendPaymentAmount()) {
$pm['amount'] = $payment['SUM']; $pm['amount'] = $payment['SUM'];
@ -339,11 +342,9 @@ class RetailCrmOrder
Logger::getInstance()->write($order, 'orderSend'); Logger::getInstance()->write($order, 'orderSend');
if ($send) { if ($send && !RCrmActions::apiMethod($api, $methodApi, __METHOD__, $order, $site)) {
if (!RCrmActions::apiMethod($api, $methodApi, __METHOD__, $order, $site)) {
return false; return false;
} }
}
return $order; return $order;
} }
@ -397,7 +398,6 @@ class RetailCrmOrder
return false; return false;
} }
$optionsSitesList = RetailcrmConfigProvider::getSitesList();
$optionsOrderTypes = RetailcrmConfigProvider::getOrderTypes(); $optionsOrderTypes = RetailcrmConfigProvider::getOrderTypes();
$optionsDelivTypes = RetailcrmConfigProvider::getDeliveryTypes(); $optionsDelivTypes = RetailcrmConfigProvider::getDeliveryTypes();
$optionsPayTypes = RetailcrmConfigProvider::getPaymentTypes(); $optionsPayTypes = RetailcrmConfigProvider::getPaymentTypes();
@ -408,9 +408,9 @@ class RetailCrmOrder
$optionsContragentType = RetailcrmConfigProvider::getContragentTypes(); $optionsContragentType = RetailcrmConfigProvider::getContragentTypes();
$optionsCustomFields = RetailcrmConfigProvider::getCustomFields(); $optionsCustomFields = RetailcrmConfigProvider::getCustomFields();
$api = new RetailCrm\ApiClient(RetailcrmConfigProvider::getApiUrl(), RetailcrmConfigProvider::getApiKey()); $api = new ApiClient(RetailcrmConfigProvider::getApiUrl(), RetailcrmConfigProvider::getApiKey());
$arParams = array( $arParams = [
'optionsOrderTypes' => $optionsOrderTypes, 'optionsOrderTypes' => $optionsOrderTypes,
'optionsDelivTypes' => $optionsDelivTypes, 'optionsDelivTypes' => $optionsDelivTypes,
'optionsPayTypes' => $optionsPayTypes, 'optionsPayTypes' => $optionsPayTypes,
@ -419,27 +419,26 @@ class RetailCrmOrder
'optionsOrderProps' => $optionsOrderProps, 'optionsOrderProps' => $optionsOrderProps,
'optionsLegalDetails' => $optionsLegalDetails, 'optionsLegalDetails' => $optionsLegalDetails,
'optionsContragentType' => $optionsContragentType, 'optionsContragentType' => $optionsContragentType,
'optionsSitesList' => $optionsSitesList, 'optionsSitesList' => RetailcrmConfigProvider::getSitesList(),
'optionsCustomFields' => $optionsCustomFields, 'optionsCustomFields' => $optionsCustomFields,
); ];
$recOrders = array(); $recOrders = [];
foreach ($orderIds as $orderId) { foreach ($orderIds as $orderId) {
$site = null; $bitrixOrder = Order::load($orderId);
$orderObj = Order::load($orderId);
if (!$orderObj) { if (!$bitrixOrder) {
continue; continue;
} }
$arCustomer = []; $arCustomer = [];
$arCustomerCorporate = []; $arCustomerCorporate = [];
$order = self::orderObjToArr($orderObj); $order = self::orderObjToArr($bitrixOrder);
$user = UserTable::getById($order['USER_ID'])->fetch(); $user = UserTable::getById($order['USER_ID'])->fetch();
$site = RetailCrmOrder::getSite($order['LID'], $optionsSitesList); $site = self::getCrmShopCodeByLid($order['LID'], $arParams['optionsSitesList']);
if (true === $site) { if (null === $site && count($arParams['optionsSitesList']) > 0) {
continue; continue;
} }
@ -473,7 +472,7 @@ class RetailCrmOrder
} }
if (count($ordersPack) > 0) { if (count($ordersPack) > 0) {
if (false === RetailCrmOrder::uploadCustomersList($resCustomers, $api, $optionsSitesList)) { if (false === RetailCrmOrder::uploadCustomersList($resCustomers, $api, $arParams['optionsSitesList'])) {
return false; return false;
} }
@ -494,7 +493,7 @@ class RetailCrmOrder
} }
} }
if (false === RetailCrmOrder::uploadOrdersList($ordersPack, $api, $optionsSitesList)) { if (false === RetailCrmOrder::uploadOrdersList($ordersPack, $api, $arParams['optionsSitesList'])) {
return false; return false;
} }
@ -651,9 +650,9 @@ class RetailCrmOrder
* *
* @return array|false * @return array|false
*/ */
public static function uploadCustomersList($resCustomers, $api, $optionsSitesList) public static function uploadCustomersList(array $resCustomers, ApiClient $api, array $optionsSitesList)
{ {
return RetailCrmOrder::uploadItems( return self::uploadItems(
$resCustomers, $resCustomers,
'customersUpload', 'customersUpload',
'uploadedCustomers', 'uploadedCustomers',
@ -669,9 +668,9 @@ class RetailCrmOrder
* *
* @return array|false * @return array|false
*/ */
public static function uploadOrdersList($resOrders, $api, $optionsSitesList) public static function uploadOrdersList(array $resOrders, ApiClient $api, array $optionsSitesList)
{ {
return RetailCrmOrder::uploadItems( return self::uploadItems(
$resOrders, $resOrders,
'ordersUpload', 'ordersUpload',
'uploadedOrders', 'uploadedOrders',
@ -681,22 +680,14 @@ class RetailCrmOrder
} }
/** /**
* @param string $key * @param string $orderLid
* @param array $optionsSitesList * @param array $optionsSitesList
* *
* @return false|mixed|null * @return string|null
*/ */
public static function getSite(string $key, array $optionsSitesList) public static function getCrmShopCodeByLid(string $orderLid, array $optionsSitesList): ?string
{ {
if ($optionsSitesList) { return $optionsSitesList[$orderLid] ?? null;
if (array_key_exists($key, $optionsSitesList) && $optionsSitesList[$key] != null) {
return $optionsSitesList[$key];
} else {
return false;
}
}
return null;
} }
/** /**
@ -708,15 +699,20 @@ class RetailCrmOrder
* *
* @return array|false * @return array|false
*/ */
public static function uploadItems(array $pack, string $method, string $keyResponse, ApiClient $api, array $optionsSitesList) public static function uploadItems(
{ array $pack,
string $method,
string $keyResponse,
ApiClient $api,
array $optionsSitesList
) {
$uploaded = []; $uploaded = [];
$sizePack = 50; $sizePack = 50;
foreach ($pack as $key => $itemLoad) { foreach ($pack as $key => $itemLoad) {
$site = RetailCrmOrder::getSite($key, $optionsSitesList); $site = self::getCrmShopCodeByLid($key, $optionsSitesList);
if (true === $site) { if (null === $site && count($optionsSitesList) > 0) {
continue; continue;
} }
@ -738,13 +734,11 @@ class RetailCrmOrder
return false; return false;
} }
if ($response instanceof ApiResponse) { if (($response instanceof ApiResponse) && $response->offsetExists($keyResponse)) {
if ($response->offsetExists($keyResponse)) {
$uploaded = array_merge($uploaded, $response[$keyResponse]); $uploaded = array_merge($uploaded, $response[$keyResponse]);
} }
} }
} }
}
return $uploaded; return $uploaded;
} }
@ -758,9 +752,8 @@ class RetailCrmOrder
*/ */
public static function isOrderCorporate($order): bool public static function isOrderCorporate($order): bool
{ {
return (is_array($order) || $order instanceof ArrayAccess) return isset($order['customer'], $order['customer']['type'])
&& isset($order['customer']) && (is_array($order) || $order instanceof ArrayAccess)
&& isset($order['customer']['type'])
&& $order['customer']['type'] === 'customer_corporate'; && $order['customer']['type'] === 'customer_corporate';
} }

View File

@ -219,7 +219,7 @@ class intaro_retailcrm extends CModule
} }
if ($step == 11) { if ($step == 11) {
$arResult['arSites'] = RCrmActions::SitesList(); $arResult['arSites'] = RCrmActions::getSitesList();
if (count($arResult['arSites']) < 2) { if (count($arResult['arSites']) < 2) {
$step = 2; $step = 2;
} }
@ -329,7 +329,7 @@ class intaro_retailcrm extends CModule
return; return;
} }
$arResult['arSites'] = RCrmActions::SitesList(); $arResult['arSites'] = RCrmActions::getSitesList();
if (count($arResult['arSites']) > 1) { if (count($arResult['arSites']) > 1) {
@ -374,7 +374,8 @@ class intaro_retailcrm extends CModule
return; return;
} }
$ping = self::ping($api_host, $api_key); $ping = $this->ping($api_host, $api_key);
if (isset($ping['sitesList'])) { if (isset($ping['sitesList'])) {
$arResult['sitesList'] = $ping['sitesList']; $arResult['sitesList'] = $ping['sitesList'];
} elseif (isset($ping['errCode'])) { } elseif (isset($ping['errCode'])) {
@ -482,7 +483,7 @@ class intaro_retailcrm extends CModule
$this->RETAIL_CRM_API = new ApiClient($api_host, $api_key); $this->RETAIL_CRM_API = new ApiClient($api_host, $api_key);
//bitrix orderTypesList //bitrix orderTypesList
$arResult['arSites'] = RCrmActions::SitesList(); $arResult['arSites'] = RCrmActions::getSitesList();
$arResult['bitrixOrderTypesList'] = RCrmActions::OrderTypesList($arResult['arSites']); $arResult['bitrixOrderTypesList'] = RCrmActions::OrderTypesList($arResult['arSites']);
$orderTypesArr = array(); $orderTypesArr = array();
@ -658,7 +659,7 @@ class intaro_retailcrm extends CModule
} }
//bitrix orderTypesList //bitrix orderTypesList
$orderTypesList = RCrmActions::OrderTypesList(RCrmActions::SitesList()); $orderTypesList = RCrmActions::OrderTypesList(RCrmActions::getSitesList());
$orderTypesArr = array(); $orderTypesArr = array();
foreach ($orderTypesList as $orderType) { foreach ($orderTypesList as $orderType) {

View File

@ -1,4 +1,9 @@
<?php <?php
use RetailCrm\ApiClient;
/** @var $APPLICATION */
IncludeModuleLangFile(__FILE__); IncludeModuleLangFile(__FILE__);
$MODULE_ID = 'intaro.retailcrm'; $MODULE_ID = 'intaro.retailcrm';
@ -13,12 +18,12 @@ $CRM_PAYMENT = 'payment_arr';
$CRM_ORDER_TYPES_ARR = 'order_types_arr'; $CRM_ORDER_TYPES_ARR = 'order_types_arr';
$api_host = COption::GetOptionString($MODULE_ID, $CRM_API_HOST_OPTION, 0); $api_host = COption::GetOptionString($MODULE_ID, $CRM_API_HOST_OPTION, 0);
$api_key = COption::GetOptionString($MODULE_ID, $CRM_API_KEY_OPTION, 0); $api_key = COption::GetOptionString($MODULE_ID, $CRM_API_KEY_OPTION, 0);
$arResult['arSites'] = RCrmActions::SitesList(); $arResult['arSites'] = RCrmActions::getSitesList();
$RETAIL_CRM_API = new \RetailCrm\ApiClient($api_host, $api_key); $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_HOST_OPTION, $api_host);
COption::SetOptionString($MODULE_ID, $CRM_API_KEY_OPTION, $api_key); COption::SetOptionString($MODULE_ID, $CRM_API_KEY_OPTION, $api_key);
COption::SetOptionString($MODULE_ID, $CRM_SITES_LIST, serialize(array())); COption::SetOptionString($MODULE_ID, $CRM_SITES_LIST, serialize([]));
if (!isset($arResult['PAYMENT'])) { if (!isset($arResult['PAYMENT'])) {
$arResult['PAYMENT'] = unserialize(COption::GetOptionString($MODULE_ID, $CRM_PAYMENT, 0)); $arResult['PAYMENT'] = unserialize(COption::GetOptionString($MODULE_ID, $CRM_PAYMENT, 0));
@ -62,59 +67,53 @@ $arResult['bitrixPaymentList'][0]['ID'] = 'Y';
$arResult['bitrixPaymentList'][1]['NAME'] = GetMessage('PAYMENT_N'); $arResult['bitrixPaymentList'][1]['NAME'] = GetMessage('PAYMENT_N');
$arResult['bitrixPaymentList'][1]['ID'] = 'N'; $arResult['bitrixPaymentList'][1]['ID'] = 'N';
if(isset($arResult['ORDER_TYPES'])){ if (isset($arResult['ORDER_TYPES'])) {
$defaultOrderTypes = $arResult['ORDER_TYPES']; $defaultOrderTypes = $arResult['ORDER_TYPES'];
} } else {
else{ $defaultOrderTypes = [
$defaultOrderTypes = array (
1 => 'eshop-individual', 1 => 'eshop-individual',
2 => 'eshop-legal' 2 => 'eshop-legal',
); ];
} }
if(isset($arResult['DELIVERY_TYPES'])){ if (isset($arResult['DELIVERY_TYPES'])) {
$defaultDelivTypes = $arResult['DELIVERY_TYPES']; $defaultDelivTypes = $arResult['DELIVERY_TYPES'];
} } else {
else{ $defaultDelivTypes = [
$defaultDelivTypes = array (
1 => 'courier', 1 => 'courier',
2 => 'self-delivery' 2 => 'self-delivery',
); ];
} }
if(isset($arResult['PAYMENT_TYPES'])){ if (isset($arResult['PAYMENT_TYPES'])) {
$defaultPayTypes = $arResult['PAYMENT_TYPES']; $defaultPayTypes = $arResult['PAYMENT_TYPES'];
} } else {
else{ $defaultPayTypes = [
$defaultPayTypes = array (
1 => 'cash', 1 => 'cash',
4 => 'e-money', 4 => 'e-money',
5 => 'bank-card', 5 => 'bank-card',
9 => 'bank-transfer' 9 => 'bank-transfer',
); ];
} }
if(isset($arResult['PAYMENT_STATUSES'])){ if (isset($arResult['PAYMENT_STATUSES'])) {
$defaultPayStatuses = $arResult['PAYMENT_STATUSES']; $defaultPayStatuses = $arResult['PAYMENT_STATUSES'];
} } else {
else{ $defaultPayStatuses = [
$defaultPayStatuses = array (
'N' => 'new', 'N' => 'new',
'P' => 'prepayed', 'P' => 'prepayed',
'F' => 'complete', 'F' => 'complete',
); ];
} }
if(isset($arResult['PAYMENT'])){ if (isset($arResult['PAYMENT'])) {
$defaultPayment = $arResult['PAYMENT']; $defaultPayment = $arResult['PAYMENT'];
} } else {
else{ $defaultPayment = [
$defaultPayment = array(
'Y' => 'paid', 'Y' => 'paid',
'N' => 'not-paid' 'N' => 'not-paid',
); ];
} }
?> ?>
<style type="text/css"> <style type="text/css">
@ -278,7 +277,7 @@ else{
</table> </table>
</td> </td>
</tr> </tr>
<?endif;?> <?php endif;?>
<?php foreach($arResult['bitrixStatusesList'] as $bitrixStatus): ?> <?php foreach($arResult['bitrixStatusesList'] as $bitrixStatus): ?>
<tr> <tr>

View File

@ -1,6 +1,13 @@
<?php <?php
if (!check_bitrix_sessid())
use RetailCrm\ApiClient;
/** @var $APPLICATION */
if (!check_bitrix_sessid()) {
return; return;
}
IncludeModuleLangFile(__FILE__); IncludeModuleLangFile(__FILE__);
$MODULE_ID = 'intaro.retailcrm'; $MODULE_ID = 'intaro.retailcrm';
@ -12,12 +19,12 @@ $CRM_CONTRAGENT_TYPE = 'contragent_type';
$CRM_LEGAL_DETAILS = 'legal_details'; $CRM_LEGAL_DETAILS = 'legal_details';
$api_host = COption::GetOptionString($MODULE_ID, $CRM_API_HOST_OPTION, 0); $api_host = COption::GetOptionString($MODULE_ID, $CRM_API_HOST_OPTION, 0);
$api_key = COption::GetOptionString($MODULE_ID, $CRM_API_KEY_OPTION, 0); $api_key = COption::GetOptionString($MODULE_ID, $CRM_API_KEY_OPTION, 0);
$arResult['arSites'] = RCrmActions::SitesList(); $arResult['arSites'] = RCrmActions::getSitesList();
$RETAIL_CRM_API = new \RetailCrm\ApiClient($api_host, $api_key); $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_HOST_OPTION, $api_host);
COption::SetOptionString($MODULE_ID, $CRM_API_KEY_OPTION, $api_key); COption::SetOptionString($MODULE_ID, $CRM_API_KEY_OPTION, $api_key);
COption::SetOptionString($MODULE_ID, $CRM_SITES_LIST, serialize(array())); COption::SetOptionString($MODULE_ID, $CRM_SITES_LIST, serialize([]));
if (!isset($arResult['bitrixOrderTypesList'])) { if (!isset($arResult['bitrixOrderTypesList'])) {
$arResult['bitrixOrderTypesList'] = RCrmActions::OrderTypesList($arResult['arSites']); $arResult['bitrixOrderTypesList'] = RCrmActions::OrderTypesList($arResult['arSites']);
@ -33,35 +40,34 @@ if (!isset($arResult['CONTRAGENT_TYPES'])) {
$arResult['CONTRAGENT_TYPES'] = unserialize(COption::GetOptionString($MODULE_ID, $CRM_CONTRAGENT_TYPE, 0)); $arResult['CONTRAGENT_TYPES'] = unserialize(COption::GetOptionString($MODULE_ID, $CRM_CONTRAGENT_TYPE, 0));
} }
if(isset($arResult['ORDER_PROPS'])){ if (isset($arResult['ORDER_PROPS'])) {
$defaultOrderProps = $arResult['ORDER_PROPS']; $defaultOrderProps = $arResult['ORDER_PROPS'];
} } else {
else{ $defaultOrderProps = [
$defaultOrderProps = array( 1 => [
1 => array(
'fio' => 'FIO', 'fio' => 'FIO',
'index' => 'ZIP', 'index' => 'ZIP',
'text' => 'ADDRESS', 'text' => 'ADDRESS',
'phone' => 'PHONE', 'phone' => 'PHONE',
'email' => 'EMAIL' 'email' => 'EMAIL',
), ],
2 => array( 2 => [
'fio' => 'CONTACT_PERSON', 'fio' => 'CONTACT_PERSON',
'index' => 'ZIP', 'index' => 'ZIP',
'text' => 'ADDRESS', 'text' => 'ADDRESS',
'phone' => 'PHONE', 'phone' => 'PHONE',
'email' => 'EMAIL' 'email' => 'EMAIL',
) ],
); ];
} }
?> ?>
<script type="text/javascript" src="/bitrix/js/main/jquery/jquery-1.7.min.js"></script> <script type="text/javascript" src="/bitrix/js/main/jquery/jquery-1.7.min.js"></script>
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function() { $(document).ready(function() {
individual = $("[name='contragent-type-1']").val(); const individual = $("[name='contragent-type-1']").val();
legalEntity = $("[name='contragent-type-2']").val(); const legalEntity = $("[name='contragent-type-2']").val();
if (legalEntity != 'individual') { if (legalEntity !== 'individual') {
$('tr.legal-detail-2').each(function(){ $('tr.legal-detail-2').each(function(){
if($(this).hasClass(legalEntity)){ if($(this).hasClass(legalEntity)){
$(this).show(); $(this).show();
@ -70,7 +76,7 @@ else{
}); });
} }
if (individual != 'individual') { if (individual !== 'individual') {
$('tr.legal-detail-1').each(function(){ $('tr.legal-detail-1').each(function(){
if($(this).hasClass(individual)){ if($(this).hasClass(individual)){
$(this).show(); $(this).show();
@ -80,8 +86,8 @@ else{
} }
$('input.addr').change(function(){ $('input.addr').change(function(){
splitName = $(this).attr('name').split('-'); const splitName = $(this).attr('name').split('-');
orderType = splitName[2]; const orderType = splitName[2];
if(parseInt($(this).val()) === 1) if(parseInt($(this).val()) === 1)
$('tr.address-detail-' + orderType).show('slow'); $('tr.address-detail-' + orderType).show('slow');
@ -90,13 +96,15 @@ else{
}); });
$('tr.contragent-type select').change(function(){ $('tr.contragent-type select').change(function(){
splitName = $(this).attr('name').split('-'); const splitName = $(this).attr('name').split('-');
contragentType = $(this).val(); const contragentType = $(this).val();
orderType = splitName[2]; const orderType = splitName[2];
$('tr.legal-detail-' + orderType).hide(); let legalDetailOrderType = $('tr.legal-detail-' + orderType);
legalDetailOrderType.hide();
$('.legal-detail-title-' + orderType).hide(); $('.legal-detail-title-' + orderType).hide();
$('tr.legal-detail-' + orderType).each(function(){ legalDetailOrderType.each(function(){
if($(this).hasClass(contragentType)){ if($(this).hasClass(contragentType)){
$(this).show(); $(this).show();
$('.legal-detail-title-' + orderType).show(); $('.legal-detail-title-' + orderType).show();
@ -107,9 +115,9 @@ else{
</script> </script>
<div class="adm-detail-content-item-block"> <div class="adm-detail-content-item-block">
<form action="<?php echo $APPLICATION->GetCurPage() ?>" method="POST"> <form action="<?= $APPLICATION->GetCurPage() ?>" method="POST">
<?php echo bitrix_sessid_post(); ?> <?= bitrix_sessid_post()?>
<input type="hidden" name="lang" value="<?php echo LANGUAGE_ID ?>"> <input type="hidden" name="lang" value="<?= LANGUAGE_ID ?>">
<input type="hidden" name="id" value="intaro.retailcrm"> <input type="hidden" name="id" value="intaro.retailcrm">
<input type="hidden" name="install" value="Y"> <input type="hidden" name="install" value="Y">
<input type="hidden" name="step" value="4"> <input type="hidden" name="step" value="4">
@ -118,27 +126,34 @@ else{
<table class="adm-detail-content-table edit-table" id="edit1_edit_table"> <table class="adm-detail-content-table edit-table" id="edit1_edit_table">
<tbody> <tbody>
<tr class="heading"> <tr class="heading">
<td colspan="2"><b><?php echo GetMessage('STEP_NAME'); ?></b></td> <td colspan="2"><b><?= GetMessage('STEP_NAME')?></b></td>
</tr> </tr>
<tr class="heading"> <tr class="heading">
<td colspan="2"><b><?php echo GetMessage('ORDER_PROPS'); ?></b></td> <td colspan="2"><b><?= GetMessage('ORDER_PROPS')?></b></td>
</tr> </tr>
<tr align="center"> <tr align="center">
<td colspan="2"><b><?php echo GetMessage('INFO_2'); ?></b></td> <td colspan="2"><b><?= GetMessage('INFO_2')?></b></td>
</tr> </tr>
<?php foreach($arResult['bitrixOrderTypesList'] as $bitrixOrderType): ?> <?php foreach($arResult['bitrixOrderTypesList'] as $bitrixOrderType): ?>
<tr class="heading"> <tr class="heading">
<td colspan="2"><b><?php echo GetMessage('ORDER_TYPE_INFO') . ' ' . $bitrixOrderType['NAME']; ?></b></td> <td colspan="2"><b><?= GetMessage('ORDER_TYPE_INFO') . ' ' . $bitrixOrderType['NAME']?></b></td>
</tr> </tr>
<tr class="contragent-type"> <tr class="contragent-type">
<td width="50%" class="adm-detail-content-cell-l"> <td width="50%" class="adm-detail-content-cell-l">
<?php echo GetMessage('CONTRAGENT_TYPE'); ?> <?= GetMessage('CONTRAGENT_TYPE')?>
</td> </td>
<td width="50%" class="adm-detail-content-cell-r"> <td width="50%" class="adm-detail-content-cell-r">
<select name="contragent-type-<?php echo $bitrixOrderType['ID']; ?>" class="typeselect"> <select name="contragent-type-<?= $bitrixOrderType['ID']?>" class="typeselect">
<?php foreach ($arResult['contragentType'] as $contragentType): ?> <?php foreach ($arResult['contragentType'] as $contragentType): ?>
<option value="<?php echo $contragentType["ID"]; ?>" <?php if (isset($arResult['CONTRAGENT_TYPES'][$bitrixOrderType['ID']]) && $arResult['CONTRAGENT_TYPES'][$bitrixOrderType['ID']] == $contragentType["ID"]) echo 'selected'; ?>> <option value="<?= $contragentType['ID']; ?>"
<?php echo $contragentType["NAME"]; ?> <?=
(isset($arResult['CONTRAGENT_TYPES'][$bitrixOrderType['ID']])
&& $arResult['CONTRAGENT_TYPES'][$bitrixOrderType['ID']] == $contragentType['ID']) ?
'selected'
: ''
?>
>
<?= $contragentType['NAME']?>
</option> </option>
<?php endforeach; ?> <?php endforeach; ?>
</select> </select>
@ -146,27 +161,45 @@ else{
</tr> </tr>
<?php $countProps = 0; foreach($arResult['orderProps'] as $orderProp): ?> <?php $countProps = 0; foreach($arResult['orderProps'] as $orderProp): ?>
<?php if($orderProp['ID'] == 'text'): ?> <?php if($orderProp['ID'] === 'text'): ?>
<tr class="heading"> <tr class="heading">
<td colspan="2" style="background-color: transparent;"> <td colspan="2" style="background-color: transparent;">
<b> <b>
<label><input class="addr" type="radio" name="address-detail-<?php echo $bitrixOrderType['ID']; ?>" value="0" <?php if(count($defaultOrderProps[$bitrixOrderType['ID']]) < 6) echo "checked"; ?>><?php echo GetMessage('ADDRESS_SHORT'); ?></label> <label>
<label><input class="addr" type="radio" name="address-detail-<?php echo $bitrixOrderType['ID']; ?>" value="1" <?php if(count($defaultOrderProps[$bitrixOrderType['ID']]) > 5) echo "checked"; ?>><?php echo GetMessage('ADDRESS_FULL'); ?></label> <input class="addr" type="radio" name="address-detail-<?= $bitrixOrderType['ID']?>" value="0"
<?= (count($defaultOrderProps[$bitrixOrderType['ID']]) < 6) ? 'checked' : '' ?>>
<?= GetMessage('ADDRESS_SHORT')?>
</label>
<label>
<input class="addr" type="radio" name="address-detail-<?= $bitrixOrderType['ID']?>" value="1"
<?= (count($defaultOrderProps[$bitrixOrderType['ID']]) > 5) ? 'checked' : '' ?>
>
<?= GetMessage('ADDRESS_FULL')?>
</label>
</b> </b>
</td> </td>
</tr> </tr>
<?php endif; ?> <?php endif; ?>
<tr <?php if ($countProps > 3) echo 'class="address-detail-' . $bitrixOrderType['ID'] . '"'; if(($countProps > 3) && (count($defaultOrderProps[$bitrixOrderType['ID']]) < 6)) echo 'style="display:none;"';?>> <tr <?= ($countProps > 3) ? 'class="address-detail-' . $bitrixOrderType['ID'] . '"' : ''?>
<td width="50%" class="adm-detail-content-cell-l" name="<?php echo $orderProp['ID']; ?>"> <?= (($countProps > 3) && (count($defaultOrderProps[$bitrixOrderType['ID']]) < 6))
<?php echo $orderProp['NAME']; ?> ? 'style="display:none;"'
: ''
?>
>
<td width="50%" class="adm-detail-content-cell-l" name="<?= $orderProp['ID']?>">
<?= $orderProp['NAME']; ?>
</td> </td>
<td width="50%" class="adm-detail-content-cell-r"> <td width="50%" class="adm-detail-content-cell-r">
<select name="order-prop-<?php echo $orderProp['ID'] . '-' . $bitrixOrderType['ID']; ?>" class="typeselect"> <select name="order-prop-<?= $orderProp['ID'] . '-' . $bitrixOrderType['ID']?>" class="typeselect">
<option value=""></option> <option value=""></option>
<?php foreach ($arResult['arProp'][$bitrixOrderType['ID']] as $arProp): ?> <?php foreach ($arResult['arProp'][$bitrixOrderType['ID']] as $arProp): ?>
<option value="<?php echo $arProp['CODE']; ?>" <?php if ($defaultOrderProps[$bitrixOrderType['ID']][$orderProp['ID']] == $arProp['CODE']) echo 'selected'; ?>> <option value="<?= $arProp['CODE']?>"
<?php echo $arProp['NAME']; ?> <?= ($defaultOrderProps[$bitrixOrderType['ID']][$orderProp['ID']] === $arProp['CODE'])
? 'selected'
: '' ?>
>
<?= $arProp['NAME']?>
</option> </option>
<?php endforeach; ?> <?php endforeach; ?>
</select> </select>
@ -178,7 +211,7 @@ else{
<tr class="heading custom-detail-title"> <tr class="heading custom-detail-title">
<td colspan="2" style="background-color: transparent;"> <td colspan="2" style="background-color: transparent;">
<b> <b>
<?=GetMessage("ORDER_CUSTOM"); ?> <?=GetMessage('ORDER_CUSTOM'); ?>
</b> </b>
</td> </td>
</tr> </tr>
@ -188,55 +221,65 @@ else{
<?=$customFields['NAME']; ?> <?=$customFields['NAME']; ?>
</td> </td>
<td width="50%" class=""> <td width="50%" class="">
<select name="custom-fields-<?=$customFields['ID'] . '-' . $bitrixOrderType['ID']; ?>" class="typeselect"> <select name="custom-fields-<?=$customFields['ID'] . '-' . $bitrixOrderType['ID']?>" class="typeselect">
<option value=""></option> <option value=""></option>
<?foreach ($arResult['arProp'][$bitrixOrderType['ID']] as $arProp):?> <?foreach ($arResult['arProp'][$bitrixOrderType['ID']] as $arProp):?>
<option value="<?=$arProp['CODE']?>" <?php if (isset($arResult['CUSTOM_FIELDS'][$bitrixOrderType['ID']][$customFields['ID']]) && $arResult['CUSTOM_FIELDS'][$bitrixOrderType['ID']][$customFields['ID']] == $arProp['CODE']) echo 'selected'; ?>> <option value="<?=$arProp['CODE']?>"
<?=$arProp['NAME']; ?> <?= (isset($arResult['CUSTOM_FIELDS'][$bitrixOrderType['ID']][$customFields['ID']])
&& $arResult['CUSTOM_FIELDS'][$bitrixOrderType['ID']][$customFields['ID']]
=== $arProp['CODE'])
? 'selected'
: ''
?>>
<?=$arProp['NAME']?>
</option> </option>
<?endforeach;?> <?php endforeach;?>
</select> </select>
</td> </td>
</tr> </tr>
<?endforeach;?> <?php endforeach;?>
<?endif;?> <?php endif;?>
<tr class="heading legal-detail-title-<?php echo $bitrixOrderType['ID'];?>" style="display:none"> <tr class="heading legal-detail-title-<?= $bitrixOrderType['ID']?>" style="display:none">
<td colspan="2" style="background-color: transparent;"> <td colspan="2" style="background-color: transparent;">
<b> <b>
<?php echo GetMessage("ORDER_LEGAL_INFO"); ?> <?= GetMessage('ORDER_LEGAL_INFO'); ?>
</b> </b>
</td> </td>
</tr> </tr>
<?php foreach($arResult['legalDetails'] as $legalDetails): ?> <?php foreach($arResult['legalDetails'] as $legalDetails): ?>
<tr class="legal-detail-<?php echo $bitrixOrderType['ID'];?> <?php foreach($legalDetails['GROUP'] as $gr) echo $gr . ' ';?>" style="display:none"> <tr class="legal-detail-<?= $bitrixOrderType['ID']?> <?php foreach($legalDetails['GROUP'] as $gr) echo $gr . ' ';?>" style="display:none">
<td width="50%" class="adm-detail-content-cell-l"> <td width="50%" class="adm-detail-content-cell-l">
<?php echo $legalDetails['NAME']; ?> <?= $legalDetails['NAME']; ?>
</td> </td>
<td width="50%" class="adm-detail-content-cell-r"> <td width="50%" class="adm-detail-content-cell-r">
<select name="legal-detail-<?php echo $legalDetails['ID'] . '-' . $bitrixOrderType['ID']; ?>" class="typeselect"> <select name="legal-detail-<?= $legalDetails['ID'] . '-' . $bitrixOrderType['ID']?>" class="typeselect">
<option value=""></option> <option value=""></option>
<?php foreach ($arResult['arProp'][$bitrixOrderType['ID']] as $arProp): ?> <?php foreach ($arResult['arProp'][$bitrixOrderType['ID']] as $arProp): ?>
<option value="<?php echo $arProp['CODE']; ?>" <?php if (isset($arResult['LEGAL_DETAILS'][$bitrixOrderType['ID']][$legalDetails['ID']]) && $arResult['LEGAL_DETAILS'][$bitrixOrderType['ID']][$legalDetails['ID']] == $arProp['CODE']) echo 'selected'; ?>> <option value="<?= $arProp['CODE']?>"
<?php echo $arProp['NAME']; ?> <?= (isset($arResult['LEGAL_DETAILS'][$bitrixOrderType['ID']][$legalDetails['ID']])
&& $arResult['LEGAL_DETAILS'][$bitrixOrderType['ID']][$legalDetails['ID']] === $arProp['CODE'])
? 'selected' : ''
?>
>
<?= $arProp['NAME']?>
</option> </option>
<?php endforeach; ?> <?php endforeach; ?>
</select> </select>
</td> </td>
</tr> </tr>
<?php endforeach; ?> <?php endforeach; ?>
<?php endforeach; ?> <?php endforeach; ?>
</tbody> </tbody>
</table> </table>
<br /> <br />
<div style="padding: 1px 13px 2px; height:28px;"> <div style="padding: 1px 13px 2px; height:28px;">
<div align="right" style="float:right; width:50%; position:relative;"> <div align="right" style="float:right; width:50%; position:relative;">
<input type="submit" name="inst" value="<?php echo GetMessage("MOD_NEXT_STEP"); ?>" class="adm-btn-save"> <input type="submit" name="inst" value="<?= GetMessage('MOD_NEXT_STEP')?>" class="adm-btn-save">
</div> </div>
<div align="left" style="float:right; width:50%; position:relative; visible: none;"> <div align="left" style="float:right; width:50%; position:relative; visible: none;">
<input type="submit" name="back" value="<?php echo GetMessage("MOD_PREV_STEP"); ?>" class="adm-btn-save"> <input type="submit" name="back" value="<?= GetMessage('MOD_PREV_STEP')?>" class="adm-btn-save">
</div> </div>
</div> </div>
</form> </form>

View File

@ -97,7 +97,7 @@ if (file_exists($_SERVER["DOCUMENT_ROOT"] . '/bitrix/modules/intaro.retailcrm/cl
} }
} }
$arResult['arSites'] = RCrmActions::SitesList(); $arResult['arSites'] = RCrmActions::getSitesList();
//ajax update deliveryServices //ajax update deliveryServices
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && (strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') && isset($_POST['ajax']) && ($_POST['ajax'] == 1)) { if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && (strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') && isset($_POST['ajax']) && ($_POST['ajax'] == 1)) {
$api_host = COption::GetOptionString($mid, $CRM_API_HOST_OPTION, 0); $api_host = COption::GetOptionString($mid, $CRM_API_HOST_OPTION, 0);
@ -211,7 +211,8 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
$api_key = htmlspecialchars(trim($_POST['api_key'])); $api_key = htmlspecialchars(trim($_POST['api_key']));
//bitrix site list //bitrix site list
$siteListArr = array(); $siteListArr = [];
foreach ($arResult['arSites'] as $arSites) { foreach ($arResult['arSites'] as $arSites) {
if (count($arResult['arSites']) > 1) { if (count($arResult['arSites']) > 1) {
if ($_POST['sites-id-' . $arSites['LID']]) { if ($_POST['sites-id-' . $arSites['LID']]) {