1
0
mirror of synced 2024-11-22 05:16:09 +03:00

ref #93164 Не выгружать на сайт 1C-Bitrix заказы с определенным способом оформления (#330)

This commit is contained in:
Uryvskiy Dima 2023-12-21 17:24:46 +03:00 committed by GitHub
parent 3d3326018a
commit 62b165f5de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 229 additions and 54 deletions

View File

@ -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 ## 2023-12-18 v.6.5.0

View File

@ -34,7 +34,7 @@ class RetailCrmHistory
public static $CRM_DELIVERY_TYPES_ARR = 'deliv_types_arr'; public static $CRM_DELIVERY_TYPES_ARR = 'deliv_types_arr';
public static $CRM_PAYMENT_TYPES = 'pay_types_arr'; public static $CRM_PAYMENT_TYPES = 'pay_types_arr';
public static $CRM_PAYMENT_STATUSES = 'pay_statuses_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_ORDER_LAST_ID = 'order_last_id';
public static $CRM_SITES_LIST = 'sites_list'; public static $CRM_SITES_LIST = 'sites_list';
public static $CRM_ORDER_PROPS = 'order_props'; public static $CRM_ORDER_PROPS = 'order_props';
@ -50,7 +50,6 @@ class RetailCrmHistory
public static $CRM_CURRENCY = 'currency'; public static $CRM_CURRENCY = 'currency';
public static $CRM_DISCOUNT_ROUND = 'discount_round'; public static $CRM_DISCOUNT_ROUND = 'discount_round';
public static $CUSTOM_FIELDS_IS_ACTIVE = 'N'; public static $CUSTOM_FIELDS_IS_ACTIVE = 'N';
const PAGE_LIMIT = 25; const PAGE_LIMIT = 25;
public static function customerHistory() public static function customerHistory()
@ -208,8 +207,8 @@ class RetailCrmHistory
CUser::GetList( CUser::GetList(
($by = "ID"), ($by = "ID"),
($order = "desc"), ($order = "desc"),
array('ID' => $customer['externalId']), ['ID' => $customer['externalId']],
array('FIELDS' => array('PERSONAL_PHONE', 'PERSONAL_MOBILE')) ['FIELDS' => ['PERSONAL_PHONE', 'PERSONAL_MOBILE']]
)->fetch() )->fetch()
); );
} }
@ -304,7 +303,7 @@ class RetailCrmHistory
/* @var OrderLoyaltyDataService $orderLoyaltyDataService */ /* @var OrderLoyaltyDataService $orderLoyaltyDataService */
$orderLoyaltyDataService = ServiceLocator::get(OrderLoyaltyDataService::class); $orderLoyaltyDataService = ServiceLocator::get(OrderLoyaltyDataService::class);
$historyFilter = array(); $historyFilter = [];
$historyStart = COption::GetOptionString(self::$MODULE_ID, self::$CRM_ORDER_HISTORY); $historyStart = COption::GetOptionString(self::$MODULE_ID, self::$CRM_ORDER_HISTORY);
if ($historyStart && $historyStart > 0) { if ($historyStart && $historyStart > 0) {
@ -381,7 +380,7 @@ class RetailCrmHistory
$corporateCustomerBuilder = new CorporateCustomerBuilder(); $corporateCustomerBuilder = new CorporateCustomerBuilder();
$corporateContact = array(); $corporateContact = [];
$orderCustomerExtId = $order['customer']['externalId'] ?? null; $orderCustomerExtId = $order['customer']['externalId'] ?? null;
$corporateCustomerBuilder->setOrderCustomerExtId($orderCustomerExtId) $corporateCustomerBuilder->setOrderCustomerExtId($orderCustomerExtId)
->setContragentTypes($contragentTypes) ->setContragentTypes($contragentTypes)
@ -432,6 +431,16 @@ class RetailCrmHistory
} }
if (!isset($order['externalId'])) { 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 (empty($orderCustomerExtId)) {
if (!isset($order['customer']['id']) if (!isset($order['customer']['id'])
|| (RetailCrmOrder::isOrderCorporate($order) || (RetailCrmOrder::isOrderCorporate($order)
@ -520,10 +529,10 @@ class RetailCrmHistory
$api, $api,
'customersFixExternalIds', 'customersFixExternalIds',
__METHOD__, __METHOD__,
array(array( [[
'id' => $order['customer']['id'], 'id' => $order['customer']['id'],
'externalId' => $registeredUserID 'externalId' => $registeredUserID
))) == false ]]) == false
) { ) {
continue; continue;
} }
@ -533,21 +542,21 @@ class RetailCrmHistory
$corporateCustomerBuilder->setOrderCustomerExtId($orderCustomerExtId); $corporateCustomerBuilder->setOrderCustomerExtId($orderCustomerExtId);
} }
$buyerProfileToAppend = array(); $buyerProfileToAppend = [];
if (RetailCrmOrder::isOrderCorporate($order) && !empty($order['company'])) { if (RetailCrmOrder::isOrderCorporate($order) && !empty($order['company'])) {
$buyerProfile = $corporateCustomerBuilder->getBuyerProfile()->getObjectToArray(); $buyerProfile = $corporateCustomerBuilder->getBuyerProfile()->getObjectToArray();
$buyerProfileToAppend = OrderUserProperties::getList(array( $buyerProfileToAppend = OrderUserProperties::getList([
"filter" => $buyerProfile "filter" => $buyerProfile
))->fetch(); ])->fetch();
if (empty($buyerProfileToAppend)) { if (empty($buyerProfileToAppend)) {
$buyerProfileInstance = new CSaleOrderUserProps(); $buyerProfileInstance = new CSaleOrderUserProps();
if ($buyerProfileInstance->Add($buyerProfile)) { if ($buyerProfileInstance->Add($buyerProfile)) {
$buyerProfileToAppend = OrderUserProperties::getList(array( $buyerProfileToAppend = OrderUserProperties::getList([
"filter" => $buyerProfile "filter" => $buyerProfile
))->fetch(); ])->fetch();
} }
} }
} }
@ -634,8 +643,8 @@ class RetailCrmHistory
$propsRemove = true; $propsRemove = true;
} else { } else {
if (isset($order['orderType']) && $order['orderType']) { if (isset($order['orderType']) && $order['orderType']) {
$nType = array(); $nType = [];
$tList = RCrmActions::OrderTypesList(array(array('LID' => $site))); $tList = RCrmActions::OrderTypesList([['LID' => $site]]);
foreach ($tList as $type) { foreach ($tList as $type) {
if (isset($optionsOrderTypes[$type['ID']])) { if (isset($optionsOrderTypes[$type['ID']])) {
@ -688,7 +697,7 @@ class RetailCrmHistory
//props //props
$propertyCollection = $newOrder->getPropertyCollection(); $propertyCollection = $newOrder->getPropertyCollection();
$propertyCollectionArr = $propertyCollection->getArray(); $propertyCollectionArr = $propertyCollection->getArray();
$nProps = array(); $nProps = [];
foreach ($propertyCollectionArr['properties'] as $orderProp) { foreach ($propertyCollectionArr['properties'] as $orderProp) {
if ($orderProp['ID'][0] == 'n') { if ($orderProp['ID'][0] == 'n') {
@ -705,7 +714,7 @@ class RetailCrmHistory
$nProps[] = $orderProp; $nProps[] = $orderProp;
} }
$orderDump = array(); $orderDump = [];
$propertyCollectionArr['properties'] = $nProps; $propertyCollectionArr['properties'] = $nProps;
if ($propsRemove) {//delete props if ($propsRemove) {//delete props
@ -722,7 +731,7 @@ class RetailCrmHistory
$order = $orderCrm['order']; $order = $orderCrm['order'];
} }
$propsKey = array(); $propsKey = [];
foreach ($propertyCollectionArr['properties'] as $prop) { foreach ($propertyCollectionArr['properties'] as $prop) {
if ($prop['PROPS_GROUP_ID'] != 0) { if ($prop['PROPS_GROUP_ID'] != 0) {
@ -746,7 +755,7 @@ class RetailCrmHistory
} }
$fio = RCrmActions::explodeFio($fio); $fio = RCrmActions::explodeFio($fio);
$newFio = array(); $newFio = [];
if ($fio) { if ($fio) {
$newFio[] = isset($order['lastName']) $newFio[] = isset($order['lastName'])
@ -789,7 +798,7 @@ class RetailCrmHistory
if (!empty($order['delivery']['address'][$key])) { if (!empty($order['delivery']['address'][$key])) {
$parameters['filter']['NAME.LANGUAGE_ID'] = 'ru'; $parameters['filter']['NAME.LANGUAGE_ID'] = 'ru';
$parameters['limit'] = 1; $parameters['limit'] = 1;
$parameters['select'] = array('*'); $parameters['select'] = ['*'];
// if address have a dot // if address have a dot
$loc = explode('.', $order['delivery']['address'][$key]); $loc = explode('.', $order['delivery']['address'][$key]);
@ -983,10 +992,10 @@ class RetailCrmHistory
$api, $api,
'customersFixExternalIds', 'customersFixExternalIds',
__METHOD__, __METHOD__,
array(array( [[
'id' => $response['customer']['id'], 'id' => $response['customer']['id'],
'externalId' => $registeredUserID 'externalId' => $registeredUserID
)) ]]
) == false ) == false
) { ) {
continue; continue;
@ -1198,7 +1207,7 @@ class RetailCrmHistory
$order['summ'] = $orderSumm; $order['summ'] = $orderSumm;
//payment //payment
$newHistoryPayments = array(); $newHistoryPayments = [];
if (array_key_exists('payments', $order)) { if (array_key_exists('payments', $order)) {
if (!isset($orderCrm)) { if (!isset($orderCrm)) {
@ -1344,7 +1353,7 @@ class RetailCrmHistory
); );
if ($paymentId) { if ($paymentId) {
PaymentTable::update($paymentId, array('XML_ID' => '')); PaymentTable::update($paymentId, ['XML_ID' => '']);
} }
} }
} }
@ -1357,7 +1366,7 @@ class RetailCrmHistory
$api, $api,
'ordersFixExternalIds', 'ordersFixExternalIds',
__METHOD__, __METHOD__,
array(array('id' => $order['id'], 'externalId' => $newOrder->getId()))) == false [['id' => $order['id'], 'externalId' => $newOrder->getId()]]) == false
) { ) {
continue; continue;
} }
@ -1411,12 +1420,15 @@ class RetailCrmHistory
*/ */
public static function search_array_by_value($array, $value) public static function search_array_by_value($array, $value)
{ {
$results = array(); $results = [];
if (is_array($array)) { if (is_array($array)) {
$found = array_search($value,$array); $found = array_search($value, $array);
if ($found) { if ($found) {
$results[] = $found; $results[] = $found;
} }
foreach ($array as $subarray) foreach ($array as $subarray)
$results = array_merge($results, static::search_array_by_value($subarray, $value)); $results = array_merge($results, static::search_array_by_value($subarray, $value));
} }
@ -1427,14 +1439,14 @@ class RetailCrmHistory
{ {
$customerHistory = self::filterHistory($customerHistory, 'customer'); $customerHistory = self::filterHistory($customerHistory, 'customer');
$server = Context::getCurrent()->getServer()->getDocumentRoot(); $server = Context::getCurrent()->getServer()->getDocumentRoot();
$fields = array(); $fields = [];
if (file_exists($server . '/bitrix/modules/intaro.retailcrm/classes/general/config/objects.xml')) { 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'); $objects = simplexml_load_file($server . '/bitrix/modules/intaro.retailcrm/classes/general/config/objects.xml');
foreach ($objects->fields->field as $object) { foreach ($objects->fields->field as $object) {
$fields[(string)$object["group"]][(string)$object["id"]] = (string)$object; $fields[(string)$object["group"]][(string)$object["id"]] = (string)$object;
} }
} }
$customers = array(); $customers = [];
foreach ($customerHistory as $change) { foreach ($customerHistory as $change) {
$change['customer'] = self::removeEmpty($change['customer']); $change['customer'] = self::removeEmpty($change['customer']);
if ($customers[$change['customer']['id']]) { if ($customers[$change['customer']['id']]) {
@ -1510,7 +1522,7 @@ class RetailCrmHistory
} }
} }
$orders = array(); $orders = [];
foreach ($orderHistory as $change) { foreach ($orderHistory as $change) {
$change['order'] = self::removeEmpty($change['order']); $change['order'] = self::removeEmpty($change['order']);
@ -1548,7 +1560,7 @@ class RetailCrmHistory
} }
if ($change['order']['payments']) { if ($change['order']['payments']) {
$payments = array(); $payments = [];
foreach ($change['order']['payments'] as $payment) { foreach ($change['order']['payments'] as $payment) {
$payments[$payment['id']] = $payment; $payments[$payment['id']] = $payment;
} }
@ -1761,7 +1773,7 @@ class RetailCrmHistory
$services = $service->getProfilesList(); $services = $service->getProfilesList();
if (!array_key_exists($serviceCode, $services)) { if (!array_key_exists($serviceCode, $services)) {
$serviceCode = strtoupper($serviceCode); $serviceCode = strtoupper($serviceCode);
$serviceCode = str_replace(array('-'), "_", $serviceCode); $serviceCode = str_replace('-', "_", $serviceCode);
} }
} }
@ -1893,7 +1905,7 @@ class RetailCrmHistory
* *
* @return void * @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))); $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))); $optionsPayment = array_flip(unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT, 0)));
@ -1901,7 +1913,7 @@ class RetailCrmHistory
foreach ($allPaymentSystems as $allPaymentSystem) { foreach ($allPaymentSystems as $allPaymentSystem) {
$arPaySysmems[$allPaymentSystem['ID']] = $allPaymentSystem['NAME']; $arPaySysmems[$allPaymentSystem['ID']] = $allPaymentSystem['NAME'];
} }
$paymentsList = array(); $paymentsList = [];
$paymentColl = $order->getPaymentCollection(); $paymentColl = $order->getPaymentCollection();
foreach ($paymentColl as $paymentData) { foreach ($paymentColl as $paymentData) {
$data = $paymentData->getFields()->getValues(); $data = $paymentData->getFields()->getValues();
@ -1978,7 +1990,7 @@ class RetailCrmHistory
public static function removeEmpty($inputArray) public static function removeEmpty($inputArray)
{ {
$outputArray = array(); $outputArray = [];
if (!empty($inputArray)) { if (!empty($inputArray)) {
foreach ($inputArray as $key => $element) { foreach ($inputArray as $key => $element) {
@ -2058,18 +2070,20 @@ class RetailCrmHistory
$url = CAllIBlock::ReplaceDetailUrl($elementInfo['DETAIL_PAGE_URL'], $elementInfo, false, 'E'); $url = CAllIBlock::ReplaceDetailUrl($elementInfo['DETAIL_PAGE_URL'], $elementInfo, false, 'E');
$catalog = CCatalogProduct::GetByID($offerId); $catalog = CCatalogProduct::GetByID($offerId);
$info = array( $info = [
'NAME' => $elementInfo['NAME'], 'NAME' => $elementInfo['NAME'],
'URL' => $url, 'URL' => $url,
'DIMENSIONS' => serialize(array( 'DIMENSIONS' => serialize(
'WIDTH' => $catalog['WIDTH'], [
'HEIGHT' => $catalog['HEIGHT'], 'WIDTH' => $catalog['WIDTH'],
'LENGTH' => $catalog['LENGTH'], 'HEIGHT' => $catalog['HEIGHT'],
)), 'LENGTH' => $catalog['LENGTH'],
]
),
'WEIGHT' => $catalog['WEIGHT'], 'WEIGHT' => $catalog['WEIGHT'],
'XML_ID' => $elementInfo["XML_ID"], 'XML_ID' => $elementInfo["XML_ID"],
'IBLOCK_XML_ID' => $elementInfo["IBLOCK_EXTERNAL_ID"] 'IBLOCK_XML_ID' => $elementInfo["IBLOCK_EXTERNAL_ID"]
); ];
return $info; return $info;
} }

View File

@ -1 +1 @@
- Исправлено отображение настройки пользовательских полей - Добавлена функциональность, позволяющая выгружать из CRM в Bitrix заказы с определенным способом оформления

View File

@ -14,10 +14,10 @@ use Bitrix\Sale\Delivery\Services\Manager;
use Bitrix\Sale\EventActions; use Bitrix\Sale\EventActions;
use Bitrix\Sale\Internals\OrderTable; use Bitrix\Sale\Internals\OrderTable;
use Intaro\RetailCrm\Component\ConfigProvider; use Intaro\RetailCrm\Component\ConfigProvider;
use Intaro\RetailCrm\Component\Constants;
use Intaro\RetailCrm\Component\Installer\InstallerTrait; use Intaro\RetailCrm\Component\Installer\InstallerTrait;
use Intaro\RetailCrm\Service\CurrencyService; use Intaro\RetailCrm\Service\CurrencyService;
use Intaro\RetailCrm\Service\OrderLoyaltyDataService; use Intaro\RetailCrm\Service\OrderLoyaltyDataService;
use Intaro\RetailCrm\Vendor\Symfony\Component\Process\PhpExecutableFinder;
use RetailCrm\ApiClient; use RetailCrm\ApiClient;
use RetailCrm\Exception\CurlException; use RetailCrm\Exception\CurlException;
use RetailCrm\Http\Client; 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); $api_key = COption::GetOptionString($this->MODULE_ID, $this->CRM_API_KEY_OPTION, 0);
$this->RETAIL_CRM_API = new ApiClient($api_host, $api_key); $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 //bitrix orderTypesList
$arResult['arSites'] = RCrmActions::getSitesList(); $arResult['arSites'] = RCrmActions::getSitesList();
$arResult['bitrixOrderTypesList'] = RCrmActions::OrderTypesList($arResult['arSites']); $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->HISTORY_TIME);
COption::RemoveOption($this->MODULE_ID, $this->CLIENT_ID); COption::RemoveOption($this->MODULE_ID, $this->CLIENT_ID);
COption::RemoveOption($this->MODULE_ID, $this->PROTOCOL); 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')) { if (CModule::IncludeModule('sale')) {
UnRegisterModuleDependences( UnRegisterModuleDependences(

View File

@ -1,5 +1,6 @@
<?php <?php
use Intaro\RetailCrm\Component\ConfigProvider;
use RetailCrm\ApiClient; use RetailCrm\ApiClient;
/** @var $APPLICATION */ /** @var $APPLICATION */
@ -132,6 +133,23 @@ if (isset($arResult['PAYMENT'])) {
'N' => 'not-paid', 'N' => '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();
?> ?>
<style type="text/css"> <style type="text/css">
@ -145,6 +163,10 @@ if (isset($arResult['PAYMENT'])) {
<?php CJSCore::Init(['jquery']);?> <?php CJSCore::Init(['jquery']);?>
<script type="text/javascript"> <script type="text/javascript">
function switchCrmOrderMethods() {
$('#crm_order_methods').toggle(500);
}
$(document).ready(function() { $(document).ready(function() {
$('input[name="update"]').on('click', function() { $('input[name="update"]').on('click', function() {
$('input[name="step"]').val(2); $('input[name="step"]').val(2);
@ -381,6 +403,32 @@ if (isset($arResult['PAYMENT'])) {
</td> </td>
</tr> </tr>
<?php endforeach; ?> <?php endforeach; ?>
<tr class="heading">
<td colspan="2"><b><?php echo GetMessage('CRM_ORDER_METHODS'); ?></b></td>
</tr>
<tr>
<td colspan="2" style="text-align: center!important;">
<label><input class="addr" type="checkbox" name="use_crm_order_methods" value="Y" onclick="switchCrmOrderMethods();" <?php if ($useCrmOrderMethods === 'Y') {
echo "checked";
} ?>><?php echo GetMessage('CRM_ORDER_METHODS_OPTION'); ?></label>
</td>
</tr>
<tr id="crm_order_methods" style="display:<?php echo $useCrmOrderMethods !== 'Y' ? 'none' : '';?>">
<td colspan="2" style="text-align: center!important;">
<br><br>
<select multiple size="<?php echo count($arResult['orderMethods']);?>" name="crm_order_methods[]">
<?php foreach ($arResult['orderMethods'] as $key => $name): ?>
<option value="<?php echo $key;?>"<?php if (is_array($crmOrderMethods) && in_array($key, $crmOrderMethods)) {
echo 'selected';
} ?>>
<?php echo $name;?>
</option>
<?php endforeach;?>
</select>
</td>
</tr>
</tbody> </tbody>
</table> </table>
<br /> <br />

View File

@ -1,6 +1,6 @@
<?php <?php
$arModuleVersion = [ $arModuleVersion = [
'VERSION' => '6.5.1', 'VERSION' => '6.5.2',
'VERSION_DATE' => '2023-12-21 15:00:00' 'VERSION_DATE' => '2023-12-21 17:30:00'
]; ];

View File

@ -22,3 +22,5 @@ $MESS ['DELIV_TYPES_EXPORT_F'] = 'Set the correspondence between 1C-Bitrix and R
$MESS ['STATUS_NOT_SETTINGS'] ='Cannot find suitable statuses in Bitrix'; $MESS ['STATUS_NOT_SETTINGS'] ='Cannot find suitable statuses in Bitrix';
$MESS ['INTEGRATIONS'] = ' (integration)'; $MESS ['INTEGRATIONS'] = ' (integration)';
$MESS ['INTEGRATION_PAYMENT_LIST'] = 'The status will not be transferred for integration payments'; $MESS ['INTEGRATION_PAYMENT_LIST'] = 'The status will not be transferred for integration payments';
$MESS ['CRM_ORDER_METHODS'] = 'Transfer of orders from CRM to Bitrix';
$MESS ['CRM_ORDER_METHODS_OPTION'] = 'Upload orders using selected methods from RetailCRM';

View File

@ -12,6 +12,8 @@ $MESS ['DELIVERY_TYPES_LIST'] = 'Delivery types';
$MESS ['PAYMENT_TYPES_LIST'] = 'Payment types'; $MESS ['PAYMENT_TYPES_LIST'] = 'Payment types';
$MESS ['PAYMENT_STATUS_LIST'] = 'Statuses'; $MESS ['PAYMENT_STATUS_LIST'] = 'Statuses';
$MESS ['ORDER_TYPES_LIST'] = 'Order types'; $MESS ['ORDER_TYPES_LIST'] = 'Order types';
$MESS ['CRM_ORDER_METHODS'] = 'Transfer of orders from CRM to Bitrix';
$MESS ['CRM_ORDER_METHODS_OPTION'] = 'Upload orders using selected methods from RetailCRM';
$MESS ['CONTRAGENTS_TYPES_LIST'] = 'Contragent type'; $MESS ['CONTRAGENTS_TYPES_LIST'] = 'Contragent type';
$MESS ['PAYMENT_LIST'] = 'Payment'; $MESS ['PAYMENT_LIST'] = 'Payment';
$MESS ['PAYMENT_Y'] = 'Paid'; $MESS ['PAYMENT_Y'] = 'Paid';

View File

@ -22,3 +22,5 @@ $MESS ['DELIV_TYPES_EXPORT_F'] = 'Настроить соответствие д
$MESS ['STATUS_NOT_SETTINGS'] ='Не найдены подходящие статусы в Битрикс'; $MESS ['STATUS_NOT_SETTINGS'] ='Не найдены подходящие статусы в Битрикс';
$MESS ['INTEGRATIONS'] = ' (интеграционная)'; $MESS ['INTEGRATIONS'] = ' (интеграционная)';
$MESS ['INTEGRATION_PAYMENT_LIST'] = 'Для интеграционных оплат статус не передаётся'; $MESS ['INTEGRATION_PAYMENT_LIST'] = 'Для интеграционных оплат статус не передаётся';
$MESS ['CRM_ORDER_METHODS'] = 'Передача заказов из CRM в Битрикс';
$MESS ['CRM_ORDER_METHODS_OPTION'] = 'Выгружать из RetailCRM заказы оформленные выбранными способами';

View File

@ -13,6 +13,8 @@ $MESS ['DELIVERY_TYPES_LIST'] = 'Способы доставки';
$MESS ['PAYMENT_TYPES_LIST'] = 'Способы оплаты'; $MESS ['PAYMENT_TYPES_LIST'] = 'Способы оплаты';
$MESS ['PAYMENT_STATUS_LIST'] = 'Статусы'; $MESS ['PAYMENT_STATUS_LIST'] = 'Статусы';
$MESS ['ORDER_TYPES_LIST'] = 'Типы заказа'; $MESS ['ORDER_TYPES_LIST'] = 'Типы заказа';
$MESS ['CRM_ORDER_METHODS'] = 'Передача заказов из CRM в Битрикс';
$MESS ['CRM_ORDER_METHODS_OPTION'] = 'Выгружать из RetailCRM заказы оформленные выбранными способами';
$MESS ['CONTRAGENTS_TYPES_LIST'] = 'Тип контрагента'; $MESS ['CONTRAGENTS_TYPES_LIST'] = 'Тип контрагента';
$MESS ['PAYMENT_LIST'] = 'Оплата'; $MESS ['PAYMENT_LIST'] = 'Оплата';
$MESS ['PAYMENT_Y'] = 'Оплачен'; $MESS ['PAYMENT_Y'] = 'Оплачен';

View File

@ -1171,6 +1171,22 @@ class ConfigProvider
return static::getOption(Constants::RECEIVE_TRACK_NUMBER_DELIVERY); return static::getOption(Constants::RECEIVE_TRACK_NUMBER_DELIVERY);
} }
/**
* @return string
*/
public static function useCrmOrderMethods()
{
return COption::GetOptionString(Constants::MODULE_ID, Constants::USE_CRM_ORDER_METHODS, 'N');
}
/**
* @return array
*/
public static function getCrmOrderMethods()
{
return static::getUnserializedOption(Constants::CRM_ORDER_METHODS);
}
public static function setTrackNumberStatus($trackNumberStatus) public static function setTrackNumberStatus($trackNumberStatus)
{ {
static::setOption(Constants::RECEIVE_TRACK_NUMBER_DELIVERY, $trackNumberStatus); static::setOption(Constants::RECEIVE_TRACK_NUMBER_DELIVERY, $trackNumberStatus);

View File

@ -88,7 +88,6 @@ class Constants
public const LP_BONUS_INFO = 'LP_BONUS_INFO'; public const LP_BONUS_INFO = 'LP_BONUS_INFO';
public const API_ERRORS_LOG = 'apiErrors'; public const API_ERRORS_LOG = 'apiErrors';
public const LOYALTY_ERROR = 'loyaltyErrors'; public const LOYALTY_ERROR = 'loyaltyErrors';
public const HISTORY_ERRORS = 'historyErrors';
public const REPOSITORY_ERRORS = 'repositoryErrors'; public const REPOSITORY_ERRORS = 'repositoryErrors';
public const TEMPLATES_ERROR = 'templatesErrors'; public const TEMPLATES_ERROR = 'templatesErrors';
public const DEFAULT_LOYALTY_TEMPLATE = 'default_loyalty'; public const DEFAULT_LOYALTY_TEMPLATE = 'default_loyalty';
@ -103,9 +102,10 @@ class Constants
['EVENT_NAME' => 'OnSaleComponentOrderResultPrepared', 'FROM_MODULE' => 'sale'], ['EVENT_NAME' => 'OnSaleComponentOrderResultPrepared', 'FROM_MODULE' => 'sale'],
]; ];
public const SITES_AVAILABLE = 'sites_available'; public const SITES_AVAILABLE = 'sites_available';
public const RECEIVE_TRACK_NUMBER_DELIVERY = 'receive_track_number_delivery'; public const RECEIVE_TRACK_NUMBER_DELIVERY = 'receive_track_number_delivery';
public const CUSTOM_FIELDS_TOGGLE = 'custom_fields_toggle'; public const CUSTOM_FIELDS_TOGGLE = 'custom_fields_toggle';
public const MATCHED_CUSTOM_PROPS = 'matched_order_props'; public const MATCHED_CUSTOM_PROPS = 'matched_order_props';
public const MATCHED_CUSTOM_USER_FIELDS = 'matched_custom_field'; public const MATCHED_CUSTOM_USER_FIELDS = 'matched_custom_field';
public const USE_CRM_ORDER_METHODS = 'use_crm_order_methods';
public const CRM_ORDER_METHODS = 'crm_order_methods';
} }

View File

@ -10,7 +10,6 @@ use Bitrix\Sale\Delivery\Services\Manager;
use Intaro\RetailCrm\Component\ApiClient\ClientAdapter; use Intaro\RetailCrm\Component\ApiClient\ClientAdapter;
use Intaro\RetailCrm\Component\ConfigProvider; use Intaro\RetailCrm\Component\ConfigProvider;
use Intaro\RetailCrm\Component\Constants; use Intaro\RetailCrm\Component\Constants;
use Intaro\RetailCrm\Component\Handlers\EventsHandlers;
use Intaro\RetailCrm\Repository\AgreementRepository; use Intaro\RetailCrm\Repository\AgreementRepository;
use Intaro\RetailCrm\Repository\TemplateRepository; use Intaro\RetailCrm\Repository\TemplateRepository;
use Intaro\RetailCrm\Service\CurrencyService; use Intaro\RetailCrm\Service\CurrencyService;
@ -501,6 +500,14 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) {
CAgent::RemoveAgent("RetailCrmPrices::pricesUpload();", $mid); CAgent::RemoveAgent("RetailCrmPrices::pricesUpload();", $mid);
} }
$useCrmOrderMethods = htmlspecialchars(trim($_POST['use_crm_order_methods'])) === 'Y' ? 'Y' : 'N';
$crmOrderMethod = [];
if ($useCrmOrderMethods === 'Y') {
$crmOrderMethod = $_POST['crm_order_methods'];
}
//demon //demon
$collectorKeys = []; $collectorKeys = [];
if (htmlspecialchars(trim($_POST['collector'])) === 'Y') { if (htmlspecialchars(trim($_POST['collector'])) === 'Y') {
@ -642,7 +649,7 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) {
$availableSites, $availableSites,
$api->deliveryTypesList()->deliveryTypes $api->deliveryTypesList()->deliveryTypes
); );
} catch (\RetailCrm\Exception\CurlException $e) { } catch (CurlException $e) {
RCrmActions::eventLog( RCrmActions::eventLog(
'intaro.retailcrm/options.php', 'RetailCrm\ApiClient::*List::CurlException', 'intaro.retailcrm/options.php', 'RetailCrm\ApiClient::*List::CurlException',
$e->getCode() . ': ' . $e->getMessage() $e->getCode() . ': ' . $e->getMessage()
@ -868,6 +875,16 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) {
$CRM_PRICES_UPLOAD, $CRM_PRICES_UPLOAD,
$pricesUpload $pricesUpload
); );
COption::SetOptionString(
$mid,
Constants::USE_CRM_ORDER_METHODS,
$useCrmOrderMethods
);
COption::SetOptionString(
$mid,
Constants::CRM_ORDER_METHODS,
serialize(RCrmActions::clearArr(is_array($crmOrderMethod) ? $crmOrderMethod : []))
);
COption::SetOptionString( COption::SetOptionString(
$mid, $mid,
$CRM_PRICES, $CRM_PRICES,
@ -987,7 +1004,7 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) {
$api_key = COption::GetOptionString($mid, $CRM_API_KEY_OPTION, 0); $api_key = COption::GetOptionString($mid, $CRM_API_KEY_OPTION, 0);
$api = new RetailCrm\ApiClient($api_host, $api_key); $api = new RetailCrm\ApiClient($api_host, $api_key);
//prepare crm lists // Prepare crm lists
try { try {
$arResult['orderTypesList'] = $api->orderTypesList()->orderTypes; $arResult['orderTypesList'] = $api->orderTypesList()->orderTypes;
$arResult['deliveryTypesList'] = $api->deliveryTypesList()->deliveryTypes; $arResult['deliveryTypesList'] = $api->deliveryTypesList()->deliveryTypes;
@ -1009,7 +1026,22 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) {
'utf-8', 'utf-8',
SITE_CHARSET SITE_CHARSET
); );
} catch (\RetailCrm\Exception\CurlException $e) {
$orderMethods = [];
$getOrderMethods = $api->orderMethodsList();
if ($getOrderMethods !== null && $getOrderMethods->isSuccessful()) {
foreach ($getOrderMethods->orderMethods as $method) {
if (!$method['active']) {
continue;
}
$orderMethods[$method['code']] = $method['name'];
}
}
$arResult['orderMethods'] = $orderMethods;
} catch (CurlException $e) {
RCrmActions::eventLog( RCrmActions::eventLog(
'intaro.retailcrm/options.php', 'RetailCrm\ApiClient::*List::CurlException', 'intaro.retailcrm/options.php', 'RetailCrm\ApiClient::*List::CurlException',
$e->getCode() . ': ' . $e->getMessage() $e->getCode() . ': ' . $e->getMessage()
@ -1099,11 +1131,13 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) {
$arResult['bitrixPricesExportList'] = RCrmActions::PricesExportList(); $arResult['bitrixPricesExportList'] = RCrmActions::PricesExportList();
//saved params //saved params
$useCrmOrderMethods = ConfigProvider::useCrmOrderMethods();
$crmOrderMethods = unserialize(COption::GetOptionString($mid, Constants::CRM_ORDER_METHODS, 0));
$moduleDeactivate = unserialize(COption::GetOptionString($mid, $MODULE_DEACTIVATE, 'N')); $moduleDeactivate = unserialize(COption::GetOptionString($mid, $MODULE_DEACTIVATE, 'N'));
$optionsOrderTypes = unserialize(COption::GetOptionString($mid, $CRM_ORDER_TYPES_ARR, 0)); $optionsOrderTypes = unserialize(COption::GetOptionString($mid, $CRM_ORDER_TYPES_ARR, 0));
$optionsDelivTypes = unserialize(COption::GetOptionString($mid, $CRM_DELIVERY_TYPES_ARR, 0)); $optionsDelivTypes = unserialize(COption::GetOptionString($mid, $CRM_DELIVERY_TYPES_ARR, 0));
$optionsPayTypes = unserialize(COption::GetOptionString($mid, $CRM_PAYMENT_TYPES, 0)); $optionsPayTypes = unserialize(COption::GetOptionString($mid, $CRM_PAYMENT_TYPES, 0));
$optionsPayStatuses = unserialize(COption::GetOptionString($mid, $CRM_PAYMENT_STATUSES, 0)); // --statuses $optionsPayStatuses = unserialize(COption::GetOptionString($mid, $CRM_PAYMENT_STATUSES, 0));
$optionsPayment = unserialize(COption::GetOptionString($mid, $CRM_PAYMENT, 0)); $optionsPayment = unserialize(COption::GetOptionString($mid, $CRM_PAYMENT, 0));
$optionsSitesList = unserialize(COption::GetOptionString($mid, $CRM_SITES_LIST, 0)); $optionsSitesList = unserialize(COption::GetOptionString($mid, $CRM_SITES_LIST, 0));
$optionsDischarge = (int) COption::GetOptionString($mid, $CRM_ORDER_DISCHARGE, 0); $optionsDischarge = (int) COption::GetOptionString($mid, $CRM_ORDER_DISCHARGE, 0);
@ -1407,6 +1441,10 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) {
) )
} }
function switchCrmOrderMethods() {
$('#crm_order_methods').toggle(500);
}
function switchPLStatus() { function switchPLStatus() {
$('#loyalty_main_settings').toggle(500); $('#loyalty_main_settings').toggle(500);
} }
@ -1919,6 +1957,32 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) {
</td> </td>
</tr> </tr>
<?php endforeach; ?> <?php endforeach; ?>
<tr class="heading">
<td colspan="2"><b><?php echo GetMessage('CRM_ORDER_METHODS'); ?></b></td>
</tr>
<tr>
<td colspan="2" style="text-align: center!important;">
<label><input class="addr" type="checkbox" name="use_crm_order_methods" value="Y" onclick="switchCrmOrderMethods();" <?php if ($useCrmOrderMethods === 'Y') {
echo "checked";
} ?>><?php echo GetMessage('CRM_ORDER_METHODS_OPTION'); ?></label>
</td>
</tr>
<tr id="crm_order_methods" style="display:<?php echo $useCrmOrderMethods !== 'Y' ? 'none' : '';?>">
<td colspan="2" style="text-align: center!important;">
<br><br>
<select multiple size="<?php echo count($arResult['orderMethods']);?>" name="crm_order_methods[]">
<?php foreach ($arResult['orderMethods'] as $key => $name): ?>
<option value="<?php echo $key;?>"<?php if (is_array($crmOrderMethods) && in_array($key, $crmOrderMethods)) {
echo 'selected';
} ?>>
<?php echo $name;?>
</option>
<?php endforeach;?>
</select>
</td>
</tr>
<?php $tabControl->BeginNextTab(); ?> <?php $tabControl->BeginNextTab(); ?>
<input type="hidden" name="tab" value="catalog"> <input type="hidden" name="tab" value="catalog">
<tr class="option-head"> <tr class="option-head">