Исправлена выгрузка заказов через агент (#372)
This commit is contained in:
parent
b68779a054
commit
41257b9d7c
@ -1,3 +1,6 @@
|
||||
## 2024-10-31 v6.5.38
|
||||
- Исправлена выгрузка заказов через агент
|
||||
|
||||
## 2024-10-30 v6.5.37
|
||||
- Исправлена подписка модуля на событие сохранения заказа
|
||||
|
||||
|
@ -266,8 +266,8 @@ class RCrmActions
|
||||
if (is_array($failedIds) && !empty($failedIds)) {
|
||||
RetailCrmOrder::uploadOrders(50, true);
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
return 'RCrmActions::uploadOrdersAgent();';
|
||||
}
|
||||
|
||||
/**
|
||||
@ -290,7 +290,6 @@ class RCrmActions
|
||||
|
||||
RetailCrmHistory::customerHistory();
|
||||
RetailCrmHistory::orderHistory();
|
||||
self::uploadOrdersAgent();
|
||||
} catch (\Throwable $exception) {
|
||||
Logger::getInstance()->write(
|
||||
'Fail orderAgent:' . PHP_EOL .
|
||||
|
@ -10,6 +10,7 @@
|
||||
*/
|
||||
|
||||
use Bitrix\Main\Context;
|
||||
use Bitrix\Main\Type\DateTime;
|
||||
use Bitrix\Main\Context\Culture;
|
||||
use Bitrix\Main\UserTable;
|
||||
use Bitrix\Sale\Delivery\Services\Manager;
|
||||
@ -429,7 +430,7 @@ class RetailCrmOrder
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ('ordersEdit' === $methodApi) {
|
||||
$order = RetailCrmService::unsetIntegrationDeliveryFields($order);
|
||||
}
|
||||
@ -536,9 +537,11 @@ class RetailCrmOrder
|
||||
$resCustomersAdded = [];
|
||||
$resCustomersCorporate = [];
|
||||
$orderIds = [];
|
||||
$orderUpdateIds = [];
|
||||
|
||||
$lastUpOrderId = RetailcrmConfigProvider::getLastOrderId();
|
||||
$failedIds = RetailcrmConfigProvider::getFailedOrdersIds();
|
||||
$uploadMethod = RetailcrmConfigProvider::getOrderDischarge();
|
||||
|
||||
if ($failed == true && $failedIds !== false && count($failedIds) > 0) {
|
||||
$orderIds = $failedIds;
|
||||
@ -557,6 +560,22 @@ class RetailCrmOrder
|
||||
}
|
||||
}
|
||||
|
||||
if((int)$uploadMethod === 0) {
|
||||
$dateOfLastUpdate = RetailcrmConfigProvider::getLastOrderUpdate();
|
||||
$dbOrderUpdate = OrderTable::GetList([
|
||||
'order' => ['ID' => 'ASC'],
|
||||
'filter' => ['>DATE_UPDATE' => DateTime::createFromTimestamp(strtotime($dateOfLastUpdate))],
|
||||
'limit' => $pSize,
|
||||
'select' => ['ID'],
|
||||
]);
|
||||
|
||||
while ($arOrderUpdate = $dbOrderUpdate->fetch()) {
|
||||
$orderUpdateIds[] = $arOrderUpdate['ID'];
|
||||
}
|
||||
}
|
||||
|
||||
$orderIds = array_unique(array_merge($orderIds, $orderUpdateIds));
|
||||
|
||||
if (count($orderIds) <= 0) {
|
||||
return false;
|
||||
}
|
||||
@ -588,6 +607,7 @@ class RetailCrmOrder
|
||||
];
|
||||
|
||||
$recOrders = [];
|
||||
$maxUpdateDate = $dateOfLastUpdate;
|
||||
|
||||
foreach ($orderIds as $orderId) {
|
||||
$bitrixOrder = Order::load($orderId);
|
||||
@ -598,6 +618,8 @@ class RetailCrmOrder
|
||||
|
||||
$arCustomer = [];
|
||||
$arCustomerCorporate = [];
|
||||
$methodApi = 'ordersCreate';
|
||||
|
||||
$order = self::orderObjToArr($bitrixOrder);
|
||||
$site = self::getCrmShopCodeByLid($order['LID'], $arParams['optionsSitesList']);
|
||||
|
||||
@ -615,14 +637,30 @@ class RetailCrmOrder
|
||||
continue;
|
||||
}
|
||||
|
||||
self::createCustomerForOrder($api, $arCustomer, $arCustomerCorporate,$arParams, $order, $site);
|
||||
if((int)$uploadMethod === 0) {
|
||||
$orderCrm = RCrmActions::apiMethod($api, 'ordersGet', __METHOD__, $orderId, $site);
|
||||
|
||||
if (isset($orderCrm['order'])) {
|
||||
$methodApi = 'ordersEdit';
|
||||
$arParams['crmOrder'] = $orderCrm['order'];
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($order['RESPONSIBLE_ID']) && !empty($order['RESPONSIBLE_ID'])) {
|
||||
$managerService = ManagerService::getInstance();
|
||||
$arParams['managerId'] = $managerService->getManagerCrmId((int) $order['RESPONSIBLE_ID']);
|
||||
}
|
||||
|
||||
$arOrders = self::orderSend($order, $api, $arParams, false, $site,'ordersCreate');
|
||||
if ($methodApi === 'ordersEdit') {
|
||||
$updateDate = $bitrixOrder->getField('DATE_UPDATE')->format("Y-m-d H:i:s");
|
||||
$maxUpdateDate = $updateDate > $maxUpdateDate ? $updateDate : $maxUpdateDate;
|
||||
|
||||
self::orderSend($order, $api, $arParams, true, $site);
|
||||
continue;
|
||||
}
|
||||
|
||||
self::createCustomerForOrder($api, $arCustomer, $arCustomerCorporate,$arParams, $order, $site);
|
||||
$arOrders = self::orderSend($order, $api, $arParams, false, $site, $methodApi);
|
||||
|
||||
if (!$arCustomer || !$arOrders) {
|
||||
continue;
|
||||
@ -644,6 +682,8 @@ class RetailCrmOrder
|
||||
$recOrders[] = $orderId;
|
||||
}
|
||||
|
||||
RetailcrmConfigProvider::setLastOrderUpdate($maxUpdateDate);
|
||||
|
||||
if (count($ordersPack) > 0) {
|
||||
if (false === RetailCrmOrder::uploadCustomersList($resCustomers, $api, $arParams['optionsSitesList'])) {
|
||||
return false;
|
||||
|
@ -1 +1 @@
|
||||
- Исправлена подписка модуля на событие сохранения заказа
|
||||
- Исправлена выгрузка заказов через агент
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
$arModuleVersion = [
|
||||
'VERSION' => '6.5.37',
|
||||
'VERSION_DATE' => '2024-10-30 14:00:00'
|
||||
'VERSION' => '6.5.38',
|
||||
'VERSION_DATE' => '2024-10-31 15:00:00'
|
||||
];
|
||||
|
@ -23,6 +23,7 @@ $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 ['LP_WARNING'] = 'Loyalty program of RetailCRM is available only with the “Uploading orders by event” options active';
|
||||
$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.';
|
||||
$MESS ['ICRM_OPTIONS_SUBMIT_TITLE'] = 'Save settings';
|
||||
@ -41,6 +42,7 @@ $MESS ['ICRM_OPTIONS_ORDER_DISCHARGE_TAB'] = 'Orders uploading mode';
|
||||
$MESS ['ORDER_DISCH'] = 'Orders uploading mode';
|
||||
$MESS ['DISCHARGE_AGENT'] = 'Upload orders using agent';
|
||||
$MESS ['DISCHARGE_EVENTS'] = 'Upload orders by events';
|
||||
$MESS ['DISCHARGE_WITHOUT_UPDATE'] = 'Upload orders by agent (without update)';
|
||||
$MESS ['INFO_2'] = ' Set the correspondence between 1C-Bitrix and RetailCRM order fields.';
|
||||
$MESS ['ORDER_PROPS'] = 'Correspondence settings between RetailCRM order fields and 1C-Bitrix order properties';
|
||||
$MESS ['FIO'] = 'Full name';
|
||||
|
@ -21,6 +21,7 @@ $MESS ['PAYMENT_TYPES_LIST'] = 'Способы оплаты';
|
||||
$MESS ['PAYMENT_STATUS_LIST'] = 'Статусы';
|
||||
$MESS ['ORDER_TYPES_LIST'] = 'Типы заказа';
|
||||
$MESS ['CRM_ORDER_METHODS'] = 'Передача заказов из CRM в Битрикс';
|
||||
$MESS ['LP_WARNING'] = 'Программа лояльности RetailCRM доступна только при активной опции "Выгрузка заказов по событию"';
|
||||
$MESS ['CRM_ORDER_METHODS_OPTION'] = 'Выгружать из RetailCRM заказы оформленные выбранными способами';
|
||||
$MESS ['CONTRAGENTS_TYPES_LIST'] = 'Тип контрагента';
|
||||
$MESS ['PAYMENT_LIST'] = 'Оплата';
|
||||
@ -62,7 +63,7 @@ $MESS ['ICRM_OPTIONS_ORDER_DISCHARGE_TAB'] = 'Режим выгрузки зак
|
||||
$MESS ['ORDER_DISCH'] = 'Режим выгрузки заказов';
|
||||
$MESS ['DISCHARGE_AGENT'] = 'Выгрузка заказов с помощью агента';
|
||||
$MESS ['DISCHARGE_EVENTS'] = 'Выгрузка заказов по событию';
|
||||
|
||||
$MESS ['DISCHARGE_WITHOUT_UPDATE'] = 'Выгрузка заказов по агенту (только создание заказов)';
|
||||
$MESS ['INFO_2'] = ' Задайте соответствие между полями заказа 1C-Битрикс и RetailCRM.';
|
||||
|
||||
$MESS ['ORDER_PROPS'] = 'Настройки соответствия полей заказа RetailCRM свойствам заказа 1С-Битрикс';
|
||||
|
@ -548,6 +548,36 @@ class ConfigProvider
|
||||
return static::getOption(Constants::CRM_ORDER_LAST_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* getLastOrderUpdate
|
||||
*
|
||||
* @return bool|string|null
|
||||
*/
|
||||
public static function getLastOrderUpdate()
|
||||
{
|
||||
return static::getOption(Constants::LAST_ORDER_UPDATE);
|
||||
}
|
||||
|
||||
/**
|
||||
* setLastOrderUpdate
|
||||
*
|
||||
* @return bool|string|null
|
||||
*/
|
||||
public static function setLastOrderUpdate($value)
|
||||
{
|
||||
static::setOption(Constants::LAST_ORDER_UPDATE, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* getOrderDischarge
|
||||
*
|
||||
* @return bool|string|null
|
||||
*/
|
||||
public static function getOrderDischarge()
|
||||
{
|
||||
return static::getOption(Constants::CRM_ORDER_DISCHARGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* getSendPaymentAmount
|
||||
*
|
||||
|
@ -18,7 +18,7 @@ namespace Intaro\RetailCrm\Component;
|
||||
*/
|
||||
class Constants
|
||||
{
|
||||
public const MODULE_VERSION = '6.5.37';
|
||||
public const MODULE_VERSION = '6.5.38';
|
||||
public const CRM_PURCHASE_PRICE_NULL = 'purchasePrice_null';
|
||||
public const BITRIX_USER_ID_PREFIX = 'bitrixUserId-';
|
||||
public const CRM_USERS_MAP = 'crm_users_map';
|
||||
@ -134,4 +134,5 @@ class Constants
|
||||
public const MODULE_DEACTIVATE = 'module_deactivate';
|
||||
public const AGENTS_DEACTIVATE = 'agents_deactivate';
|
||||
public const EVENTS_DEACTIVATE = 'events_deactivate';
|
||||
public const LAST_ORDER_UPDATE = 'last_order_update';
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ use Bitrix\Main\LoaderException;
|
||||
use Bitrix\Main\SystemException;
|
||||
use Bitrix\Main\UI\Extension;
|
||||
use Bitrix\Sale\Delivery\Services\Manager;
|
||||
use Bitrix\Sale\Internals\OrderTable;
|
||||
use Intaro\RetailCrm\Component\ApiClient\ClientAdapter;
|
||||
use Intaro\RetailCrm\Component\ConfigProvider;
|
||||
use Intaro\RetailCrm\Component\Constants;
|
||||
@ -22,6 +23,7 @@ IncludeModuleLangFile(__FILE__);
|
||||
include (__DIR__ . '/lib/component/advanced/loyaltyinstaller.php');
|
||||
|
||||
$mid = 'intaro.retailcrm';
|
||||
$loyaltyEventClass = 'Intaro\RetailCrm\Component\Handlers\EventsHandlers';
|
||||
$uri = $APPLICATION->GetCurPage() . '?mid=' . htmlspecialchars($mid) . '&lang=' . LANGUAGE_ID;
|
||||
|
||||
if (!CModule::IncludeModule('intaro.retailcrm') || !CModule::IncludeModule('sale') || !CModule::IncludeModule('iblock') || !CModule::IncludeModule('catalog')) {
|
||||
@ -314,16 +316,60 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) {
|
||||
//order discharge mode
|
||||
// 0 - agent
|
||||
// 1 - event
|
||||
// 2 - agent without update
|
||||
$orderDischarge = (int) htmlspecialchars(trim($_POST['order-discharge']));
|
||||
|
||||
if (($orderDischarge != $previousDischarge) && ($orderDischarge === 0)) {
|
||||
if (($orderDischarge != $previousDischarge) && ($orderDischarge === 0 || $orderDischarge === 2 )) {
|
||||
// remove depenedencies
|
||||
UnRegisterModuleDependences('sale', 'OnOrderUpdate', $mid, 'RetailCrmEvent', "onUpdateOrder");
|
||||
UnRegisterModuleDependences('sale', 'OnSaleOrderDeleted', $mid, 'RetailCrmEvent', "orderDelete");
|
||||
UnRegisterModuleDependences('sale', 'OnSaleOrderSaved', $mid, 'RetailCrmEvent', "orderSave");
|
||||
UnRegisterModuleDependences('sale', 'OnOrderUpdate', $mid, 'RetailCrmEvent', "onUpdateOrder");
|
||||
UnRegisterModuleDependences('sale', 'OnSaleOrderSaved', $mid, $loyaltyEventClass, 'OnSaleOrderSavedHandler');
|
||||
UnRegisterModuleDependences('sale', 'OnSaleComponentOrderResultPrepared', $mid, $loyaltyEventClass, 'OnSaleComponentOrderResultPreparedHandler');
|
||||
ConfigProvider::setLoyaltyProgramStatus('N');
|
||||
|
||||
$dateAgent = new DateTime();
|
||||
$intAgent = new DateInterval('PT60S');
|
||||
$dateAgent->add($intAgent);
|
||||
|
||||
CAgent::AddAgent(
|
||||
'RCrmActions::uploadOrdersAgent();',
|
||||
$mid,
|
||||
'N',
|
||||
180,
|
||||
$dateAgent->format('d.m.Y H:i:s'),
|
||||
'Y',
|
||||
$dateAgent->format('d.m.Y H:i:s'),
|
||||
30
|
||||
);
|
||||
|
||||
if ($orderDischarge === 0) {
|
||||
COption::SetOptionString($mid, Constants::LAST_ORDER_UPDATE, date("Y-m-d H:i:s"));
|
||||
} else {
|
||||
COption::RemoveOption($mid, Constants::LAST_ORDER_UPDATE);
|
||||
}
|
||||
|
||||
$dbOrder = OrderTable::GetList([
|
||||
'order' => ['ID' => 'DESC'],
|
||||
'limit' => 1,
|
||||
'select' => ['ID'],
|
||||
]);
|
||||
|
||||
$arOrder = $dbOrder->fetch();
|
||||
|
||||
if ($dbOrder) {
|
||||
COption::SetOptionString($mid, Constants::CRM_ORDER_LAST_ID, $arOrder['ID']);
|
||||
} else {
|
||||
COption::SetOptionString($mid, Constants::CRM_ORDER_LAST_ID, 0);
|
||||
}
|
||||
|
||||
} elseif (($orderDischarge != $previousDischarge) && ($orderDischarge === 1)) {
|
||||
// event dependencies
|
||||
RegisterModuleDependences('sale', 'OnOrderUpdate', $mid, 'RetailCrmEvent', "onUpdateOrder");
|
||||
RegisterModuleDependences('sale', 'OnSaleOrderDeleted', $mid, 'RetailCrmEvent', "orderDelete");
|
||||
RegisterModuleDependences('sale', 'OnSaleOrderSaved', $mid, 'RetailCrmEvent', "orderSave");
|
||||
COption::RemoveOption($mid, Constants::LAST_ORDER_UPDATE);
|
||||
CAgent::RemoveAgent("RCrmActions::uploadOrdersAgent();", $mid);
|
||||
}
|
||||
|
||||
$optionCart = COption::GetOptionString($mid, Constants::CART, 'N');
|
||||
@ -604,22 +650,16 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) {
|
||||
}
|
||||
} catch (Exception $exception) {
|
||||
RCrmActions::eventLog(
|
||||
'intaro.retailcrm/options.php', 'Options_Loyalty_toggle::enable',
|
||||
'intaro.retailcrm/options.php', 'OrderLoyaltyDataService::createLoyaltyHlBlock',
|
||||
$e->getCode() . ': ' . $exception->getMessage()
|
||||
);
|
||||
}
|
||||
|
||||
ConfigProvider::setLoyaltyProgramStatus('Y');
|
||||
} else {
|
||||
try {
|
||||
ConfigProvider::setLoyaltyProgramStatus('N');
|
||||
$loyaltySetup->deleteLPEvents();
|
||||
} catch (Exception $exception) {
|
||||
RCrmActions::eventLog(
|
||||
'intaro.retailcrm/options.php', 'Options_Loyalty_toggle::disable',
|
||||
$e->getCode() . ': ' . $exception->getMessage()
|
||||
);
|
||||
}
|
||||
ConfigProvider::setLoyaltyProgramStatus('N');
|
||||
UnRegisterModuleDependences('sale', 'OnSaleOrderSaved', $mid, $loyaltyEventClass, 'OnSaleOrderSavedHandler');
|
||||
UnRegisterModuleDependences('sale', 'OnSaleComponentOrderResultPrepared', $mid, $loyaltyEventClass, 'OnSaleComponentOrderResultPreparedHandler');
|
||||
}
|
||||
|
||||
try {
|
||||
@ -3015,9 +3055,17 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) {
|
||||
<label><input class="addr" type="radio" name="order-discharge" value="0" <?php if ($optionsDischarge === 0) {
|
||||
echo "checked";
|
||||
} ?>><?php echo GetMessage('DISCHARGE_AGENT'); ?></label>
|
||||
<label><input class="addr" type="radio" name="order-discharge" value="2" <?php if ($optionsDischarge === 2) {
|
||||
echo "checked";
|
||||
} ?>><?php echo GetMessage('DISCHARGE_WITHOUT_UPDATE'); ?></label>
|
||||
</b>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2" class="option-head option-other-top option-other-bottom" style="color:#c24141">
|
||||
<b><?php echo GetMessage('LP_WARNING'); ?></b>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2" class="option-head option-other-top option-other-bottom">
|
||||
<b><?php echo GetMessage('COUPON_CUSTOM_FIELD'); ?></b>
|
||||
|
@ -1185,14 +1185,26 @@ function update()
|
||||
{
|
||||
Loader::includeModule('sale');
|
||||
Loader::includeModule('highloadblock');
|
||||
$loyaltyEventClass = 'Intaro\RetailCrm\Component\Handlers\EventsHandlers';
|
||||
|
||||
COption::SetOptionString('intaro.retailcrm', 'api_version', 'v5');
|
||||
RegisterModuleDependences('sale', 'OnSaleOrderSaved', 'intaro.retailcrm', 'RetailCrmEvent', 'orderSave', 99);
|
||||
|
||||
if (Option::get('intaro.retailcrm', 'loyalty_program_toggle') !== 'Y') {
|
||||
UnRegisterModuleDependences('sale', 'OnSaleOrderSaved', 'intaro.retailcrm', $loyaltyEventClass, 'OnSaleOrderSavedHandler');
|
||||
UnRegisterModuleDependences('sale', 'OnSaleComponentOrderResultPrepared', 'intaro.retailcrm', $loyaltyEventClass, 'OnSaleComponentOrderResultPreparedHandler');
|
||||
$orderDischarge = Option::get('intaro.retailcrm', 'order_discharge');
|
||||
|
||||
if ($orderDischarge === '0') {
|
||||
$dateAgent = new DateTime();
|
||||
|
||||
$dateAgent->add('PT60S');
|
||||
CAgent::AddAgent(
|
||||
'RCrmActions::uploadOrdersAgent();',
|
||||
'intaro.retailcrm',
|
||||
'N',
|
||||
180,
|
||||
$dateAgent->format('d.m.Y H:i:s'),
|
||||
'Y',
|
||||
$dateAgent->format('d.m.Y H:i:s'),
|
||||
30
|
||||
);
|
||||
|
||||
COption::SetOptionString('intaro.retailcrm', 'order_discharge', '2');
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user