add agent in updater
This commit is contained in:
parent
d20453cc9c
commit
0da6b782a4
3 changed files with 57 additions and 27 deletions
|
@ -574,10 +574,7 @@ class RetailCrmOrder
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
$orderIds = array_unique(array_merge($orderIds, $orderUpdateIds));
|
||||
|
||||
|
||||
$orderIds = array_unique(array_merge($orderIds, $orderUpdateIds));
|
||||
if (count($orderIds) <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
@ -609,6 +606,7 @@ class RetailCrmOrder
|
|||
];
|
||||
|
||||
$recOrders = [];
|
||||
$maxUpdateDate = $dateOfLastUpdate;
|
||||
|
||||
foreach ($orderIds as $orderId) {
|
||||
$bitrixOrder = Order::load($orderId);
|
||||
|
@ -637,7 +635,6 @@ class RetailCrmOrder
|
|||
}
|
||||
|
||||
$orderCrm = RCrmActions::apiMethod($api, 'ordersGet', __METHOD__, $orderId, $site);
|
||||
RetailcrmConfigProvider::setLastOrderUpdate(date("Y-m-d H:i:s"));
|
||||
|
||||
if (isset($orderCrm['order'])) {
|
||||
$methodApi = 'ordersEdit';
|
||||
|
@ -646,18 +643,19 @@ class RetailCrmOrder
|
|||
$methodApi = 'ordersCreate';
|
||||
}
|
||||
|
||||
self::createCustomerForOrder($api, $arCustomer, $arCustomerCorporate,$arParams, $order, $site);
|
||||
|
||||
if (isset($order['RESPONSIBLE_ID']) && !empty($order['RESPONSIBLE_ID'])) {
|
||||
$managerService = ManagerService::getInstance();
|
||||
$arParams['managerId'] = $managerService->getManagerCrmId((int) $order['RESPONSIBLE_ID']);
|
||||
}
|
||||
|
||||
if ($methodApi === 'ordersEdit') {
|
||||
$arOrders = self::orderSend($order, $api, $arParams, true, $site, '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) {
|
||||
|
@ -680,6 +678,8 @@ class RetailCrmOrder
|
|||
$recOrders[] = $orderId;
|
||||
}
|
||||
|
||||
RetailcrmConfigProvider::setLastOrderUpdate($maxUpdateDate);
|
||||
|
||||
if (count($ordersPack) > 0) {
|
||||
if (false === RetailCrmOrder::uploadCustomersList($resCustomers, $api, $arParams['optionsSitesList'])) {
|
||||
return false;
|
||||
|
|
|
@ -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;
|
||||
|
@ -315,7 +316,6 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) {
|
|||
// 0 - agent
|
||||
// 1 - event
|
||||
// 2 - agent without update
|
||||
$agentUpload = false;
|
||||
$orderDischarge = (int) htmlspecialchars(trim($_POST['order-discharge']));
|
||||
|
||||
if (($orderDischarge != $previousDischarge) && ($orderDischarge === 0 || $orderDischarge === 2 )) {
|
||||
|
@ -323,23 +323,7 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) {
|
|||
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);
|
||||
|
@ -354,7 +338,32 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) {
|
|||
$dateAgent->format('d.m.Y H:i:s'),
|
||||
30
|
||||
);
|
||||
} else {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -1194,6 +1194,27 @@ function update()
|
|||
UnRegisterModuleDependences('sale', 'OnSaleOrderSaved', 'intaro.retailcrm', $loyaltyEventClass, 'OnSaleOrderSavedHandler');
|
||||
UnRegisterModuleDependences('sale', 'OnSaleComponentOrderResultPrepared', 'intaro.retailcrm', $loyaltyEventClass, 'OnSaleComponentOrderResultPreparedHandler');
|
||||
}
|
||||
|
||||
$orderDischarge = Option::get('intaro.retailcrm', 'order_discharge');
|
||||
|
||||
if ($orderDischarge === '0' || $orderDischarge === '2') {
|
||||
$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
|
||||
);
|
||||
|
||||
if ($orderDischarge === '0') {
|
||||
COption::SetOptionString('intaro.retailcrm', 'last_order_update', date("Y-m-d H:i:s"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function createCustomPropertyFile()
|
||||
|
|
Loading…
Add table
Reference in a new issue