1
0
mirror of synced 2024-11-28 00:06:07 +03:00

ref #92205 Изменена логика передачи адреса доставки в заказе из Bitrix в CRM (#315)

This commit is contained in:
Uryvskiy Dima 2023-10-13 12:49:09 +03:00 committed by GitHub
parent 8db6531fc8
commit 7404105dec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 61 additions and 40 deletions

View File

@ -1,3 +1,6 @@
## 2023-10-10 v.6.4.7
- Изменена логика передачи адреса доставки в заказе из Bitrix в CRM
## 2023-09-07 v.6.4.6 ## 2023-09-07 v.6.4.6
- Исправлена передача ФИО покупателя в заказе - Исправлена передача ФИО покупателя в заказе
@ -8,7 +11,7 @@
- Исправлены ошибки при работе с программой лояльности - Исправлены ошибки при работе с программой лояльности
## 2023-08-29 v.6.4.3 ## 2023-08-29 v.6.4.3
- Добавлена валидация валют при установке и настройке модуля - Добавлена валидация валют при настройке модуля
## 2023-08-23 v.6.4.2 ## 2023-08-23 v.6.4.2
- Исправлена ошибка создания заказов для корпоративных клиентов при использовании функционала брошенных корзин - Исправлена ошибка создания заказов для корпоративных клиентов при использовании функционала брошенных корзин
@ -29,7 +32,7 @@
- Исправлена передача брошенных корзин - Исправлена передача брошенных корзин
## 2023-07-04 v.6.3.17 ## 2023-07-04 v.6.3.17
- Добавлен функционал передачи примененного купона в заказе Битрикс в пользовательское поле заказа CRM - Добавлен функционал передачи примененного купона в заказе Bitrix в пользовательское поле заказа CRM
## 2023-06-30 v.6.3.16 ## 2023-06-30 v.6.3.16
- Добавлена передача НДС товаров - Добавлена передача НДС товаров

View File

@ -321,6 +321,7 @@ class RCrmActions
/** @var \Intaro\RetailCrm\Service\Utils $utils */ /** @var \Intaro\RetailCrm\Service\Utils $utils */
$utils = ServiceLocator::getOrCreate(\Intaro\RetailCrm\Service\Utils::class); $utils = ServiceLocator::getOrCreate(\Intaro\RetailCrm\Service\Utils::class);
return $utils->fromUTF8($str); return $utils->fromUTF8($str);
} }

View File

@ -15,7 +15,6 @@ use RetailCrm\ApiClient;
use Intaro\RetailCrm\Service\ManagerService; use Intaro\RetailCrm\Service\ManagerService;
use Intaro\RetailCrm\Service\LoyaltyAccountService; use Intaro\RetailCrm\Service\LoyaltyAccountService;
use RetailCrm\Response\ApiResponse; use RetailCrm\Response\ApiResponse;
use \Bitrix\Sale\Location\Name\LocationTable as LocationTableName;
use Intaro\RetailCrm\Component\ConfigProvider; use Intaro\RetailCrm\Component\ConfigProvider;
use Intaro\RetailCrm\Model\Api\Response\OrdersCreateResponse; use Intaro\RetailCrm\Model\Api\Response\OrdersCreateResponse;
@ -121,7 +120,11 @@ class RetailCrmOrder
$order['contragent']['contragentType'] = $arParams['optionsContragentType'][$arOrder['PERSON_TYPE_ID']]; $order['contragent']['contragentType'] = $arParams['optionsContragentType'][$arOrder['PERSON_TYPE_ID']];
//fields
$countryList = RetailCrmService::getCountryList();
$deliveryAddress = ['city' => '', 'text' => '', 'index' => '', 'region' => '', 'countryIso' => ''];
//Order fields
foreach ($arOrder['PROPS']['properties'] as $prop) { foreach ($arOrder['PROPS']['properties'] as $prop) {
if (!empty($arParams['optionsLegalDetails']) if (!empty($arParams['optionsLegalDetails'])
&& is_array($arParams['optionsLegalDetails'][$arOrder['PERSON_TYPE_ID']]) && is_array($arParams['optionsLegalDetails'][$arOrder['PERSON_TYPE_ID']])
@ -147,44 +150,39 @@ class RetailCrmOrder
$order[$search] = $prop['VALUE'][0];//phone, email $order[$search] = $prop['VALUE'][0];//phone, email
} }
} else {//address }
if ($prop['TYPE'] === 'LOCATION' && isset($prop['VALUE'][0]) && $prop['VALUE'][0] != '') { }
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])) {
$arLoc = LocationTable::getByCode($prop['VALUE'][0])->fetch(); $arLoc = LocationTable::getByCode($prop['VALUE'][0])->fetch();
if ($arLoc) { $deliveryLocation = CSaleLocation::GetByID($arLoc['ID']);
$server = Context::getCurrent()->getServer()->getDocumentRoot();
$countrys = [];
if (file_exists($server . '/bitrix/modules/intaro.retailcrm/classes/general/config/country.xml')) { $deliveryAddress['city'] = $deliveryLocation['CITY_NAME'] ?? '';
$countrysFile = simplexml_load_file($server . '/bitrix/modules/intaro.retailcrm/classes/general/config/country.xml'); $deliveryAddress['region'] = $deliveryLocation['REGION_NAME'] ?? '';
foreach ($countrysFile->country as $country) { $deliveryAddress['countryIso'] = $countryList['COUNTRY_NAME'] ?? '';
$countrys[RCrmActions::fromJSON((string) $country->name)] = (string) $country->alpha;
} }
} }
$location = LocationTableName::getList([ // Clear empty fields
'filter' => ['=LOCATION_ID' => $arLoc['CITY_ID'], 'LANGUAGE_ID' => 'ru'] $deliveryAddress = array_filter($deliveryAddress);
])->fetch();
if (count($countrys) > 0) { if (!empty($deliveryAddress)) {
$countryOrder = LocationTableName::getList([ $order['delivery']['address'] = $deliveryAddress;
'filter' => ['=LOCATION_ID' => $arLoc['COUNTRY_ID'], 'LANGUAGE_ID' => 'ru']
])->fetch();
if(isset($countrys[$countryOrder['NAME']])){
$order['countryIso'] = $countrys[$countryOrder['NAME']];
}
}
}
$prop['VALUE'][0] = $location['NAME'];
} }
if (!empty($prop['VALUE'][0])) { //Deliverys
$order['delivery']['address'][$search] = $prop['VALUE'][0];
}
}
}
}
//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']];

View File

@ -1,5 +1,7 @@
<?php <?php
use Bitrix\Main\Context;
/** /**
* Class RetailCrmService * Class RetailCrmService
*/ */
@ -178,4 +180,20 @@ class RetailCrmService
); );
} }
} }
public static function getCountryList()
{
$server = Context::getCurrent()->getServer()->getDocumentRoot();
$countryList = [];
if (file_exists($server . '/bitrix/modules/intaro.retailcrm/classes/general/config/country.xml')) {
$countryFile = simplexml_load_file($server . '/bitrix/modules/intaro.retailcrm/classes/general/config/country.xml');
foreach ($countryFile->country as $country) {
$countryList[RCrmActions::fromJSON((string) $country->name)] = (string) $country->alpha;
}
}
return $countryList;
}
} }

View File

@ -1,6 +1,6 @@
<?php <?php
$arModuleVersion = [ $arModuleVersion = [
'VERSION' => '6.4.6', 'VERSION' => '6.4.7',
'VERSION_DATE' => '2023-09-07 16:30:00' 'VERSION_DATE' => '2023-10-10 18:00:00'
]; ];

View File

@ -154,6 +154,7 @@ class RetailCrmOrder_v5Test extends BitrixTestCase {
$rcrmActions = Mockery::mock('alias:' . RCrmActions::class); $rcrmActions = Mockery::mock('alias:' . RCrmActions::class);
$rcrmActions->shouldReceive('apiMethod')->withAnyArgs()->andReturn(true); $rcrmActions->shouldReceive('apiMethod')->withAnyArgs()->andReturn(true);
$rcrmActions->shouldReceive('fromJSON')->withAnyArgs()->andReturn('');
$result = RetailCrmOrder::uploadOrders(); $result = RetailCrmOrder::uploadOrders();