diff --git a/CHANGELOG.md b/CHANGELOG.md index 7fdea7f1..0929c39a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 2023-10-10 v.6.4.7 +- Изменена логика передачи адреса доставки в заказе из Bitrix в CRM + ## 2023-09-07 v.6.4.6 - Исправлена передача ФИО покупателя в заказе @@ -8,7 +11,7 @@ - Исправлены ошибки при работе с программой лояльности ## 2023-08-29 v.6.4.3 -- Добавлена валидация валют при установке и настройке модуля +- Добавлена валидация валют при настройке модуля ## 2023-08-23 v.6.4.2 - Исправлена ошибка создания заказов для корпоративных клиентов при использовании функционала брошенных корзин @@ -29,7 +32,7 @@ - Исправлена передача брошенных корзин ## 2023-07-04 v.6.3.17 -- Добавлен функционал передачи примененного купона в заказе Битрикс в пользовательское поле заказа CRM +- Добавлен функционал передачи примененного купона в заказе Bitrix в пользовательское поле заказа CRM ## 2023-06-30 v.6.3.16 - Добавлена передача НДС товаров diff --git a/intaro.retailcrm/classes/general/RCrmActions.php b/intaro.retailcrm/classes/general/RCrmActions.php index 8157598d..44ca24c7 100644 --- a/intaro.retailcrm/classes/general/RCrmActions.php +++ b/intaro.retailcrm/classes/general/RCrmActions.php @@ -321,6 +321,7 @@ class RCrmActions /** @var \Intaro\RetailCrm\Service\Utils $utils */ $utils = ServiceLocator::getOrCreate(\Intaro\RetailCrm\Service\Utils::class); + return $utils->fromUTF8($str); } diff --git a/intaro.retailcrm/classes/general/order/RetailCrmOrder_v5.php b/intaro.retailcrm/classes/general/order/RetailCrmOrder_v5.php index d9e42b58..25bb1c23 100644 --- a/intaro.retailcrm/classes/general/order/RetailCrmOrder_v5.php +++ b/intaro.retailcrm/classes/general/order/RetailCrmOrder_v5.php @@ -15,7 +15,6 @@ use RetailCrm\ApiClient; use Intaro\RetailCrm\Service\ManagerService; use Intaro\RetailCrm\Service\LoyaltyAccountService; use RetailCrm\Response\ApiResponse; -use \Bitrix\Sale\Location\Name\LocationTable as LocationTableName; use Intaro\RetailCrm\Component\ConfigProvider; use Intaro\RetailCrm\Model\Api\Response\OrdersCreateResponse; @@ -121,7 +120,11 @@ class RetailCrmOrder $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) { if (!empty($arParams['optionsLegalDetails']) && is_array($arParams['optionsLegalDetails'][$arOrder['PERSON_TYPE_ID']]) @@ -147,44 +150,39 @@ class RetailCrmOrder $order[$search] = $prop['VALUE'][0];//phone, email } - } else {//address - 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(); - $countrys = []; - - if (file_exists($server . '/bitrix/modules/intaro.retailcrm/classes/general/config/country.xml')) { - $countrysFile = simplexml_load_file($server . '/bitrix/modules/intaro.retailcrm/classes/general/config/country.xml'); - foreach ($countrysFile->country as $country) { - $countrys[RCrmActions::fromJSON((string) $country->name)] = (string) $country->alpha; - } - } - - $location = LocationTableName::getList([ - 'filter' => ['=LOCATION_ID' => $arLoc['CITY_ID'], 'LANGUAGE_ID' => 'ru'] - ])->fetch(); - - if (count($countrys) > 0) { - $countryOrder = LocationTableName::getList([ - '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])) { - $order['delivery']['address'][$search] = $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(); + $deliveryLocation = CSaleLocation::GetByID($arLoc['ID']); + + $deliveryAddress['city'] = $deliveryLocation['CITY_NAME'] ?? ''; + $deliveryAddress['region'] = $deliveryLocation['REGION_NAME'] ?? ''; + $deliveryAddress['countryIso'] = $countryList['COUNTRY_NAME'] ?? ''; + } } - //deliverys + // Clear empty fields + $deliveryAddress = array_filter($deliveryAddress); + + if (!empty($deliveryAddress)) { + $order['delivery']['address'] = $deliveryAddress; + } + + //Deliverys if (array_key_exists($arOrder['DELIVERYS'][0]['id'], $arParams['optionsDelivTypes'])) { $order['delivery']['code'] = $arParams['optionsDelivTypes'][$arOrder['DELIVERYS'][0]['id']]; diff --git a/intaro.retailcrm/classes/general/services/RetailCrmService.php b/intaro.retailcrm/classes/general/services/RetailCrmService.php index 58081426..2978eb6f 100644 --- a/intaro.retailcrm/classes/general/services/RetailCrmService.php +++ b/intaro.retailcrm/classes/general/services/RetailCrmService.php @@ -1,5 +1,7 @@ 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; + } } diff --git a/intaro.retailcrm/install/version.php b/intaro.retailcrm/install/version.php index 33c9f4b0..7c5315c8 100644 --- a/intaro.retailcrm/install/version.php +++ b/intaro.retailcrm/install/version.php @@ -1,6 +1,6 @@ '6.4.6', - 'VERSION_DATE' => '2023-09-07 16:30:00' + 'VERSION' => '6.4.7', + 'VERSION_DATE' => '2023-10-10 18:00:00' ]; diff --git a/tests/classes/general/order/RetailCrmOrder_v5Test.php b/tests/classes/general/order/RetailCrmOrder_v5Test.php index 78d65795..eb76aeb4 100644 --- a/tests/classes/general/order/RetailCrmOrder_v5Test.php +++ b/tests/classes/general/order/RetailCrmOrder_v5Test.php @@ -154,6 +154,7 @@ class RetailCrmOrder_v5Test extends BitrixTestCase { $rcrmActions = Mockery::mock('alias:' . RCrmActions::class); $rcrmActions->shouldReceive('apiMethod')->withAnyArgs()->andReturn(true); + $rcrmActions->shouldReceive('fromJSON')->withAnyArgs()->andReturn(''); $result = RetailCrmOrder::uploadOrders();