Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 2026-07-01 v6.8.4
- Добавлена поддержка мультисайтовости для типа контрагента

## 2026-06-30 v6.8.3
- Исправлено присвоение PERSON_TYPE_ID для $newOrder

Expand Down
8 changes: 4 additions & 4 deletions intaro.retailcrm/classes/general/events/RetailCrmEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public static function orderSave($event)
$optionsSitesList = RetailcrmConfigProvider::getSitesList();
$optionsOrderProps = RetailcrmConfigProvider::getOrderProps();
$optionsLegalDetails = RetailcrmConfigProvider::getLegalDetails();
$optionsContragentType = RetailcrmConfigProvider::getContragentTypes();
$optionsContragentType = RetailcrmConfigProvider::getContragentTypesBySite();
$optionsCustomFields = RetailcrmConfigProvider::getCustomFields();

//corp cliente swich
Expand Down Expand Up @@ -224,7 +224,7 @@ public static function orderSave($event)

//TODO эта управляющая конструкция по функционалу дублирует RetailCrmOrder::createCustomerForOrder.
// Необходимо устранить дублирование, вынеся логику в обособленный класс-сервис
if ('Y' === $optionCorpClient && in_array($optionsContragentType[$arOrder['PERSON_TYPE_ID']], ['legal-entity', 'enterpreneur'])) {
if ('Y' === $optionCorpClient && in_array($optionsContragentType[$arOrder['LID']][$arOrder['PERSON_TYPE_ID']] ?? null, ['legal-entity', 'enterpreneur'])) {
//corparate cliente
$nickName = '';
$address = '';
Expand Down Expand Up @@ -325,7 +325,7 @@ function ($carry, $item) use ($nickName) {
$resultUserCorp = RetailCrmCorporateClient::clientSend(
$arOrder,
$api,
$optionsContragentType[$arOrder['PERSON_TYPE_ID']],
$optionsContragentType[$arOrder['LID']][$arOrder['PERSON_TYPE_ID']] ?? null,
true,
false,
$site
Expand Down Expand Up @@ -430,7 +430,7 @@ function ($carry, $item) use ($nickName) {
$resultUser = RetailCrmUser::customerSend(
$arUser,
$api,
$optionsContragentType[$arOrder['PERSON_TYPE_ID']],
$optionsContragentType[$arOrder['LID']][$arOrder['PERSON_TYPE_ID']] ?? null,
true,
$site
);
Expand Down
11 changes: 10 additions & 1 deletion intaro.retailcrm/classes/general/history/RetailCrmHistory_v5.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@
use Bitrix\Main\ArgumentException;
use Bitrix\Main\ArgumentNullException;
use Bitrix\Main\ArgumentOutOfRangeException;
use Bitrix\Main\ArgumentTypeException;
use Bitrix\Main\Context;
use Bitrix\Main\NotImplementedException;
use Bitrix\Main\NotSupportedException;
use Bitrix\Main\ObjectException;
use Bitrix\Main\ObjectNotFoundException;
use Bitrix\Main\ObjectPropertyException;
use Bitrix\Main\SystemException;
use Bitrix\Sale\Basket;
use Bitrix\Sale\Delivery\Services\EmptyDeliveryService;
Expand Down Expand Up @@ -295,7 +300,7 @@ public static function orderHistory(): bool
$optionsOrderNumbers = RetailcrmConfigProvider::getOrderNumbers();
$optionsCanselOrder = RetailcrmConfigProvider::getCancellableOrderPaymentStatuses();
$currency = RetailcrmConfigProvider::getCurrencyOrDefault();
$contragentTypes = array_flip(RetailcrmConfigProvider::getContragentTypes());
$contragentTypesBySite = RetailcrmConfigProvider::getContragentTypesBySite();
$shipmentDeducted = RetailcrmConfigProvider::getShipmentDeducted();

$optionsPayment = [
Expand Down Expand Up @@ -411,6 +416,8 @@ public static function orderHistory(): bool
continue;
}

$contragentTypes = array_flip($contragentTypesBySite[$site] ?? []);

if (isset($order['customer']['externalId']) && !is_numeric($order['customer']['externalId'])) {
unset($order['customer']['externalId']);
}
Expand Down Expand Up @@ -666,6 +673,8 @@ public static function orderHistory(): bool
continue;
}

$contragentTypes = array_flip($contragentTypesBySite[$site] ?? []);

self::setManager($newOrder, $order);

//delivery
Expand Down
12 changes: 6 additions & 6 deletions intaro.retailcrm/classes/general/order/RetailCrmOrder_v5.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public static function orderSend(
$order['customer']['browserId'] = $_COOKIE['_rc'];
}

$order['contragent']['contragentType'] = $arParams['optionsContragentType'][$arOrder['PERSON_TYPE_ID']];
$order['contragent']['contragentType'] = $arParams['optionsContragentType'][$arOrder['LID']][$arOrder['PERSON_TYPE_ID']] ?? null;

$countryList = BitrixOrderService::getCountryList();
$isSendCustomFields = 'N';
Expand Down Expand Up @@ -615,7 +615,7 @@ public static function uploadOrders(int $pSize = 50, bool $failed = false, array
$optionsPayment = RetailcrmConfigProvider::getPayment();
$optionsOrderProps = RetailcrmConfigProvider::getOrderProps();
$optionsLegalDetails = RetailcrmConfigProvider::getLegalDetails();
$optionsContragentType = RetailcrmConfigProvider::getContragentTypes();
$optionsContragentType = RetailcrmConfigProvider::getContragentTypesBySite();
$optionsCustomFields = RetailcrmConfigProvider::getCustomFields();

$api = new ApiClient(RetailcrmConfigProvider::getApiUrl(), RetailcrmConfigProvider::getApiKey());
Expand Down Expand Up @@ -772,7 +772,7 @@ public static function createCustomerForOrder(
array $order,
$site
): void {
$optionsContragentType = RetailcrmConfigProvider::getContragentTypes();
$optionsContragentType = RetailcrmConfigProvider::getContragentTypesBySite();
$user = UserTable::getById($order['USER_ID'])->fetch();

if (!$user) {
Expand All @@ -793,7 +793,7 @@ public static function createCustomerForOrder(

if (
'Y' === RetailcrmConfigProvider::getCorporateClientStatus()
&& in_array($optionsContragentType[$order['PERSON_TYPE_ID']], ['legal-entity', 'enterpreneur'])
&& in_array($optionsContragentType[$order['LID']][$order['PERSON_TYPE_ID']] ?? null, ['legal-entity', 'enterpreneur'])
) {
// TODO check if order is corporate, and if it IS - make corporate order
$arCustomer = RetailCrmUser::customerSend(
Expand All @@ -807,7 +807,7 @@ public static function createCustomerForOrder(
$arCustomerCorporate = RetailCrmCorporateClient::clientSend(
$order,
$api,
$optionsContragentType[$order['PERSON_TYPE_ID']],
$optionsContragentType[$order['LID']][$order['PERSON_TYPE_ID']] ?? null,
false,
true,
$site
Expand All @@ -824,7 +824,7 @@ public static function createCustomerForOrder(
$arCustomer = RetailCrmUser::customerSend(
$user,
$api,
$optionsContragentType[$order['PERSON_TYPE_ID']],
$optionsContragentType[$order['LID']][$order['PERSON_TYPE_ID']] ?? null,
false,
$site
);
Expand Down
2 changes: 1 addition & 1 deletion intaro.retailcrm/description.ru
Original file line number Diff line number Diff line change
@@ -1 +1 @@
- Исправлено присвоение PERSON_TYPE_ID для $newOrder
- Добавлена поддержка мультисайтовости для типа контрагента
26 changes: 22 additions & 4 deletions intaro.retailcrm/install/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,18 @@ function DoInstall()
$arResult['LEGAL_DETAILS'] = unserialize($legalDetails, ['allowed_classes' => false]);
}
if ($contragentType = COption::GetOptionString($this->OLD_MODULE_ID, Constants::CRM_CONTRAGENT_TYPE, 0)) {
$arResult['CONTRAGENT_TYPES'] = unserialize($contragentType, ['allowed_classes' => false]);
$oldContragentTypes = unserialize($contragentType, ['allowed_classes' => false]);

$arResult['CONTRAGENT_TYPES'] = [];
$arSites = RCrmActions::getSitesList();

if (is_array($oldContragentTypes)) {
foreach ($arSites as $site) {
foreach ($oldContragentTypes as $personTypeId => $contragentTypeValue) {
$arResult['CONTRAGENT_TYPES'][$site['LID']][$personTypeId] = $contragentTypeValue;
}
}
}
}

$APPLICATION->IncludeAdminFile(
Expand Down Expand Up @@ -769,14 +780,20 @@ function DoInstall()

//contragents type list
$contragentTypeArr = [];
foreach ($orderTypesList as $orderType) {
$contragentTypeArr[$orderType['ID']] = htmlspecialchars(trim($_POST['contragent-type-' . $orderType['ID']]));
$arSites = RCrmActions::getSitesList();

foreach ($arSites as $site) {
foreach ($orderTypesList as $orderType) {
$contragentTypeArr[$site['LID']][$orderType['ID']] = htmlspecialchars(
trim($_POST['contragent-type-' . $site['LID'] . '-' . $orderType['ID']])
);
}
}

COption::SetOptionString($this->MODULE_ID, Constants::CRM_ADDRESS_OPTIONS, serialize($addressDetailOptions));
COption::SetOptionString($this->MODULE_ID, Constants::CRM_ORDER_PROPS, serialize(RCrmActions::clearArr($orderPropsArr)));
COption::SetOptionString($this->MODULE_ID, Constants::CRM_LEGAL_DETAILS, serialize(RCrmActions::clearArr($legalDetailsArr)));
COption::SetOptionString($this->MODULE_ID, Constants::CRM_CONTRAGENT_TYPE, serialize(RCrmActions::clearArr($contragentTypeArr)));
COption::SetOptionString($this->MODULE_ID, Constants::CRM_CONTRAGENT_TYPE_SITE, serialize(RCrmActions::clearArr($contragentTypeArr)));

$APPLICATION->IncludeAdminFile(
GetMessage('MODULE_INSTALL_TITLE'), $this->INSTALL_PATH . '/step4.php'
Expand Down Expand Up @@ -1191,6 +1208,7 @@ public function DoUninstall()
COption::RemoveOption($this->MODULE_ID, Constants::CRM_ORDER_TYPES_ARR);
COption::RemoveOption($this->MODULE_ID, Constants::CRM_LEGAL_DETAILS);
COption::RemoveOption($this->MODULE_ID, Constants::CRM_CONTRAGENT_TYPE);
COption::RemoveOption($this->MODULE_ID, Constants::CRM_CONTRAGENT_TYPE_SITE);
COption::RemoveOption($this->MODULE_ID, Constants::CRM_SITES_LIST);
COption::RemoveOption($this->MODULE_ID, Constants::CRM_ORDER_DISCHARGE);
COption::RemoveOption($this->MODULE_ID, Constants::CRM_ORDER_FAILED_IDS);
Expand Down
84 changes: 46 additions & 38 deletions intaro.retailcrm/install/step3.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,24 @@

if (!isset($arResult['CONTRAGENT_TYPES'])) {
$arResult['CONTRAGENT_TYPES'] = unserialize(
(string) COption::GetOptionString(Constants::MODULE_ID, Constants::CRM_CONTRAGENT_TYPE, 0),
(string) COption::GetOptionString(Constants::MODULE_ID, Constants::CRM_CONTRAGENT_TYPE_SITE, 0),
['allowed_classes' => false]
);

if ($arResult['CONTRAGENT_TYPES'] === false) {
foreach ($arResult['contragentType'] as $crmContrAgentType) {
if ($crmContrAgentType['ID'] === 'individual') {
$arResult['CONTRAGENT_TYPES']['1'] = 'individual';
}
if ($arResult['CONTRAGENT_TYPES'] === false || empty($arResult['CONTRAGENT_TYPES'])) {
$arResult['CONTRAGENT_TYPES'] = [];

foreach ($arResult['arSites'] as $site) {
$arResult['CONTRAGENT_TYPES'][$site['LID']] = [];

if ($crmContrAgentType['ID'] === 'legal-entity') {
$arResult['CONTRAGENT_TYPES']['2'] = 'legal-entity';
foreach ($arResult['contragentType'] as $crmContrAgentType) {
if ($crmContrAgentType['ID'] === 'individual') {
$arResult['CONTRAGENT_TYPES'][$site['LID']]['1'] = 'individual';
}

if ($crmContrAgentType['ID'] === 'legal-entity') {
$arResult['CONTRAGENT_TYPES'][$site['LID']]['2'] = 'legal-entity';
}
}
}
}
Expand Down Expand Up @@ -122,34 +128,37 @@ function updateAddressList()
}

$(document).ready(function() {
const individual = $("[name='contragent-type-1']").val();
const legalEntity = $("[name='contragent-type-2']").val();
$('input:checked[name^="address-detail-"]').each(updateAddressList);
<?php foreach ($arResult['arSites'] as $site): ?>
const individual_<?= $site['LID'] ?> = $("[name='contragent-type-<?= $site['LID'] ?>-1']").val();
const legalEntity_<?= $site['LID'] ?> = $("[name='contragent-type-<?= $site['LID'] ?>-2']").val();

if (legalEntity !== 'individual') {
if (legalEntity_<?= $site['LID'] ?> !== 'individual') {
$('tr.legal-detail-2').each(function(){
if($(this).hasClass(legalEntity)){
if($(this).hasClass(legalEntity_<?= $site['LID'] ?>)){
$(this).show();
$('.legal-detail-title-2').show();
}
});
}

if (individual !== 'individual') {
if (individual_<?= $site['LID'] ?> !== 'individual') {
$('tr.legal-detail-1').each(function(){
if($(this).hasClass(individual)){
if($(this).hasClass(individual_<?= $site['LID'] ?>)){
$(this).show();
$('.legal-detail-title-1').show();
}
});
}
<?php endforeach; ?>

$('input[name^="address-detail-"]').change(updateAddressList);

$('input:checked[name^="address-detail-"]').each(updateAddressList);

$('tr.contragent-type select').change(function(){
const splitName = $(this).attr('name').split('-');
const contragentType = $(this).val();
const orderType = splitName[2];
const siteLid = splitName[2];
const orderType = splitName[3];
let legalDetailOrderType = $('tr.legal-detail-' + orderType);

legalDetailOrderType.hide();
Expand Down Expand Up @@ -189,27 +198,26 @@ function updateAddressList()
<tr class="heading">
<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">
<?= GetMessage('CONTRAGENT_TYPE')?>
</td>
<td width="50%" class="adm-detail-content-cell-r">
<select name="contragent-type-<?= $bitrixOrderType['ID']?>" class="typeselect">
<?php foreach ($arResult['contragentType'] as $contragentType): ?>
<option value="<?= $contragentType['ID']; ?>"
<?=
(isset($arResult['CONTRAGENT_TYPES'][$bitrixOrderType['ID']])
&& $arResult['CONTRAGENT_TYPES'][$bitrixOrderType['ID']] == $contragentType['ID']) ?
'selected'
: ''
?>
>
<?= $contragentType['NAME']?>
</option>
<?php endforeach; ?>
</select>
</td>
</tr>
<?php foreach ($arResult['arSites'] as $site): ?>
<tr class="contragent-type">
<td width="50%" class="adm-detail-content-cell-l">
<?= GetMessage('CONTRAGENT_TYPE') . ' (' . $site['NAME'] . ' [' . $site['LID'] . '])'?>
</td>
<td width="50%" class="adm-detail-content-cell-r">
<select name="contragent-type-<?= $site['LID'] . '-' . $bitrixOrderType['ID']?>" class="typeselect">
<?php foreach ($arResult['contragentType'] as $contragentType): ?>
<option value="<?= $contragentType['ID']; ?>"
<?= (isset($arResult['CONTRAGENT_TYPES'][$site['LID']][$bitrixOrderType['ID']])
&& $arResult['CONTRAGENT_TYPES'][$site['LID']][$bitrixOrderType['ID']] == $contragentType['ID']) ?
'selected' : '' ?>
>
<?= $contragentType['NAME']?>
</option>
<?php endforeach; ?>
</select>
</td>
</tr>
<?php endforeach; ?>

<?php $countProps = 0; foreach($arResult['orderProps'] as $orderProp): ?>
<?php if($orderProp['ID'] === 'text'): ?>
Expand Down
4 changes: 2 additions & 2 deletions intaro.retailcrm/install/version.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

$arModuleVersion = [
'VERSION' => '6.8.3',
'VERSION_DATE' => '2026-06-30 12:00:00'
'VERSION' => '6.8.4',
'VERSION_DATE' => '2026-07-01 12:00:00'
];
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ public function __construct()
$this->cookieExtractor = ServiceLocator::get(CookieService::class);
$this->sites = ConfigProvider::getSitesList();
$this->legalDetails = ConfigProvider::getLegalDetails();
$this->contragentTypes = ConfigProvider::getContragentTypes();
}

/**
Expand All @@ -103,12 +102,16 @@ public function build(): BuilderInterface
throw new BuilderException('Order should be provided for building corporate customer!');
}

$contragentType = ConfigProvider::getContragentTypeForPersonType($this->order->getPersonTypeId());
$contragentType = ConfigProvider::getContragentTypeForPersonType(
$this->order->getPersonTypeId(),
$this->order->getSiteId()
);

if (null === $contragentType) {
throw new BuilderException(sprintf(
'Cannot find corresponding contragent type for PERSON_TYPE_ID `%s`',
$this->order->getPersonTypeId()
'Cannot find corresponding contragent type for PERSON_TYPE_ID `%s` and site `%s`',
$this->order->getPersonTypeId(),
$this->order->getSiteId()
));
}

Expand Down Expand Up @@ -269,8 +272,13 @@ protected function buildLegalDetails(): void
}
}

if (array_key_exists($this->order->getPersonTypeId(), $this->contragentTypes)) {
$this->customer->contragent->contragentType = $this->contragentTypes[$this->order->getPersonTypeId()];
$contragentType = ConfigProvider::getContragentTypeForPersonType(
$this->order->getPersonTypeId(),
$this->order->getSiteId()
);

if (null !== $contragentType) {
$this->customer->contragent->contragentType = $contragentType;
}

if (empty($this->customer->nickName)) {
Expand Down
Loading
Loading