1
0
mirror of synced 2024-11-21 21:06:09 +03:00

ref #93511 Исправление передачи адреса доставки (#332)

This commit is contained in:
Kocmonavtik 2024-01-09 10:44:17 +03:00 committed by GitHub
parent 46570494a3
commit a66ec1d663
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 312 additions and 110 deletions

View File

@ -1,5 +1,8 @@
## 2023-12-29 v.6.5.4
- Исправлена передача адреса доставки
## 2023-12-27 v.6.5.3
- Исправлен баг с двойной сериализацией при получении списка пользователей
- Исправлена ошибка с двойной сериализацией при получении списка пользователей
## 2023-12-21 v.6.5.2
- Добавлена функциональность, позволяющая выгружать из CRM в Bitrix заказы с определенным способом оформления

View File

@ -136,7 +136,31 @@ class RCrmActions
public static function OrderPropsList()
{
$bitrixPropsList = [];
$arPropsAll = OrderPropsTable::getList(['select' => ['*'], 'filter' => ['CODE' => '_%']]);
$arPropsAll = OrderPropsTable::getList([
'select' => ['*'],
'filter' => [
['CODE' => '_%'],
['!=TYPE' => 'LOCATION']
]
]);
while ($prop = $arPropsAll->Fetch()) {
$bitrixPropsList[$prop['PERSON_TYPE_ID']][] = $prop;
}
return $bitrixPropsList;
}
public static function getLocationProps()
{
$bitrixPropsList = [];
$arPropsAll = OrderPropsTable::getList([
'select' => ['*'],
'filter' => [
['CODE' => '_%'],
['TYPE' => 'LOCATION']
]
]);
while ($prop = $arPropsAll->Fetch()) {
$bitrixPropsList[$prop['PERSON_TYPE_ID']][] = $prop;

View File

@ -792,52 +792,87 @@ class RetailCrmHistory
} else {
self::setProp($somePropValue, RCrmActions::fromJSON($order[$key]));
}
} elseif (is_array($order['delivery']['address']) && array_key_exists($key, $order['delivery']['address'])) {
if ($propsKey[$orderProp]['TYPE'] == 'LOCATION') {
} elseif ($propsKey[$orderProp]['TYPE'] === 'LOCATION'
&& (
isset($order['delivery']['address']['city'])
|| isset($order['delivery']['address']['region'])
)
) {
try {
$parameters = [
'filter' => [
'NAME.LANGUAGE_ID' => 'ru'
],
'limit' => 1,
'select' => ['*']
];
if (!empty($order['delivery']['address'][$key])) {
$parameters['filter']['NAME.LANGUAGE_ID'] = 'ru';
$parameters['limit'] = 1;
$parameters['select'] = ['*'];
$somePropValue = $propertyCollection
->getItemByOrderPropertyId($propsKey[$orderProp]['ID'])
;
// if address have a dot
$loc = explode('.', $order['delivery']['address'][$key]);
if (count($loc) == 1) {
$codeLocation = $somePropValue->getValue();
$subParameters = $parameters;
$subParameters['filter']['=CODE'] = RCrmActions::fromJSON($codeLocation);
$subLocation = Finder::find($subParameters)->fetch();
if (!isset($order['delivery']['address']['city'])) {
$parameters['filter']['=ID'] = RCrmActions::fromJSON($subLocation['CITY_ID']);
} else { // В системе город пишется с префиксом (г. Москва)
$loc = explode('.', $order['delivery']['address']['city']);
if (count($loc) === 1) {
$parameters['filter']['=NAME.NAME'] = RCrmActions::fromJSON(trim($loc[0]));
} else {
$parameters['filter']['=NAME.NAME'] = RCrmActions::fromJSON(trim($loc[1]));
}
}
$location = Finder::find(
$parameters
)->fetch();
if (!isset($order['delivery']['address']['region'])) {
$parameters['filter']['=PARENT.ID'] = RCrmActions::fromJSON($subLocation['REGION_ID']);
} else {
$parameters['filter']['PARENT.NAME.NAME'] = RCrmActions::fromJSON(trim($order['delivery']['address']['region']));
}
$location = Finder::find($parameters)->fetch();
//При существовании района в локации, фильтр по региону изменяется
if (empty($location)) {
if (!isset($order['delivery']['address']['region'])) {
$parameters['filter']['=PARENT.PARENT.ID'] = RCrmActions::fromJSON($subLocation['REGION_ID']);
unset($parameters['filter']['=PARENT.ID']);
} else {
$parameters['filter']['PARENT.PARENT.NAME.NAME'] = RCrmActions::fromJSON(trim($order['delivery']['address']['region']));
unset($parameters['filter']['PARENT.NAME.NAME']);
}
$location = Finder::find($parameters)->fetch();
}
if (!empty($location)) {
$somePropValue = $propertyCollection
->getItemByOrderPropertyId($propsKey[$orderProp]['ID'])
;
try {
self::setProp($somePropValue, $location['CODE']);
} catch (ArgumentException $argumentException) {
} else {
if (isset($order['externalId'])) {
$message = 'ExternalId: ' . $order['externalId'];
} else {
$message = 'CRM id: ' . $order['id'];
}
RCrmActions::eventLog(
'RetailCrmHistory::orderHistory',
'RetailCrmHistory::setProp',
'Location parameter is incorrect in order number=' . $order['number']
'Ошибка обновления локации в заказе. ' . $message
);
}
} else {
} catch (\Exception $exception) {
RCrmActions::eventLog(
'RetailCrmHistory::orderHistory',
'RetailCrmHistory::setProp',
sprintf(
'Error location. %s is empty in order number=%s',
$order['delivery']['address'][$key],
$order['number']
)
'Error when updating a location. Order: '
. $order['number'] . ' message:' . $exception->getMessage()
);
}
} else {
} elseif (is_array($order['delivery']['address']) && array_key_exists($key, $order['delivery']['address'])) {
$somePropValue = $propertyCollection
->getItemByOrderPropertyId($propsKey[$orderProp]['ID']);
self::setProp(
@ -847,7 +882,6 @@ class RetailCrmHistory
}
}
}
}
if (isset($order['company']['id'])) {
if (!empty($order['company']['name'])) {

View File

@ -122,7 +122,6 @@ class RetailCrmOrder
$order['contragent']['contragentType'] = $arParams['optionsContragentType'][$arOrder['PERSON_TYPE_ID']];
$countryList = BitrixOrderService::getCountryList();
$deliveryAddress = ['city' => '', 'text' => '', 'index' => '', 'region' => '', 'countryIso' => ''];
$isSendCustomFields = 'N';
if (method_exists(RCrmActions::class, 'convertCmsFieldToCrmValue')) {
@ -156,33 +155,34 @@ class RetailCrmOrder
$order[$search] = $prop['VALUE'][0];//phone, email
}
}
}
if ($prop['CODE'] === 'ZIP' && !empty($prop['VALUE'][0])) {
$deliveryAddress['index'] = $prop['VALUE'][0];
}
if ($prop['CODE'] === 'CITY' && $deliveryAddress['city'] === '' && !empty($prop['VALUE'][0])) {
$deliveryAddress['city'] = $prop['VALUE'][0];
}
if ($prop['CODE'] === 'ADDRESS' && !empty($prop['VALUE'][0])) {
$deliveryAddress['text'] = $prop['VALUE'][0];
}
if ($prop['TYPE'] === 'LOCATION' && isset($prop['VALUE'][0]) && !empty($prop['VALUE'][0])) {
} else {
if ($prop['TYPE'] === 'LOCATION' && isset($prop['VALUE'][0]) && $prop['VALUE'][0] != '') {
$arLoc = LocationTable::getByCode($prop['VALUE'][0])->fetch();
if ($arLoc) {
$deliveryLocation = CSaleLocation::GetByID($arLoc['ID']);
$order['delivery']['address']['region'] = $deliveryLocation['REGION_NAME'] ?? '';
$city = $deliveryLocation['CITY_NAME'] ?? null;
$deliveryAddress['city'] = $deliveryLocation['CITY_NAME'] ?? '';
$deliveryAddress['region'] = $deliveryLocation['REGION_NAME'] ?? '';
$deliveryAddress['countryIso'] = $countryList['COUNTRY_NAME'] ?? '';
if (count($countryList) > 0 && isset($countryList[$deliveryLocation['COUNTRY_NAME']])) {
$order['countryIso'] = $countryList[$deliveryLocation['COUNTRY_NAME']];
}
}
// Удаляем пустые значения
$deliveryAddress = array_filter($deliveryAddress);
$prop['VALUE'][0] = null;
}
if (!empty($prop['VALUE'][0])) {
$order['delivery']['address'][$search] = $prop['VALUE'][0];
}
}
}
}
//Перезапись города при его наличии в свойстве типа LOCATION
if (isset($city)) {
$order['delivery']['address']['city'] = $city;
}
// Пункт самовывоза
$pickupPointAddress = '';
@ -193,8 +193,6 @@ class RetailCrmOrder
if ($pickupPointAddress !== '') {
$order['delivery']['address']['text'] = $pickupPointAddress;
} elseif(!empty($deliveryAddress)) {
$order['delivery']['address'] = $deliveryAddress;
}
//Deliverys

View File

@ -1 +1 @@
- Исправлен баг с двойной сериализацией при получении списка пользователей
- Исправлена передача адреса доставки

View File

@ -658,6 +658,7 @@ class intaro_retailcrm extends CModule
//new page
//form orderProps
$arResult['arProp'] = RCrmActions::OrderPropsList();
$arResult['locationProp'] = RCrmActions::getLocationProps();
$request = Application::getInstance()->getContext()->getRequest();
@ -803,8 +804,11 @@ class intaro_retailcrm extends CModule
$orderTypesList = RCrmActions::OrderTypesList(RCrmActions::getSitesList());
$orderTypesArr = [];
$addressDetailOptions = [];
foreach ($orderTypesList as $orderType) {
$orderTypesArr[$orderType['ID']] = htmlspecialchars(trim($_POST['order-type-' . $orderType['ID']]));
$addressDetailOptions[$orderType['ID']] = $_POST['address-detail-' . $orderType['ID']];
}
$orderPropsArr = [];
@ -846,6 +850,7 @@ class intaro_retailcrm extends CModule
$contragentTypeArr[$orderType['ID']] = htmlspecialchars(trim($_POST['contragent-type-' . $orderType['ID']]));
}
COption::SetOptionString($this->MODULE_ID, $this->CRM_ADDRESS_OPTIONS, serialize($addressDetailOptions));
COption::SetOptionString($this->MODULE_ID, $this->CRM_ORDER_PROPS, serialize(RCrmActions::clearArr($orderPropsArr)));
COption::SetOptionString($this->MODULE_ID, $this->CRM_CUSTOM_FIELDS, serialize(RCrmActions::clearArr($customFieldsArr)));
COption::SetOptionString($this->MODULE_ID, $this->CRM_LEGAL_DETAILS, serialize(RCrmActions::clearArr($legalDetailsArr)));

View File

@ -32,6 +32,7 @@ if (count($arResult['arSites']) === 1) {
if (!isset($arResult['bitrixOrderTypesList'])) {
$arResult['bitrixOrderTypesList'] = RCrmActions::OrderTypesList($arResult['arSites']);
$arResult['arProp'] = RCrmActions::OrderPropsList();
$arResult['locationProp'] = RCrmActions::getLocationProps();
$arResult['ORDER_PROPS'] = unserialize(COption::GetOptionString($MODULE_ID, $CRM_ORDER_PROPS, 0));
}
@ -80,9 +81,43 @@ if (isset($arResult['ORDER_PROPS'])) {
<?php CJSCore::Init(['jquery']);?>
<script type="text/javascript">
function updateAddressList()
{
splitName = $(this).attr('name').split('-');
orderType = splitName[2];
if (parseInt($(this).val()) === 1) {
let locationElement = document.getElementById('locationElement-' + orderType);
let replacedSelect = document.getElementsByName('order-prop-text-' + orderType);
let replacedElement = replacedSelect[0].parentNode.parentNode;
let addedLocation = locationElement.cloneNode(true);
addedLocation.querySelector(`select`).setAttribute("name", 'order-prop-text-' + orderType);
addedLocation.removeAttribute("hidden");
addedLocation.removeAttribute("id");
replacedElement.replaceWith(addedLocation);
$('tr.address-detail-' + orderType).show('slow');
} else if (parseInt($(this).val()) === 0) {
let locationElement = document.getElementById('textAddressElement-' + orderType);
let replacedSelect = document.getElementsByName('order-prop-text-' + orderType);
let replacedElement = replacedSelect[0].parentNode.parentNode;
let addedLocation = locationElement.cloneNode(true);
addedLocation.querySelector(`select`).setAttribute("name", 'order-prop-text-' + orderType);
addedLocation.removeAttribute("hidden");
addedLocation.removeAttribute("id");
replacedElement.replaceWith(addedLocation);
$('tr.address-detail-' + orderType).hide('slow');
}
}
$(document).ready(function() {
const individual = $("[name='contragent-type-1']").val();
const legalEntity = $("[name='contragent-type-2']").val();
$('input:checked[name^="address-detail-"]').each(updateAddressList);
if (legalEntity !== 'individual') {
$('tr.legal-detail-2').each(function(){
@ -102,15 +137,7 @@ if (isset($arResult['ORDER_PROPS'])) {
});
}
$('input.addr').change(function(){
const splitName = $(this).attr('name').split('-');
const orderType = splitName[2];
if(parseInt($(this).val()) === 1)
$('tr.address-detail-' + orderType).show('slow');
else if(parseInt($(this).val()) === 0)
$('tr.address-detail-' + orderType).hide('slow');
});
$('input[name^="address-detail-"]').change(updateAddressList);
$('tr.contragent-type select').change(function(){
const splitName = $(this).attr('name').split('-');
@ -223,6 +250,42 @@ if (isset($arResult['ORDER_PROPS'])) {
</tr>
<?php $countProps++; endforeach; ?>
<tr id="<?php echo 'locationElement-' . $bitrixOrderType['ID']; ?>" hidden="hidden">
<td class="adm-detail-content-cell-l" width="50%" name="text"><?php echo GetMessage('LOCATION_LABEL'); ?></td>
<td class="adm-detail-content-cell-r" width="50%">
<select class="typeselect">
<option value=""></option>
<?php foreach ($arResult['locationProp'][$bitrixOrderType['ID']] as $arProp): ?>
<option value="<?php echo $arProp['CODE']; ?>"
<?php if ($defaultOrderProps[$bitrixOrderType['ID']]['text'] === $arProp['CODE']) {
echo 'selected';
} ?>
>
<?php echo $arProp['NAME'];?>
</option>
<?php endforeach;?>
</select>
</td>
</tr>
<tr id="<?php echo 'textAddressElement-' . $bitrixOrderType['ID']; ?>" hidden="hidden">
<td class="adm-detail-content-cell-l" width="50%" name="text"><?php echo GetMessage('TEXT_ADDRESS_LABEL'); ?></td>
<td class="adm-detail-content-cell-r" width="50%">
<select class="typeselect">
<option value=""></option>
<?php foreach ($arResult['arProp'][$bitrixOrderType['ID']] as $arProp): ?>
<option value="<?php echo $arProp['CODE']; ?>"
<?php if ($defaultOrderProps[$bitrixOrderType['ID']]['text'] === $arProp['CODE']) {
echo 'selected';
} ?>
>
<?php echo $arProp['NAME']; ?>
</option>
<?php endforeach; ?>
</select>
</td>
</tr>
<?if (isset($arResult['customFields']) && count($arResult['customFields']) > 0):?>
<tr class="heading custom-detail-title">
<td colspan="2" style="background-color: transparent;">

View File

@ -1,6 +1,6 @@
<?php
$arModuleVersion = [
'VERSION' => '6.5.3',
'VERSION_DATE' => '2023-12-27 12:30:00'
'VERSION' => '6.5.4',
'VERSION_DATE' => '2023-12-29 15:00:00'
];

View File

@ -27,3 +27,6 @@ $MESS ['BLOCK'] = 'Block';
$MESS ['HOUSE'] = 'House';
$MESS ['ADDRESS_SHORT'] = 'Short address';
$MESS ['ADDRESS_FULL'] = 'Detailed address';
$MESS ['LOCATION_LABEL'] = 'Location';
$MESS ['TEXT_ADDRESS_LABEL'] = 'Address (line)';

View File

@ -134,3 +134,6 @@ $MESS ['NOTATION_CUSTOM_FIELDS'] = 'Before enabling this functionality, make sur
$MESS ['NOTATION_MATCHED_CUSTOM_FIELDS'] = 'For correct data exchange, the types of matched fields must be the same!';
$MESS ['ADD_LABEL'] = 'Add';
$MESS ['DELETE_MATCHED'] = 'Delete';
$MESS ['LOCATION_LABEL'] = 'Location';
$MESS ['TEXT_ADDRESS_LABEL'] = 'Address (line)';

View File

@ -28,3 +28,6 @@ $MESS ['BLOCK'] = 'Подъезд';
$MESS ['HOUSE'] = 'Строение / корпус';
$MESS ['ADDRESS_SHORT'] = 'Краткий адрес';
$MESS ['ADDRESS_FULL'] = 'Детальный адрес';
$MESS ['LOCATION_LABEL'] = 'Местоположение (LOCATION)';
$MESS ['TEXT_ADDRESS_LABEL'] = 'Адрес (строкой)';

View File

@ -193,3 +193,6 @@ $MESS ['NOTATION_CUSTOM_FIELDS'] = 'Перед подключением данн
$MESS ['NOTATION_MATCHED_CUSTOM_FIELDS'] = 'Для корректного обмена данными типы сопоставляемых полей должны быть одинаковыми!';
$MESS ['ADD_LABEL'] = 'Добавить';
$MESS ['DELETE_MATCHED'] = 'Удалить';
$MESS ['LOCATION_LABEL'] = 'Местоположение (LOCATION)';
$MESS ['TEXT_ADDRESS_LABEL'] = 'Адрес (строкой)';

View File

@ -1125,6 +1125,7 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) {
//bitrix orderPropsList
$arResult['arProp'] = RCrmActions::OrderPropsList();
$arResult['locationProp'] = RCrmActions::getLocationProps();
$arResult['bitrixIblocksExportList'] = RCrmActions::IblocksExportList();
$arResult['bitrixStoresExportList'] = RCrmActions::StoresExportList();
@ -1540,16 +1541,42 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) {
}
}
$(document).ready(function() {
$('input.addr').change(function() {
function updateAddressList()
{
splitName = $(this).attr('name').split('-');
orderType = splitName[2];
if (parseInt($(this).val()) === 1)
if (parseInt($(this).val()) === 1) {
let locationElement = document.getElementById('locationElement-' + orderType);
let replacedSelect = document.getElementsByName('order-prop-text-' + orderType);
let replacedElement = replacedSelect[0].parentNode.parentNode;
let addedLocation = locationElement.cloneNode(true);
addedLocation.querySelector(`select`).setAttribute("name", 'order-prop-text-' + orderType);
addedLocation.removeAttribute("hidden");
addedLocation.removeAttribute("id");
replacedElement.replaceWith(addedLocation);
$('tr.address-detail-' + orderType).show('slow');
else if (parseInt($(this).val()) === 0)
} else if (parseInt($(this).val()) === 0) {
let locationElement = document.getElementById('textAddressElement-' + orderType);
let replacedSelect = document.getElementsByName('order-prop-text-' + orderType);
let replacedElement = replacedSelect[0].parentNode.parentNode;
let addedLocation = locationElement.cloneNode(true);
addedLocation.querySelector(`select`).setAttribute("name", 'order-prop-text-' + orderType);
addedLocation.removeAttribute("hidden");
addedLocation.removeAttribute("id");
replacedElement.replaceWith(addedLocation);
$('tr.address-detail-' + orderType).hide('slow');
});
}
}
$(document).ready(function() {
$('input[name^="address-detail-"]').change(updateAddressList);
$('input:checked[name^="address-detail-"]').each(updateAddressList);
$('tr.contragent-type select').change(function() {
splitName = $(this).attr('name').split('-');
@ -2087,6 +2114,41 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) {
</tr>
<? endforeach; ?>
<? endif; ?>
<tr id="<?php echo 'locationElement-' . $bitrixOrderType['ID']; ?>" hidden="hidden">
<td class="adm-detail-content-cell-l" width="50%" name="text"><?php echo GetMessage('LOCATION_LABEL'); ?></td>
<td class="adm-detail-content-cell-r" width="50%">
<select class="typeselect">
<option value=""></option>
<?php foreach ($arResult['locationProp'][$bitrixOrderType['ID']] as $arProp): ?>
<option value="<?php echo $arProp['CODE']; ?>"
<?php if ($optionsOrderProps[$bitrixOrderType['ID']]['text'] === $arProp['CODE']) {
echo 'selected';
} ?>
>
<?php echo $arProp['NAME'];?>
</option>
<?php endforeach;?>
</select>
</td>
</tr>
<tr id="<?php echo 'textAddressElement-' . $bitrixOrderType['ID']; ?>" hidden="hidden">
<td class="adm-detail-content-cell-l" width="50%" name="text"><?php echo GetMessage('TEXT_ADDRESS_LABEL'); ?></td>
<td class="adm-detail-content-cell-r" width="50%">
<select class="typeselect">
<option value=""></option>
<?php foreach ($arResult['arProp'][$bitrixOrderType['ID']] as $arProp): ?>
<option value="<?php echo $arProp['CODE']; ?>"
<?php if ($optionsOrderProps[$bitrixOrderType['ID']]['text'] === $arProp['CODE']) {
echo 'selected';
} ?>
>
<?php echo $arProp['NAME']; ?>
</option>
<?php endforeach; ?>
</select>
</td>
</tr>
<tr class="heading legal-detail-title-<?php echo $bitrixOrderType['ID']; ?>" <?php if (is_array($optionsLegalDetails[$bitrixOrderType['ID']]) && count($optionsLegalDetails[$bitrixOrderType['ID']]) < 1) {
echo 'style="display:none"';
} ?>>
@ -2120,6 +2182,7 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) {
</tr>
<?php endforeach; ?>
<?php endforeach; ?>
<?php $tabControl->BeginNextTab(); ?>
<?php
//loyalty program options