From 7c667112d5239188ef07ebfdabf028952c3bbbb4 Mon Sep 17 00:00:00 2001 From: Uryvskiy Dima Date: Wed, 5 Jul 2023 10:34:37 +0300 Subject: [PATCH] =?UTF-8?q?ref=20#90482=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D0=BE?= =?UTF-8?q?=D0=BD=D0=B0=D0=BB=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B4=D0=B0=D1=87?= =?UTF-8?q?=D0=B8=20=D0=BF=D1=80=D0=B8=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=BD?= =?UTF-8?q?=D0=BE=D0=B3=D0=BE=20=D0=BA=D1=83=D0=BF=D0=BE=D0=BD=D0=B0=20?= =?UTF-8?q?=D0=B2=20=D0=B7=D0=B0=D0=BA=D0=B0=D0=B7=D0=B5=20=D0=91=D0=B8?= =?UTF-8?q?=D1=82=D1=80=D0=B8=D0=BA=D1=81=20=D0=B2=20=D0=BF=D0=BE=D0=BB?= =?UTF-8?q?=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D1=82=D0=B5=D0=BB=D1=8C=D1=81?= =?UTF-8?q?=D0=BA=D0=BE=D0=B5=20=D0=BF=D0=BE=D0=BB=D0=B5=20=D0=B7=D0=B0?= =?UTF-8?q?=D0=BA=D0=B0=D0=B7=D0=B0=20CRM=20(#302)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 3 ++ .../classes/general/ApiClient_v5.php | 4 +- .../general/order/RetailCrmOrder_v5.php | 19 +++++++++ intaro.retailcrm/description.ru | 2 +- intaro.retailcrm/install/version.php | 4 +- intaro.retailcrm/lang/en/options.php | 2 + intaro.retailcrm/lang/ru/options.php | 2 + .../lib/component/configprovider.php | 17 ++++++++ intaro.retailcrm/lib/component/constants.php | 1 + intaro.retailcrm/options.php | 42 ++++++++++++++++++- 10 files changed, 90 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index da34ec13..73417120 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 2023-07-04 v.6.3.17 +- Добавлен функционал передачи примененного купона в заказе Битрикс в пользовательское поле заказа CRM + ## 2023-06-30 v.6.3.16 - Добавлена передача НДС товаров diff --git a/intaro.retailcrm/classes/general/ApiClient_v5.php b/intaro.retailcrm/classes/general/ApiClient_v5.php index cd6dc64b..036f7626 100644 --- a/intaro.retailcrm/classes/general/ApiClient_v5.php +++ b/intaro.retailcrm/classes/general/ApiClient_v5.php @@ -1433,9 +1433,9 @@ class ApiClient * * @return ApiResponse */ - public function customFieldsList(array $filter = array(), $limit = null, $page = null) + public function customFieldsList(array $filter = [], $limit = null, $page = null) { - $parameters = array(); + $parameters = []; if (count($filter)) { $parameters['filter'] = $filter; diff --git a/intaro.retailcrm/classes/general/order/RetailCrmOrder_v5.php b/intaro.retailcrm/classes/general/order/RetailCrmOrder_v5.php index fb372078..05525ec4 100644 --- a/intaro.retailcrm/classes/general/order/RetailCrmOrder_v5.php +++ b/intaro.retailcrm/classes/general/order/RetailCrmOrder_v5.php @@ -75,6 +75,25 @@ class RetailCrmOrder 'delivery' => ['cost' => $arOrder['PRICE_DELIVERY']], ]; + $orderCouponField = ConfigProvider::getOrderCouponField(); + + if ($orderCouponField !== '__default_empty_value__') { + $couponList = \Bitrix\Sale\Internals\OrderCouponsTable::getList([ + 'select' => ['COUPON'], + 'filter' => ['=ORDER_ID' => $arOrder['ID']], + ]); + $appliedCoupons = []; + + while ($coupon = $couponList->fetch()) + { + $appliedCoupons[] = $coupon['COUPON']; + } + + if (!empty($orderCouponField) && $appliedCoupons !== []) { + $order['customFields'][$orderCouponField] = implode('; ', $appliedCoupons); + } + } + if (!empty($arOrder['REASON_CANCELED'])) { $order['statusComment'] = $arOrder['REASON_CANCELED']; } diff --git a/intaro.retailcrm/description.ru b/intaro.retailcrm/description.ru index af0a8dcb..4660267c 100644 --- a/intaro.retailcrm/description.ru +++ b/intaro.retailcrm/description.ru @@ -1 +1 @@ -- Добавлена передача НДС товаров \ No newline at end of file +- Добавлен функционал передачи примененного купона в заказе Битрикс в пользовательское поле заказа CRM diff --git a/intaro.retailcrm/install/version.php b/intaro.retailcrm/install/version.php index 23800f9b..29639722 100644 --- a/intaro.retailcrm/install/version.php +++ b/intaro.retailcrm/install/version.php @@ -1,6 +1,6 @@ '6.3.16', - 'VERSION_DATE' => '2023-06-30 18:00:00' + 'VERSION' => '6.3.17', + 'VERSION_DATE' => '2023-07-04 18:00:00' ]; diff --git a/intaro.retailcrm/lang/en/options.php b/intaro.retailcrm/lang/en/options.php index 9adef6f2..9f1ef83b 100644 --- a/intaro.retailcrm/lang/en/options.php +++ b/intaro.retailcrm/lang/en/options.php @@ -18,6 +18,8 @@ $MESS ['PAYMENT_Y'] = 'Paid'; $MESS ['PAYMENT_N'] = 'Not paid'; $MESS ['LEGAL_DETAIL'] = 'Legal entity and bank details'; $MESS ['ORDER_CUSTOM'] = 'Custom fields'; +$MESS ['COUPON_CUSTOM_FIELD'] = 'Select a custom field in the CRM to transfer the applied coupon in the Bitrix order'; +$MESS ['SELECT_VALUE'] = '-- Select a value --'; $MESS ['ORDER_UPLOAD'] = 'Re-upload orders'; $MESS ['ORDER_NUMBER'] = 'Order numbers: '; $MESS ['ORDER_UPLOAD_INFO'] = 'Click "Start uploading" to upload all the orders . Or list the required order IDs separated by commas, intervals or dashes. For example: 1, 3, 5-10, 12, 13... etc.'; diff --git a/intaro.retailcrm/lang/ru/options.php b/intaro.retailcrm/lang/ru/options.php index 952bed90..0c458074 100644 --- a/intaro.retailcrm/lang/ru/options.php +++ b/intaro.retailcrm/lang/ru/options.php @@ -19,6 +19,8 @@ $MESS ['PAYMENT_Y'] = 'Оплачен'; $MESS ['PAYMENT_N'] = 'Не оплачен'; $MESS ['LEGAL_DETAIL'] = 'Юридические и банковские реквизиты'; $MESS ['ORDER_CUSTOM'] = 'Кастомные поля'; +$MESS ['COUPON_CUSTOM_FIELD'] = 'Выберите пользовательское поле в CRM для передачи примененного купона в заказе Битрикс'; +$MESS ['SELECT_VALUE'] = '-- Выберите значение --'; $MESS ['ORDER_UPLOAD'] = 'Повторная выгрузка заказов'; $MESS ['ORDER_NUMBER'] = 'Номера заказов: '; $MESS ['ORDER_UPLOAD_INFO'] = 'Для загрузки всех заказов нажмите кнопку «Начать выгрузку». Или перечислите необходимые ID заказов через запятую, интервалы через тире. Например: 1, 3, 5-10, 12, 13... и т.д.'; diff --git a/intaro.retailcrm/lib/component/configprovider.php b/intaro.retailcrm/lib/component/configprovider.php index 40986755..80f6c77b 100644 --- a/intaro.retailcrm/lib/component/configprovider.php +++ b/intaro.retailcrm/lib/component/configprovider.php @@ -69,6 +69,9 @@ class ConfigProvider /** @var bool|null|string $orderVat */ protected static $orderVat; + /** @var null|string $orderVat */ + protected static $orderCouponField; + /** @var array $orderTypes */ protected static $orderTypes; @@ -501,6 +504,20 @@ class ConfigProvider return static::$customFields; } + /** + * get CRM order coupon field + * + * @return string + */ + public static function getOrderCouponField() + { + if (self::isEmptyNotZero(static::$orderCouponField)) { + static::$orderCouponField = static::getOption(Constants::CRM_COUPON_FIELD); + } + + return static::$orderCouponField; + } + /** * getCancellableOrderPaymentStatuses * diff --git a/intaro.retailcrm/lib/component/constants.php b/intaro.retailcrm/lib/component/constants.php index 54d9332a..1f57c107 100644 --- a/intaro.retailcrm/lib/component/constants.php +++ b/intaro.retailcrm/lib/component/constants.php @@ -44,6 +44,7 @@ class Constants public const CRM_SITES_LIST_CORPORATE = 'shops-corporate'; public const CRM_ORDER_NUMBERS = 'order_numbers'; public const CRM_ORDER_VAT = 'order_vat'; + public const CRM_COUPON_FIELD = 'crm_coupon_field'; public const CRM_CANCEL_ORDER = 'cansel_order'; public const CRM_INVENTORIES_UPLOAD = 'inventories_upload'; public const CRM_STORES = 'stores'; diff --git a/intaro.retailcrm/options.php b/intaro.retailcrm/options.php index 1f21878e..aa70a403 100644 --- a/intaro.retailcrm/options.php +++ b/intaro.retailcrm/options.php @@ -35,6 +35,7 @@ $CRM_ORDER_DISCHARGE = 'order_discharge'; $CRM_ORDER_PROPS = 'order_props'; $CRM_LEGAL_DETAILS = 'legal_details'; $CRM_CUSTOM_FIELDS = 'custom_fields'; +$CRM_COUPON_FIELD = 'crm_coupon_field'; $CRM_CONTRAGENT_TYPE = 'contragent_type'; $CRM_SITES_LIST = 'sites_list'; $CRM_ORDER_NUMBERS = 'order_numbers'; @@ -405,6 +406,7 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) { $orderNumbers = htmlspecialchars(trim($_POST['order-numbers'])) ?: 'N'; $orderDimensions = htmlspecialchars(trim($_POST[$CRM_DIMENSIONS])) ?: 'N'; $sendPaymentAmount = htmlspecialchars(trim($_POST[RetailcrmConstants::SEND_PAYMENT_AMOUNT])) ?: 'N'; + $crmCouponFiled = htmlspecialchars(trim($_POST['crm-coupon-field'])) ?: 'N'; //stores $bitrixStoresArr = []; @@ -812,6 +814,11 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) { $CRM_ORDER_VAT, $orderVat ); + COption::SetOptionString( + $mid, + $CRM_COUPON_FIELD, + $crmCouponFiled + ); COption::SetOptionString( $mid, $CRM_CANSEL_ORDER, @@ -1051,9 +1058,27 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) { //currency $baseCurrency = \Bitrix\Currency\CurrencyManager::getBaseCurrency(); - $currencyOption = COption::GetOptionString($mid, $CRM_CURRENCY, 0) ? COption::GetOptionString($mid, $CRM_CURRENCY, 0) : $baseCurrency; + $currencyOption = COption::GetOptionString($mid, $CRM_CURRENCY, 0) ?: $baseCurrency; $currencyList = \Bitrix\Currency\CurrencyManager::getCurrencyList(); + $customFields = [['code' => '__default_empty_value__', 'name' => GetMessage('SELECT_VALUE')]]; + $crmCouponFieldOption = COption::GetOptionString($mid, $CRM_COUPON_FIELD, 0) ?: null; + $page = 1; + + do { + $getCustomFields = $api->customFieldsList(['entity' => 'order', 'type' => ['string', 'text']], 100, $page); + + if (!$getCustomFields->isSuccessful() && empty($getCustomFields['customFields'])) { + break; + } + + foreach ($getCustomFields['customFields'] as $customField) { + $customFields[] = $customField; + } + + $page++; + } while($getCustomFields['pagination']['currentPage'] < $getCustomFields['pagination']['totalPageCount']); + $optionsOrderDimensions = COption::GetOptionString($mid, $CRM_DIMENSIONS, 'N'); $addressOptions = unserialize(COption::GetOptionString($mid, $CRM_ADDRESS_OPTIONS, 0)); @@ -2193,6 +2218,21 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) { + + + +

+ + +