1
0
Fork 0
mirror of synced 2025-04-04 14:23:33 +03:00

Agent-upload-fix

This commit is contained in:
anton 2024-10-24 17:44:18 +03:00
parent b68779a054
commit d20453cc9c
9 changed files with 114 additions and 12 deletions

View file

@ -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 .

View file

@ -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,24 @@ 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;
}
@ -615,6 +636,16 @@ class RetailCrmOrder
continue;
}
$orderCrm = RCrmActions::apiMethod($api, 'ordersGet', __METHOD__, $orderId, $site);
RetailcrmConfigProvider::setLastOrderUpdate(date("Y-m-d H:i:s"));
if (isset($orderCrm['order'])) {
$methodApi = 'ordersEdit';
$arParams['crmOrder'] = $orderCrm['order'];
} else {
$methodApi = 'ordersCreate';
}
self::createCustomerForOrder($api, $arCustomer, $arCustomerCorporate,$arParams, $order, $site);
if (isset($order['RESPONSIBLE_ID']) && !empty($order['RESPONSIBLE_ID'])) {
@ -622,7 +653,12 @@ class RetailCrmOrder
$arParams['managerId'] = $managerService->getManagerCrmId((int) $order['RESPONSIBLE_ID']);
}
$arOrders = self::orderSend($order, $api, $arParams, false, $site,'ordersCreate');
if ($methodApi === 'ordersEdit') {
$arOrders = self::orderSend($order, $api, $arParams, true, $site, 'ordersEdit');
continue;
}
$arOrders = self::orderSend($order, $api, $arParams, false, $site, $methodApi);
if (!$arCustomer || !$arOrders) {
continue;

View file

@ -1 +1 @@
- Исправлена подписка модуля на событие сохранения заказа
- Исправлена выгрузка заказов через агент

View file

@ -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'
];

View file

@ -41,6 +41,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';

View file

@ -62,7 +62,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С-Битрикс';

View file

@ -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
*

View file

@ -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';
}

View file

@ -314,16 +314,48 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) {
//order discharge mode
// 0 - agent
// 1 - event
// 2 - agent without update
$agentUpload = false;
$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");
$agentUpload = true;
if ($orderDischarge === 0 && COption::GetOptionString($mid, Constants::LAST_ORDER_UPDATE) === '') {
COption::SetOptionString($mid, Constants::LAST_ORDER_UPDATE, date("Y-m-d H:i:s"));
} else {
COption::RemoveOption($mid, Constants::LAST_ORDER_UPDATE);
}
} 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);
}
if ($agentUpload) {
$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
);
} else {
CAgent::RemoveAgent("RCrmActions::uploadOrdersAgent();", $mid);
}
$optionCart = COption::GetOptionString($mid, Constants::CART, 'N');
@ -3015,6 +3047,9 @@ 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>