From 62b165f5dee9a95412ed6bfac15d955ecb2338ef Mon Sep 17 00:00:00 2001 From: Uryvskiy Dima Date: Thu, 21 Dec 2023 17:24:46 +0300 Subject: [PATCH] =?UTF-8?q?ref=20#93164=20=D0=9D=D0=B5=20=D0=B2=D1=8B?= =?UTF-8?q?=D0=B3=D1=80=D1=83=D0=B6=D0=B0=D1=82=D1=8C=20=D0=BD=D0=B0=20?= =?UTF-8?q?=D1=81=D0=B0=D0=B9=D1=82=201C-Bitrix=20=D0=B7=D0=B0=D0=BA=D0=B0?= =?UTF-8?q?=D0=B7=D1=8B=20=D1=81=20=D0=BE=D0=BF=D1=80=D0=B5=D0=B4=D0=B5?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=BD=D1=8B=D0=BC=20=D1=81=D0=BF=D0=BE=D1=81?= =?UTF-8?q?=D0=BE=D0=B1=D0=BE=D0=BC=20=D0=BE=D1=84=D0=BE=D1=80=D0=BC=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=20(#330)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 5 +- .../general/history/RetailCrmHistory_v5.php | 98 +++++++++++-------- intaro.retailcrm/description.ru | 2 +- intaro.retailcrm/install/index.php | 24 ++++- intaro.retailcrm/install/step2.php | 48 +++++++++ intaro.retailcrm/install/version.php | 4 +- intaro.retailcrm/lang/en/install/step2.php | 2 + intaro.retailcrm/lang/en/options.php | 2 + intaro.retailcrm/lang/ru/install/step2.php | 2 + intaro.retailcrm/lang/ru/options.php | 2 + .../lib/component/configprovider.php | 16 +++ intaro.retailcrm/lib/component/constants.php | 4 +- intaro.retailcrm/options.php | 74 +++++++++++++- 13 files changed, 229 insertions(+), 54 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7048c162..4c1f9057 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,7 @@ -## 2023-12-21 v.6.5.1 +## 2023-12-21 v.6.5.2 +- Добавлена функциональность, позволяющая выгружать из CRM в Bitrix заказы с определенным способом оформления + +## 2023-12-19 v.6.5.1 - Исправлено отображение настройки пользовательских полей ## 2023-12-18 v.6.5.0 diff --git a/intaro.retailcrm/classes/general/history/RetailCrmHistory_v5.php b/intaro.retailcrm/classes/general/history/RetailCrmHistory_v5.php index b13fe741..985f9fb5 100644 --- a/intaro.retailcrm/classes/general/history/RetailCrmHistory_v5.php +++ b/intaro.retailcrm/classes/general/history/RetailCrmHistory_v5.php @@ -34,7 +34,7 @@ class RetailCrmHistory public static $CRM_DELIVERY_TYPES_ARR = 'deliv_types_arr'; public static $CRM_PAYMENT_TYPES = 'pay_types_arr'; public static $CRM_PAYMENT_STATUSES = 'pay_statuses_arr'; - public static $CRM_PAYMENT = 'payment_arr'; //order payment Y/N + public static $CRM_PAYMENT = 'payment_arr'; public static $CRM_ORDER_LAST_ID = 'order_last_id'; public static $CRM_SITES_LIST = 'sites_list'; public static $CRM_ORDER_PROPS = 'order_props'; @@ -50,7 +50,6 @@ class RetailCrmHistory public static $CRM_CURRENCY = 'currency'; public static $CRM_DISCOUNT_ROUND = 'discount_round'; public static $CUSTOM_FIELDS_IS_ACTIVE = 'N'; - const PAGE_LIMIT = 25; public static function customerHistory() @@ -208,8 +207,8 @@ class RetailCrmHistory CUser::GetList( ($by = "ID"), ($order = "desc"), - array('ID' => $customer['externalId']), - array('FIELDS' => array('PERSONAL_PHONE', 'PERSONAL_MOBILE')) + ['ID' => $customer['externalId']], + ['FIELDS' => ['PERSONAL_PHONE', 'PERSONAL_MOBILE']] )->fetch() ); } @@ -304,7 +303,7 @@ class RetailCrmHistory /* @var OrderLoyaltyDataService $orderLoyaltyDataService */ $orderLoyaltyDataService = ServiceLocator::get(OrderLoyaltyDataService::class); - $historyFilter = array(); + $historyFilter = []; $historyStart = COption::GetOptionString(self::$MODULE_ID, self::$CRM_ORDER_HISTORY); if ($historyStart && $historyStart > 0) { @@ -381,7 +380,7 @@ class RetailCrmHistory $corporateCustomerBuilder = new CorporateCustomerBuilder(); - $corporateContact = array(); + $corporateContact = []; $orderCustomerExtId = $order['customer']['externalId'] ?? null; $corporateCustomerBuilder->setOrderCustomerExtId($orderCustomerExtId) ->setContragentTypes($contragentTypes) @@ -432,6 +431,16 @@ class RetailCrmHistory } if (!isset($order['externalId'])) { + if (ConfigProvider::useCrmOrderMethods() === 'Y') { + $orderMethods = ConfigProvider::getCrmOrderMethods(); + + // 1. Клиент активировал опцию, но не выбрал способы оформления - пропускаем все заказы. + // 2. Если способа оформления заказа нет в выбранном в настройках списке - пропускаем заказ. + if ($orderMethods === [] || !in_array($order['orderMethod'], $orderMethods, true)) { + continue; + } + } + if (empty($orderCustomerExtId)) { if (!isset($order['customer']['id']) || (RetailCrmOrder::isOrderCorporate($order) @@ -520,10 +529,10 @@ class RetailCrmHistory $api, 'customersFixExternalIds', __METHOD__, - array(array( + [[ 'id' => $order['customer']['id'], 'externalId' => $registeredUserID - ))) == false + ]]) == false ) { continue; } @@ -533,21 +542,21 @@ class RetailCrmHistory $corporateCustomerBuilder->setOrderCustomerExtId($orderCustomerExtId); } - $buyerProfileToAppend = array(); + $buyerProfileToAppend = []; if (RetailCrmOrder::isOrderCorporate($order) && !empty($order['company'])) { $buyerProfile = $corporateCustomerBuilder->getBuyerProfile()->getObjectToArray(); - $buyerProfileToAppend = OrderUserProperties::getList(array( + $buyerProfileToAppend = OrderUserProperties::getList([ "filter" => $buyerProfile - ))->fetch(); + ])->fetch(); if (empty($buyerProfileToAppend)) { $buyerProfileInstance = new CSaleOrderUserProps(); if ($buyerProfileInstance->Add($buyerProfile)) { - $buyerProfileToAppend = OrderUserProperties::getList(array( + $buyerProfileToAppend = OrderUserProperties::getList([ "filter" => $buyerProfile - ))->fetch(); + ])->fetch(); } } } @@ -634,8 +643,8 @@ class RetailCrmHistory $propsRemove = true; } else { if (isset($order['orderType']) && $order['orderType']) { - $nType = array(); - $tList = RCrmActions::OrderTypesList(array(array('LID' => $site))); + $nType = []; + $tList = RCrmActions::OrderTypesList([['LID' => $site]]); foreach ($tList as $type) { if (isset($optionsOrderTypes[$type['ID']])) { @@ -688,7 +697,7 @@ class RetailCrmHistory //props $propertyCollection = $newOrder->getPropertyCollection(); $propertyCollectionArr = $propertyCollection->getArray(); - $nProps = array(); + $nProps = []; foreach ($propertyCollectionArr['properties'] as $orderProp) { if ($orderProp['ID'][0] == 'n') { @@ -705,7 +714,7 @@ class RetailCrmHistory $nProps[] = $orderProp; } - $orderDump = array(); + $orderDump = []; $propertyCollectionArr['properties'] = $nProps; if ($propsRemove) {//delete props @@ -722,7 +731,7 @@ class RetailCrmHistory $order = $orderCrm['order']; } - $propsKey = array(); + $propsKey = []; foreach ($propertyCollectionArr['properties'] as $prop) { if ($prop['PROPS_GROUP_ID'] != 0) { @@ -746,7 +755,7 @@ class RetailCrmHistory } $fio = RCrmActions::explodeFio($fio); - $newFio = array(); + $newFio = []; if ($fio) { $newFio[] = isset($order['lastName']) @@ -789,7 +798,7 @@ class RetailCrmHistory if (!empty($order['delivery']['address'][$key])) { $parameters['filter']['NAME.LANGUAGE_ID'] = 'ru'; $parameters['limit'] = 1; - $parameters['select'] = array('*'); + $parameters['select'] = ['*']; // if address have a dot $loc = explode('.', $order['delivery']['address'][$key]); @@ -983,10 +992,10 @@ class RetailCrmHistory $api, 'customersFixExternalIds', __METHOD__, - array(array( + [[ 'id' => $response['customer']['id'], 'externalId' => $registeredUserID - )) + ]] ) == false ) { continue; @@ -1198,7 +1207,7 @@ class RetailCrmHistory $order['summ'] = $orderSumm; //payment - $newHistoryPayments = array(); + $newHistoryPayments = []; if (array_key_exists('payments', $order)) { if (!isset($orderCrm)) { @@ -1344,7 +1353,7 @@ class RetailCrmHistory ); if ($paymentId) { - PaymentTable::update($paymentId, array('XML_ID' => '')); + PaymentTable::update($paymentId, ['XML_ID' => '']); } } } @@ -1357,7 +1366,7 @@ class RetailCrmHistory $api, 'ordersFixExternalIds', __METHOD__, - array(array('id' => $order['id'], 'externalId' => $newOrder->getId()))) == false + [['id' => $order['id'], 'externalId' => $newOrder->getId()]]) == false ) { continue; } @@ -1411,12 +1420,15 @@ class RetailCrmHistory */ public static function search_array_by_value($array, $value) { - $results = array(); + $results = []; + if (is_array($array)) { - $found = array_search($value,$array); + $found = array_search($value, $array); + if ($found) { $results[] = $found; } + foreach ($array as $subarray) $results = array_merge($results, static::search_array_by_value($subarray, $value)); } @@ -1427,14 +1439,14 @@ class RetailCrmHistory { $customerHistory = self::filterHistory($customerHistory, 'customer'); $server = Context::getCurrent()->getServer()->getDocumentRoot(); - $fields = array(); + $fields = []; if (file_exists($server . '/bitrix/modules/intaro.retailcrm/classes/general/config/objects.xml')) { $objects = simplexml_load_file($server . '/bitrix/modules/intaro.retailcrm/classes/general/config/objects.xml'); foreach ($objects->fields->field as $object) { $fields[(string)$object["group"]][(string)$object["id"]] = (string)$object; } } - $customers = array(); + $customers = []; foreach ($customerHistory as $change) { $change['customer'] = self::removeEmpty($change['customer']); if ($customers[$change['customer']['id']]) { @@ -1510,7 +1522,7 @@ class RetailCrmHistory } } - $orders = array(); + $orders = []; foreach ($orderHistory as $change) { $change['order'] = self::removeEmpty($change['order']); @@ -1548,7 +1560,7 @@ class RetailCrmHistory } if ($change['order']['payments']) { - $payments = array(); + $payments = []; foreach ($change['order']['payments'] as $payment) { $payments[$payment['id']] = $payment; } @@ -1761,7 +1773,7 @@ class RetailCrmHistory $services = $service->getProfilesList(); if (!array_key_exists($serviceCode, $services)) { $serviceCode = strtoupper($serviceCode); - $serviceCode = str_replace(array('-'), "_", $serviceCode); + $serviceCode = str_replace('-', "_", $serviceCode); } } @@ -1893,7 +1905,7 @@ class RetailCrmHistory * * @return void */ - public static function paymentsUpdate($order, $paymentsCrm, &$newHistoryPayments = array()) + public static function paymentsUpdate($order, $paymentsCrm, &$newHistoryPayments = []) { $optionsPayTypes = array_flip(unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT_TYPES, 0))); $optionsPayment = array_flip(unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT, 0))); @@ -1901,7 +1913,7 @@ class RetailCrmHistory foreach ($allPaymentSystems as $allPaymentSystem) { $arPaySysmems[$allPaymentSystem['ID']] = $allPaymentSystem['NAME']; } - $paymentsList = array(); + $paymentsList = []; $paymentColl = $order->getPaymentCollection(); foreach ($paymentColl as $paymentData) { $data = $paymentData->getFields()->getValues(); @@ -1978,7 +1990,7 @@ class RetailCrmHistory public static function removeEmpty($inputArray) { - $outputArray = array(); + $outputArray = []; if (!empty($inputArray)) { foreach ($inputArray as $key => $element) { @@ -2058,18 +2070,20 @@ class RetailCrmHistory $url = CAllIBlock::ReplaceDetailUrl($elementInfo['DETAIL_PAGE_URL'], $elementInfo, false, 'E'); $catalog = CCatalogProduct::GetByID($offerId); - $info = array( + $info = [ 'NAME' => $elementInfo['NAME'], 'URL' => $url, - 'DIMENSIONS' => serialize(array( - 'WIDTH' => $catalog['WIDTH'], - 'HEIGHT' => $catalog['HEIGHT'], - 'LENGTH' => $catalog['LENGTH'], - )), + 'DIMENSIONS' => serialize( + [ + 'WIDTH' => $catalog['WIDTH'], + 'HEIGHT' => $catalog['HEIGHT'], + 'LENGTH' => $catalog['LENGTH'], + ] + ), 'WEIGHT' => $catalog['WEIGHT'], 'XML_ID' => $elementInfo["XML_ID"], 'IBLOCK_XML_ID' => $elementInfo["IBLOCK_EXTERNAL_ID"] - ); + ]; return $info; } diff --git a/intaro.retailcrm/description.ru b/intaro.retailcrm/description.ru index f2a70663..7ff564aa 100644 --- a/intaro.retailcrm/description.ru +++ b/intaro.retailcrm/description.ru @@ -1 +1 @@ -- Исправлено отображение настройки пользовательских полей +- Добавлена функциональность, позволяющая выгружать из CRM в Bitrix заказы с определенным способом оформления diff --git a/intaro.retailcrm/install/index.php b/intaro.retailcrm/install/index.php index f37afa67..71708ff2 100644 --- a/intaro.retailcrm/install/index.php +++ b/intaro.retailcrm/install/index.php @@ -14,10 +14,10 @@ use Bitrix\Sale\Delivery\Services\Manager; use Bitrix\Sale\EventActions; use Bitrix\Sale\Internals\OrderTable; use Intaro\RetailCrm\Component\ConfigProvider; +use Intaro\RetailCrm\Component\Constants; use Intaro\RetailCrm\Component\Installer\InstallerTrait; use Intaro\RetailCrm\Service\CurrencyService; use Intaro\RetailCrm\Service\OrderLoyaltyDataService; -use Intaro\RetailCrm\Vendor\Symfony\Component\Process\PhpExecutableFinder; use RetailCrm\ApiClient; use RetailCrm\Exception\CurlException; use RetailCrm\Http\Client; @@ -552,6 +552,24 @@ class intaro_retailcrm extends CModule $api_key = COption::GetOptionString($this->MODULE_ID, $this->CRM_API_KEY_OPTION, 0); $this->RETAIL_CRM_API = new ApiClient($api_host, $api_key); + $useCrmOrderMethods = htmlspecialchars(trim($_POST['use_crm_order_methods'])) === 'Y' ? 'Y' : 'N'; + $crmOrderMethod = []; + + if ($useCrmOrderMethods === 'Y') { + $crmOrderMethod = $_POST['crm_order_methods']; + } + COption::SetOptionString( + $this->MODULE_ID, + Constants::USE_CRM_ORDER_METHODS, + $useCrmOrderMethods + ); + + COption::SetOptionString( + $this->MODULE_ID, + Constants::CRM_ORDER_METHODS, + serialize(RCrmActions::clearArr(is_array($crmOrderMethod) ? $crmOrderMethod : [])) + ); + //bitrix orderTypesList $arResult['arSites'] = RCrmActions::getSitesList(); $arResult['bitrixOrderTypesList'] = RCrmActions::OrderTypesList($arResult['arSites']); @@ -1271,6 +1289,10 @@ class intaro_retailcrm extends CModule COption::RemoveOption($this->MODULE_ID, $this->HISTORY_TIME); COption::RemoveOption($this->MODULE_ID, $this->CLIENT_ID); COption::RemoveOption($this->MODULE_ID, $this->PROTOCOL); + COption::RemoveOption($this->MODULE_ID, Constants::MATCHED_CUSTOM_PROPS); + COption::RemoveOption($this->MODULE_ID, Constants::MATCHED_CUSTOM_USER_FIELDS); + COption::RemoveOption($this->MODULE_ID, Constants::CRM_ORDER_METHODS); + COption::RemoveOption($this->MODULE_ID, Constants::USE_CRM_ORDER_METHODS); if (CModule::IncludeModule('sale')) { UnRegisterModuleDependences( diff --git a/intaro.retailcrm/install/step2.php b/intaro.retailcrm/install/step2.php index ee59b0c9..42f31222 100644 --- a/intaro.retailcrm/install/step2.php +++ b/intaro.retailcrm/install/step2.php @@ -1,5 +1,6 @@ 'not-paid', ]; } + +$orderMethods = []; +$getOrderMethods = $RETAIL_CRM_API->orderMethodsList(); + +if ($getOrderMethods !== null && $getOrderMethods->isSuccessful()) { + foreach ($getOrderMethods->orderMethods as $method) { + if (!$method['active']) { + continue; + } + + $orderMethods[$method['code']] = $method['name']; + } +} + +$arResult['orderMethods'] = $orderMethods; +$crmOrderMethods = ConfigProvider::getCrmOrderMethods(); +$useCrmOrderMethods = ConfigProvider::useCrmOrderMethods(); ?>