1
0
mirror of synced 2025-01-18 17:01: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
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;
IncludeModuleLangFile(__FILE__);
@ -8,13 +14,16 @@ class RCrmActions
public static $MODULE_ID = 'intaro.retailcrm';
public static $CRM_ORDER_FAILED_IDS = 'order_failed_ids';
public static $CRM_API_VERSION = 'api_version';
public const CANCEL_PROPERTY_CODE = 'INTAROCRM_IS_CANCELED';
const CANCEL_PROPERTY_CODE = 'INTAROCRM_IS_CANCELED';
public static function SitesList()
/**
* @return array
*/
public static function getSitesList(): array
{
$arSites = array();
$rsSites = CSite::GetList($by, $sort, array('ACTIVE' => 'Y'));
$arSites = [];
$rsSites = CSite::GetList($by, $sort, ['ACTIVE' => 'Y']);
while ($ar = $rsSites->Fetch()) {
$arSites[] = $ar;
}
@ -44,7 +53,7 @@ class RCrmActions
{
$bitrixDeliveryTypesList = array();
$arDeliveryServiceAll = \Bitrix\Sale\Delivery\Services\Manager::getActiveList();
$noOrderId = \Bitrix\Sale\Delivery\Services\EmptyDeliveryService::getEmptyDeliveryServiceId();
$noOrderId = EmptyDeliveryService::getEmptyDeliveryServiceId();
$groups = array();
foreach ($arDeliveryServiceAll as $arDeliveryService) {
if ($arDeliveryService['CLASS_NAME'] == '\Bitrix\Sale\Delivery\Services\Group') {
@ -69,7 +78,7 @@ class RCrmActions
public static function PaymentList()
{
$bitrixPaymentTypesList = array();
$dbPaymentAll = \Bitrix\Sale\PaySystem\Manager::getList(array(
$dbPaymentAll = Manager::getList(array(
'select' => array('ID', 'NAME'),
'filter' => array('ACTIVE' => 'Y')
));
@ -83,9 +92,9 @@ class RCrmActions
public static function StatusesList()
{
$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),
'select' => array('ID', "NAME" => 'Bitrix\Sale\Internals\StatusLangTable:STATUS.NAME')
'select' => array('ID', 'NAME' => 'Bitrix\Sale\Internals\StatusLangTable:STATUS.NAME')
));
while ($arStatus = $obStatuses->fetch()) {
$bitrixPaymentStatusesList[$arStatus['ID']] = array(
@ -100,7 +109,7 @@ class RCrmActions
public static function OrderPropsList()
{
$bitrixPropsList = array();
$arPropsAll = \Bitrix\Sale\Internals\OrderPropsTable::getList(array(
$arPropsAll = OrderPropsTable::getList(array(
'select' => array('*'),
'filter' => array('CODE' => '_%')
));
@ -133,7 +142,7 @@ class RCrmActions
public static function StoresExportList()
{
$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()) {
$catalogExportStores[] = $stores;
}
@ -144,10 +153,10 @@ class RCrmActions
public static function IblocksExportList()
{
$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()) {
if ($arCatalog = CCatalog::GetByIDExt($iblock["ID"])) {
if($arCatalog['CATALOG_TYPE'] == "D" || $arCatalog['CATALOG_TYPE'] == "X" || $arCatalog['CATALOG_TYPE'] == "P") {
if ($arCatalog = CCatalog::GetByIDExt($iblock['ID'])) {
if($arCatalog['CATALOG_TYPE'] == 'D' || $arCatalog['CATALOG_TYPE'] == 'X' || $arCatalog['CATALOG_TYPE'] == 'P') {
$catalogExportIblocks[$iblock['ID']] = array(
'ID' => $iblock['ID'],
'IBLOCK_TYPE_ID' => $iblock['IBLOCK_TYPE_ID'],
@ -156,8 +165,8 @@ class RCrmActions
'NAME' => $iblock['NAME'],
);
if ($arCatalog['CATALOG_TYPE'] == "X" || $arCatalog['CATALOG_TYPE'] == "P") {
$iblockOffer = CCatalogSKU::GetInfoByProductIBlock($iblock["ID"]);
if ($arCatalog['CATALOG_TYPE'] == 'X' || $arCatalog['CATALOG_TYPE'] == 'P') {
$iblockOffer = CCatalogSKU::GetInfoByProductIBlock($iblock['ID']);
$catalogExportIblocks[$iblock['ID']]['SKU'] = $iblockOffer;
}
}
@ -175,11 +184,11 @@ class RCrmActions
public static function eventLog($auditType, $itemId, $description)
{
CEventLog::Add(array(
"SEVERITY" => "SECURITY",
"AUDIT_TYPE_ID" => $auditType,
"MODULE_ID" => self::$MODULE_ID,
"ITEM_ID" => $itemId,
"DESCRIPTION" => $description,
'SEVERITY' => 'SECURITY',
'AUDIT_TYPE_ID' => $auditType,
'MODULE_ID' => self::$MODULE_ID,
'ITEM_ID' => $itemId,
'DESCRIPTION' => $description,
));
}
@ -373,7 +382,7 @@ class RCrmActions
if (empty($fio)) {
return $result;
} else {
$newFio = explode(" ", $fio, 3);
$newFio = explode(' ', $fio, 3);
}
switch (count($newFio)) {
@ -490,7 +499,7 @@ class RCrmActions
if (!$result) {
$err = new RuntimeException(
$methodApi . ": Got null instead of valid result!"
$methodApi . ': Got null instead of valid result!'
);
Logger::getInstance()->write(sprintf(
'%s%s%s',
@ -548,7 +557,7 @@ class RCrmActions
return false;
}
} catch (\RetailCrm\Exception\CurlException $e) {
} catch (CurlException $e) {
static::logException(
$method,
$methodApi,
@ -572,7 +581,7 @@ class RCrmActions
);
return false;
} catch (\RetailCrm\Exception\InvalidJsonException $e) {
} catch (InvalidJsonException $e) {
static::logException(
$method,
$methodApi,

View File

@ -1,6 +1,8 @@
<?php
use Intaro\RetailCrm\Service\ManagerService;
use Bitrix\Sale\Payment;
use RetailCrm\ApiClient;
/**
* Class RetailCrmEvent
@ -10,21 +12,12 @@ class RetailCrmEvent
protected static $MODULE_ID = 'intaro.retailcrm';
protected static $CRM_API_HOST_OPTION = 'api_host';
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_STATUSES = 'pay_statuses_arr';
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_CONTRAGENT_TYPE = 'contragent_type';
protected static $CRM_ORDER_FAILED_IDS = 'order_failed_ids';
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
@ -32,7 +25,7 @@ class RetailCrmEvent
* @return bool
* @throws InvalidArgumentException
*/
function OnAfterUserUpdate($arFields)
public function OnAfterUserUpdate($arFields)
{
if (isset($GLOBALS['RETAIL_CRM_HISTORY']) && $GLOBALS['RETAIL_CRM_HISTORY']) {
return false;
@ -59,7 +52,7 @@ class RetailCrmEvent
* @param mixed $ID - Order id
* @param mixed $arFields - Order arFields
*/
function onUpdateOrder($ID, $arFields)
public function onUpdateOrder($ID, $arFields)
{
if (isset($GLOBALS['RETAIL_CRM_HISTORY']) && $GLOBALS['RETAIL_CRM_HISTORY']) {
$GLOBALS['RETAILCRM_ORDER_OLD_EVENT'] = false;
@ -68,7 +61,7 @@ class RetailCrmEvent
$GLOBALS['RETAILCRM_ORDER_OLD_EVENT'] = true;
if (($arFields['CANCELED'] == 'Y')
if (($arFields['CANCELED'] === 'Y')
&& (sizeof($arFields['BASKET_ITEMS']) == 0)
&& (sizeof($arFields['ORDER_PROP']) == 0)
) {
@ -83,7 +76,7 @@ class RetailCrmEvent
*
* @param object $event - Order object
*/
function orderDelete($event)
public function orderDelete($event)
{
$GLOBALS['RETAILCRM_ORDER_DELETE'] = true;
@ -98,7 +91,7 @@ class RetailCrmEvent
* @throws \Bitrix\Main\SystemException
* @throws \Bitrix\Main\ArgumentException
*/
function orderSave($event)
public function orderSave($event)
{
if (true == $GLOBALS['ORDER_DELETE_USER_ADMIN']) {
return false;
@ -120,13 +113,13 @@ class RetailCrmEvent
return false;
}
if (!CModule::IncludeModule("sale")) {
if (!CModule::IncludeModule('sale')) {
RCrmActions::eventLog('RetailCrmEvent::orderSave', 'sale', 'module not found');
return false;
}
if (!CModule::IncludeModule("catalog")) {
if (!CModule::IncludeModule('catalog')) {
RCrmActions::eventLog('RetailCrmEvent::orderSave', 'catalog', 'module not found');
return false;
@ -136,12 +129,13 @@ class RetailCrmEvent
if (method_exists($event, 'getId')) {
$obOrder = $event;
} elseif (method_exists($event, 'getParameter')) {
$obOrder = $event->getParameter("ENTITY");
$obOrder = $event->getParameter('ENTITY');
} else {
RCrmActions::eventLog('RetailCrmEvent::orderSave', 'events', 'event error');
return false;
}
$arOrder = RetailCrmOrder::orderObjToArr($obOrder);
$api = new RetailCrm\ApiClient(RetailcrmConfigProvider::getApiUrl(), RetailcrmConfigProvider::getApiKey());
@ -161,7 +155,7 @@ class RetailCrmEvent
//corp cliente swich
$optionCorpClient = RetailcrmConfigProvider::getCorporateClientStatus();
$arParams = RCrmActions::clearArr(array(
$arParams = RCrmActions::clearArr([
'optionsOrderTypes' => $optionsOrderTypes,
'optionsDelivTypes' => $optionsDelivTypes,
'optionsPayTypes' => $optionsPayTypes,
@ -171,8 +165,8 @@ class RetailCrmEvent
'optionsLegalDetails' => $optionsLegalDetails,
'optionsContragentType' => $optionsContragentType,
'optionsSitesList' => $optionsSitesList,
'optionsCustomFields' => $optionsCustomFields
));
'optionsCustomFields' => $optionsCustomFields,
]);
//many sites?
if ($optionsSitesList) {
@ -195,7 +189,6 @@ class RetailCrmEvent
}
$orderCompany = null;
if ('Y' === $optionCorpClient) {
if (true === RetailCrmCorporateClient::isCorpTookExternalId((string) $arOrder['USER_ID'], $api)) {
RetailCrmCorporateClient::setPrefixForExternalId((string) $arOrder['USER_ID'], $api);
@ -204,22 +197,22 @@ class RetailCrmEvent
//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
$nickName = '';
$address = '';
$corpAddress = '';
$contragent = array();
$userCorp = array();
$contragent = [];
$userCorp = [];
$corpName = RetailcrmConfigProvider::getCorporateClientName();
$corpAddress = RetailcrmConfigProvider::getCorporateClientAddress();
foreach ($arOrder['PROPS']['properties'] as $prop) {
if ($prop['CODE'] == $corpName) {
if ($prop['CODE'] === $corpName) {
$nickName = $prop['VALUE'][0];
}
if ($prop['CODE'] == $corpAddress) {
if ($prop['CODE'] === $corpAddress) {
$address = $prop['VALUE'][0];
}
@ -235,7 +228,7 @@ class RetailCrmEvent
}
$customersCorporate = false;
$response = $api->customersCorporateList(array('companyName' => $nickName));
$response = $api->customersCorporateList(['companyName' => $nickName]);
if ($response && $response->getStatusCode() == 200) {
$customersCorporate = $response['customersCorporate'];
@ -245,7 +238,7 @@ class RetailCrmEvent
$userCorp['customerCorporate'] = $singleCorp;
$companiesResponse = $api->customersCorporateCompanies(
$singleCorp['id'],
array(),
[],
null,
null,
'id',
@ -256,7 +249,7 @@ class RetailCrmEvent
$orderCompany = array_reduce(
$companiesResponse['companies'],
function ($carry, $item) use ($nickName) {
if (is_array($item) && $item['name'] == $nickName) {
if (is_array($item) && $item['name'] === $nickName) {
$carry = $item;
}
@ -286,7 +279,7 @@ class RetailCrmEvent
$arUser['PERSONAL_STREET'] = $address;
}
$resultUser = RetailCrmUser::customerSend($arUser, $api, "individual", true, $site);
$resultUser = RetailCrmUser::customerSend($arUser, $api, 'individual', true, $site);
if (!$resultUser) {
RCrmActions::eventLog(
@ -298,7 +291,7 @@ class RetailCrmEvent
return false;
}
$userCrm = array('customer' => array('externalId' => $arOrder['USER_ID']));
$userCrm = ['customer' => ['externalId' => $arOrder['USER_ID']]];
}
if (!isset($userCorp['customerCorporate'])) {
@ -320,56 +313,56 @@ class RetailCrmEvent
}
$arParams['customerCorporate'] = $resultUserCorp;
$arParams['orderCompany'] = isset($resultUserCorp['mainCompany']) ? $resultUserCorp['mainCompany'] : null;
$arParams['orderCompany'] = $resultUserCorp['mainCompany'] ?? null;
$customerCorporateAddress = array();
$customerCorporateCompany = array();
$customerCorporateAddress = [];
$customerCorporateCompany = [];
$addressResult = null;
$companyResult = null;
if (!empty($address)) {
//TODO address builder add
$customerCorporateAddress = array(
$customerCorporateAddress = [
'name' => $nickName,
'isMain' => true,
'text' => $address
);
'text' => $address,
];
$addressResult = $api->customersCorporateAddressesCreate($resultUserCorp['id'], $customerCorporateAddress, 'id', $site);
}
$customerCorporateCompany = array(
$customerCorporateCompany = [
'name' => $nickName,
'isMain' => true,
'contragent' => $contragent
);
'contragent' => $contragent,
];
if (!empty($addressResult)) {
$customerCorporateCompany['address'] = array(
'id' => $addressResult['id']
);
$customerCorporateCompany['address'] = [
'id' => $addressResult['id'],
];
}
$companyResult = $api->customersCorporateCompaniesCreate($resultUserCorp['id'], $customerCorporateCompany, 'id', $site);
$customerCorporateContact = array(
$customerCorporateContact = [
'isMain' => true,
'customer' => array(
'customer' => [
'externalId' => $arOrder['USER_ID'],
'site' => $site
)
);
'site' => $site,
],
];
if (!empty($companyResult)) {
$orderCompany = array(
'id' => $companyResult['id']
);
$orderCompany = [
'id' => $companyResult['id'],
];
$customerCorporateContact['companies'] = array(
array(
'company' => $orderCompany
)
);
$customerCorporateContact['companies'] = [
[
'company' => $orderCompany,
],
];
}
$api->customersCorporateContactsCreate(
@ -381,7 +374,7 @@ class RetailCrmEvent
$arParams['orderCompany'] = array_merge(
$customerCorporateCompany,
array('id' => $companyResult['id'])
['id' => $companyResult['id']]
);
} else {
RetailCrmCorporateClient::addCustomersCorporateAddresses(
@ -413,12 +406,10 @@ class RetailCrmEvent
}
}
}
if (isset($arOrder['RESPONSIBLE_ID']) && !empty($arOrder['RESPONSIBLE_ID'])) {
$managerService = ManagerService::getInstance();
$arParams['managerId'] = $managerService->getManagerCrmId($arOrder['RESPONSIBLE_ID']);
}
//order
$resultOrder = RetailCrmOrder::orderSend($arOrder, $api, $arParams, true, $site, $methodApi);
@ -438,7 +429,7 @@ class RetailCrmEvent
* @throws InvalidArgumentException
*
*/
function paymentSave($event)
public function paymentSave(Payment $event)
{
$apiVersion = COption::GetOptionString(self::$MODULE_ID, 'api_version', 0);
@ -446,7 +437,7 @@ class RetailCrmEvent
$order = $event->getCollection()->getOrder();
if ((isset($GLOBALS['RETAIL_CRM_HISTORY']) && $GLOBALS['RETAIL_CRM_HISTORY'])
|| $apiVersion != 'v5'
|| $apiVersion !== 'v5'
|| $order->isNew()
) {
return false;
@ -457,7 +448,7 @@ class RetailCrmEvent
$optionsPayStatuses = RetailcrmConfigProvider::getPayment();
$integrationPaymentTypes = RetailcrmConfigProvider::getIntegrationPaymentTypes();
$arPayment = array(
$arPayment = [
'ID' => $event->getId(),
'ORDER_ID' => $event->getField('ORDER_ID'),
'PAID' => $event->getField('PAID'),
@ -465,7 +456,7 @@ class RetailCrmEvent
'SUM' => $event->getField('SUM'),
'LID' => $order->getSiteId(),
'DATE_PAID' => $event->getField('DATE_PAID'),
);
];
if ($optionsSitesList) {
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']])) {
$paymentToCrm = array(
'type' => $optionsPaymentTypes[$arPayment['PAY_SYSTEM_ID']]
);
$paymentToCrm = [
'type' => $optionsPaymentTypes[$arPayment['PAY_SYSTEM_ID']],
];
if (!empty($arPayment['ID'])) {
$paymentToCrm['externalId'] = RCrmActions::generatePaymentExternalId($arPayment['ID']);
@ -508,7 +499,7 @@ class RetailCrmEvent
if (!empty($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);
} elseif (is_string($arPayment['DATE_PAID'])) {
$paymentToCrm['paidAt'] = $arPayment['DATE_PAID'];
@ -538,7 +529,7 @@ class RetailCrmEvent
} elseif (array_key_exists($arPayment['ID'], $paymentsExternalIds)) {
$paymentData = $paymentsExternalIds[$arPayment['ID']];
} else {
$paymentData = array();
$paymentData = [];
}
if (empty($paymentData)) {
@ -573,7 +564,7 @@ class RetailCrmEvent
*
* @throws InvalidArgumentException
*/
function paymentDelete($event)
public function paymentDelete(Payment $event): void
{
$apiVersion = COption::GetOptionString(self::$MODULE_ID, 'api_version', 0);
@ -584,13 +575,13 @@ class RetailCrmEvent
return;
}
$optionsSitesList = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_SITES_LIST, 0));
$optionsSitesList = RetailcrmConfigProvider::getSitesList();
$arPayment = array(
$arPayment = [
'ID' => $event->getId(),
'ORDER_ID' => $event->getField('ORDER_ID'),
'LID' => $event->getCollection()->getOrder()->getSiteId()
);
'LID' => $event->getCollection()->getOrder()->getSiteId(),
];
if ($optionsSitesList) {
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_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);
if (isset($orderCrm['order']['payments']) && $orderCrm['order']['payments']) {

View File

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

View File

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

View File

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

View File

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

View File

@ -1,6 +1,13 @@
<?php
if (!check_bitrix_sessid())
use RetailCrm\ApiClient;
/** @var $APPLICATION */
if (!check_bitrix_sessid()) {
return;
}
IncludeModuleLangFile(__FILE__);
$MODULE_ID = 'intaro.retailcrm';
@ -12,12 +19,12 @@ $CRM_CONTRAGENT_TYPE = 'contragent_type';
$CRM_LEGAL_DETAILS = 'legal_details';
$api_host = COption::GetOptionString($MODULE_ID, $CRM_API_HOST_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_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'])) {
$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));
}
if(isset($arResult['ORDER_PROPS'])){
if (isset($arResult['ORDER_PROPS'])) {
$defaultOrderProps = $arResult['ORDER_PROPS'];
}
else{
$defaultOrderProps = array(
1 => array(
} else {
$defaultOrderProps = [
1 => [
'fio' => 'FIO',
'index' => 'ZIP',
'text' => 'ADDRESS',
'phone' => 'PHONE',
'email' => 'EMAIL'
),
2 => array(
'email' => 'EMAIL',
],
2 => [
'fio' => 'CONTACT_PERSON',
'index' => 'ZIP',
'text' => 'ADDRESS',
'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">
$(document).ready(function() {
individual = $("[name='contragent-type-1']").val();
legalEntity = $("[name='contragent-type-2']").val();
const individual = $("[name='contragent-type-1']").val();
const legalEntity = $("[name='contragent-type-2']").val();
if (legalEntity != 'individual') {
if (legalEntity !== 'individual') {
$('tr.legal-detail-2').each(function(){
if($(this).hasClass(legalEntity)){
$(this).show();
@ -70,7 +76,7 @@ else{
});
}
if (individual != 'individual') {
if (individual !== 'individual') {
$('tr.legal-detail-1').each(function(){
if($(this).hasClass(individual)){
$(this).show();
@ -80,8 +86,8 @@ else{
}
$('input.addr').change(function(){
splitName = $(this).attr('name').split('-');
orderType = splitName[2];
const splitName = $(this).attr('name').split('-');
const orderType = splitName[2];
if(parseInt($(this).val()) === 1)
$('tr.address-detail-' + orderType).show('slow');
@ -90,13 +96,15 @@ else{
});
$('tr.contragent-type select').change(function(){
splitName = $(this).attr('name').split('-');
contragentType = $(this).val();
orderType = splitName[2];
$('tr.legal-detail-' + orderType).hide();
const splitName = $(this).attr('name').split('-');
const contragentType = $(this).val();
const orderType = splitName[2];
let legalDetailOrderType = $('tr.legal-detail-' + orderType);
legalDetailOrderType.hide();
$('.legal-detail-title-' + orderType).hide();
$('tr.legal-detail-' + orderType).each(function(){
legalDetailOrderType.each(function(){
if($(this).hasClass(contragentType)){
$(this).show();
$('.legal-detail-title-' + orderType).show();
@ -107,9 +115,9 @@ else{
</script>
<div class="adm-detail-content-item-block">
<form action="<?php echo $APPLICATION->GetCurPage() ?>" method="POST">
<?php echo bitrix_sessid_post(); ?>
<input type="hidden" name="lang" value="<?php echo LANGUAGE_ID ?>">
<form action="<?= $APPLICATION->GetCurPage() ?>" method="POST">
<?= bitrix_sessid_post()?>
<input type="hidden" name="lang" value="<?= LANGUAGE_ID ?>">
<input type="hidden" name="id" value="intaro.retailcrm">
<input type="hidden" name="install" value="Y">
<input type="hidden" name="step" value="4">
@ -118,27 +126,34 @@ else{
<table class="adm-detail-content-table edit-table" id="edit1_edit_table">
<tbody>
<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 class="heading">
<td colspan="2"><b><?php echo GetMessage('ORDER_PROPS'); ?></b></td>
<td colspan="2"><b><?= GetMessage('ORDER_PROPS')?></b></td>
</tr>
<tr align="center">
<td colspan="2"><b><?php echo GetMessage('INFO_2'); ?></b></td>
<td colspan="2"><b><?= GetMessage('INFO_2')?></b></td>
</tr>
<?php foreach($arResult['bitrixOrderTypesList'] as $bitrixOrderType): ?>
<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 class="contragent-type">
<td width="50%" class="adm-detail-content-cell-l">
<?php echo GetMessage('CONTRAGENT_TYPE'); ?>
<?= GetMessage('CONTRAGENT_TYPE')?>
</td>
<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): ?>
<option value="<?php echo $contragentType["ID"]; ?>" <?php if (isset($arResult['CONTRAGENT_TYPES'][$bitrixOrderType['ID']]) && $arResult['CONTRAGENT_TYPES'][$bitrixOrderType['ID']] == $contragentType["ID"]) echo 'selected'; ?>>
<?php echo $contragentType["NAME"]; ?>
<option value="<?= $contragentType['ID']; ?>"
<?=
(isset($arResult['CONTRAGENT_TYPES'][$bitrixOrderType['ID']])
&& $arResult['CONTRAGENT_TYPES'][$bitrixOrderType['ID']] == $contragentType['ID']) ?
'selected'
: ''
?>
>
<?= $contragentType['NAME']?>
</option>
<?php endforeach; ?>
</select>
@ -146,27 +161,45 @@ else{
</tr>
<?php $countProps = 0; foreach($arResult['orderProps'] as $orderProp): ?>
<?php if($orderProp['ID'] == 'text'): ?>
<?php if($orderProp['ID'] === 'text'): ?>
<tr class="heading">
<td colspan="2" style="background-color: transparent;">
<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><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>
<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>
</td>
</tr>
<?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;"';?>>
<td width="50%" class="adm-detail-content-cell-l" name="<?php echo $orderProp['ID']; ?>">
<?php echo $orderProp['NAME']; ?>
<tr <?= ($countProps > 3) ? 'class="address-detail-' . $bitrixOrderType['ID'] . '"' : ''?>
<?= (($countProps > 3) && (count($defaultOrderProps[$bitrixOrderType['ID']]) < 6))
? 'style="display:none;"'
: ''
?>
>
<td width="50%" class="adm-detail-content-cell-l" name="<?= $orderProp['ID']?>">
<?= $orderProp['NAME']; ?>
</td>
<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>
<?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'; ?>>
<?php echo $arProp['NAME']; ?>
<option value="<?= $arProp['CODE']?>"
<?= ($defaultOrderProps[$bitrixOrderType['ID']][$orderProp['ID']] === $arProp['CODE'])
? 'selected'
: '' ?>
>
<?= $arProp['NAME']?>
</option>
<?php endforeach; ?>
</select>
@ -178,7 +211,7 @@ else{
<tr class="heading custom-detail-title">
<td colspan="2" style="background-color: transparent;">
<b>
<?=GetMessage("ORDER_CUSTOM"); ?>
<?=GetMessage('ORDER_CUSTOM'); ?>
</b>
</td>
</tr>
@ -188,55 +221,65 @@ else{
<?=$customFields['NAME']; ?>
</td>
<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>
<?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'; ?>>
<?=$arProp['NAME']; ?>
<option value="<?=$arProp['CODE']?>"
<?= (isset($arResult['CUSTOM_FIELDS'][$bitrixOrderType['ID']][$customFields['ID']])
&& $arResult['CUSTOM_FIELDS'][$bitrixOrderType['ID']][$customFields['ID']]
=== $arProp['CODE'])
? 'selected'
: ''
?>>
<?=$arProp['NAME']?>
</option>
<?endforeach;?>
<?php endforeach;?>
</select>
</td>
</tr>
<?endforeach;?>
<?endif;?>
<?php endforeach;?>
<?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;">
<b>
<?php echo GetMessage("ORDER_LEGAL_INFO"); ?>
<?= GetMessage('ORDER_LEGAL_INFO'); ?>
</b>
</td>
</tr>
<?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">
<?php echo $legalDetails['NAME']; ?>
<?= $legalDetails['NAME']; ?>
</td>
<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>
<?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'; ?>>
<?php echo $arProp['NAME']; ?>
<option value="<?= $arProp['CODE']?>"
<?= (isset($arResult['LEGAL_DETAILS'][$bitrixOrderType['ID']][$legalDetails['ID']])
&& $arResult['LEGAL_DETAILS'][$bitrixOrderType['ID']][$legalDetails['ID']] === $arProp['CODE'])
? 'selected' : ''
?>
>
<?= $arProp['NAME']?>
</option>
<?php endforeach; ?>
</select>
</td>
</tr>
<?php endforeach; ?>
<?php endforeach; ?>
</tbody>
</table>
<br />
<div style="padding: 1px 13px 2px; height:28px;">
<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 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>
</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
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);
@ -211,7 +211,8 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
$api_key = htmlspecialchars(trim($_POST['api_key']));
//bitrix site list
$siteListArr = array();
$siteListArr = [];
foreach ($arResult['arSites'] as $arSites) {
if (count($arResult['arSites']) > 1) {
if ($_POST['sites-id-' . $arSites['LID']]) {