1
0
mirror of synced 2024-11-21 21:06:09 +03:00

v 0.3.5; improved ICrmOrderActions; + added step3 during install

This commit is contained in:
Grisha Pomadchin 2013-07-23 17:02:37 +04:00
parent 6f4f617d6a
commit dc2ead629f
9 changed files with 354 additions and 81 deletions

View File

@ -40,7 +40,7 @@ class ICrmOrderActions
* Mass order uploading, without repeating; always returns true, but writes error log
* @return boolean
*/
public static function uploadOrders() {
public static function uploadOrders($steps = false, $pSize = 500) {
//COption::SetOptionString(self::$MODULE_ID, self::$CRM_ORDER_LAST_ID, 0); // -- for test
@ -61,13 +61,13 @@ class ICrmOrderActions
self::eventLog('ICrmOrderActions::uploadOrders', 'catalog', 'module not found');
return true;
}
$resOrders = array();
$dbOrder = CSaleOrder::GetList();
$lastUpOrderId = COption::GetOptionString(self::$MODULE_ID, self::$CRM_ORDER_LAST_ID, 0);
$lastUpOrderIdNew = 0;
$lastOrderId = 0;
$dbOrder = CSaleOrder::GetList(array("ID" => "ASC"), array('>ID' => $lastUpOrderId));
$api_host = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_HOST_OPTION, 0);
$api_key = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_KEY_OPTION, 0);
@ -89,38 +89,81 @@ class ICrmOrderActions
'optionsPayment' => $optionsPayment
);
while ($arOrder = $dbOrder->GetNext()) {
if ($arOrder['ID'] <= $lastUpOrderId) //old orders not to upload
break;
if(!$lastUpOrderIdNew)
$lastUpOrderIdNew = $arOrder['ID'];
$order = self::orderCreate($arOrder['ID'], $api, $arParams);
if(!$order)
continue;
$resOrders[] = $order;
}
if(!empty($resOrders)) {
$orders = $api->orderUpload($resOrders);
// error pushing orders
if (!$orders) {
//handle err
self::eventLog('ICrmOrderActions::uploadOrders', 'IntaroCrm\RestApi::orderUpload', $api->getLastError());
return true;
// pack mode enable / disable
// can send data evry 500 rows
if (!$steps) {
while ($arOrder = $dbOrder->GetNext()) { //here orders by id asc; with offset
$order = self::orderCreate($arOrder['ID'], $api, $arParams);
if (!$order)
continue;
$resOrders[] = $order;
$lastOrderId = $arOrder['ID'];
}
if (!empty($resOrders)) {
$orders = $api->orderUpload($resOrders);
// error pushing orders
if (!$orders) {
//handle err
self::eventLog('ICrmOrderActions::uploadOrders', 'IntaroCrm\RestApi::orderUpload', $api->getLastError());
return true;
}
}
} else { // package mode (by default runs after install)
$orderCount = 0;
while ($arOrder = $dbOrder->GetNext()) { // here orders by id asc
$order = self::orderCreate($arOrder['ID'], $api, $arParams);
if (!$order)
continue;
$orderCount++;
$resOrders[] = $order;
$lastOrderId = $arOrder['ID'];
if($orderCount >= $pSize) {
$orders = $api->orderUpload($resOrders);
// error pushing orders
if (!$orders) {
//handle err
self::eventLog('ICrmOrderActions::uploadOrders', 'IntaroCrm\RestApi::orderUpload', $api->getLastError());
return false; // in pack mode return errors
}
COption::SetOptionString(self::$MODULE_ID, self::$CRM_ORDER_LAST_ID, $lastOrderId);
return true; // end of pack
}
}
if (!empty($resOrders)) {
$orders = $api->orderUpload($resOrders);
// error pushing orders
if (!$orders) {
//handle err
self::eventLog('ICrmOrderActions::uploadOrders', 'IntaroCrm\RestApi::orderUpload', $api->getLastError());
return false; // in pack mode return errors
}
}
}
if($lastUpOrderIdNew)
COption::SetOptionString(self::$MODULE_ID, self::$CRM_ORDER_LAST_ID, $lastUpOrderIdNew);
if($lastOrderId)
COption::SetOptionString(self::$MODULE_ID, self::$CRM_ORDER_LAST_ID, $lastOrderId);
return true; //all ok!
}
/**
*
* w+ event in bitrix log
@ -198,39 +241,12 @@ class ICrmOrderActions
);
$phones[] = $phoneWork;
$addressPersonal = array(
'index' => self::toJSON($arUser['PERSONAL_ZIP']),
'country' => self::toJSON(GetCountryByID($arUser['PERSONAL_COUNTRY'])),
'city' => self::toJSON($arUser['PERSONAL_CITY']),
'street' => self::toJSON($arUser['PERSONAL_STREET']),
'building' => self::toJSON($arUser['UF_PERSONAL_BUILDING']),
'flat' => self::toJSON($arUser['UF_PERSONAL_FLAT']),
'notes' => self::toJSON($arUser['PERSONAL_NOTES']),
'text' => self::toJSON($arUser['UF_PERSONAL_TEXT']),
'type' => 'home'
);
$addresses[] = $addressPersonal;
$addressWork = array(
'index' => self::toJSON($arUser['WORK_ZIP']),
'country' => self::toJSON(GetCountryByID($arUser['WORK_COUNTRY'])),
'city' => self::toJSON($arUser['WORK_CITY']),
'street' => self::toJSON($arUser['WORK_STREET']),
'building' => self::toJSON($arUser['UF_WORK_BUILDING']), // --
'flat' => self::toJSON($arUser['UF_WORK_FLAT']),
'notes' => self::toJSON($arUser['PERSONAL_NOTES']),
'text' => self::toJSON($arUser['UF_WORK_TEXT']),
'type' => 'work'
);
$addresses[] = $addressWork;
$result = array(
'externalId' => $arFields['USER_ID'],
'lastName' => $lastName,
'firstName' => $firstName,
'patronymic' => $patronymic,
'phones' => $phones,
'addresses' => $addresses
'phones' => $phones
);
$customer = $api->customerEdit($result);

View File

@ -154,8 +154,10 @@ class RestApi
public function orderHistory($startDate = null, $endDate = null, $limit = 100, $offset = 0)
{
$url = $this->apiUrl.'orders/history';
$this->parameters['startDate'] = $startDate;
$this->parameters['endDate'] = $endDate;
if($startDate)
$this->parameters['startDate'] = $startDate;
if($endDate)
$this->parameters['endDate'] = $endDate;
$this->parameters['limit'] = $limit;
$this->parameters['offset'] = $offset;

View File

@ -164,7 +164,7 @@ class intaro_intarocrm extends CModule
"ACTIVE" => "Y"
)
);
if ($arPaymentTypesList = $dbPaymentTypesList->Fetch()) {
do {
$arResult['bitrixPaymentTypesList'][] = $arPaymentTypesList;
@ -189,6 +189,11 @@ class intaro_intarocrm extends CModule
} while ($arPaymentStatusesList = $dbPaymentStatusesList->Fetch());
}
$arResult['bitrixPaymentStatusesList'][] = array(
'ID' => 'Y',
'NAME' => 'Отменен'
);
$APPLICATION->IncludeAdminFile(
GetMessage('MODULE_INSTALL_TITLE'),
$_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/step2.php'
@ -198,6 +203,31 @@ class intaro_intarocrm extends CModule
if(!CModule::IncludeModule("sale")) {
//handler
}
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && (strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest')
&& isset($_POST['ajax']) && ($_POST['ajax'] == 1)) {
include($this->INSTALL_PATH . '/../classes/general/ICrmOrderActions.php');
ICrmOrderActions::uploadOrders(true); // each 500
$lastUpOrderId = COption::GetOptionString($this->MODULE_ID, $this->CRM_ORDER_LAST_ID, 0);
$countLeft = (int) CSaleOrder::GetList(array("ID" => "ASC"), array('>ID' => $lastUpOrderId), array());
$countAll = (int) CSaleOrder::GetList(array("ID" => "ASC"), array(), array());
if(!isset($_POST['finish']))
$finish = 0;
else
$finish = (int) $_POST['finish'];
$percent = 100 - $countLeft * 100 / $countAll;
if(!$countLeft)
$finish = 1;
$APPLICATION->RestartBuffer();
header('Content-Type: application/x-javascript; charset='.LANG_CHARSET);
die(json_encode(array("finish" => $finish, "percent" => $percent)));
}
if (isset($_POST['back']) && $_POST['back']) {
$APPLICATION->IncludeAdminFile(
@ -282,7 +312,8 @@ class intaro_intarocrm extends CModule
);
//form payment statuses ids arr
$paymentStatusesArr = array();
$paymentStatusesArr['Y'] = htmlspecialchars(trim($_POST['payment-status-Y']));
if ($arPaymentStatusesList = $dbPaymentStatusesList->Fetch()) {
do {
$paymentStatusesArr[$arPaymentStatusesList['ID']] = htmlspecialchars(trim($_POST['payment-status-' . $arPaymentStatusesList['ID']]));
@ -300,11 +331,37 @@ class intaro_intarocrm extends CModule
COption::SetOptionString($this->MODULE_ID, $this->CRM_PAYMENT_STATUSES, serialize($paymentStatusesArr));
COption::SetOptionString($this->MODULE_ID, $this->CRM_PAYMENT, serialize($paymentArr));
COption::SetOptionString($this->MODULE_ID, $this->CRM_ORDER_LAST_ID, 0);
/*RegisterModule($this->MODULE_ID);
//agent
$dateAgent = new DateTime();
$intAgent = new DateInterval('PT600S'); // PT60S - 60 sec; 600 - 600 sec
$dateAgent->add($intAgent);
CAgent::AddAgent(
"ICrmOrderActions::uploadOrdersAgent();",
$this->MODULE_ID,
"N",
600, // interval - 10 mins
$dateAgent->format('d.m.Y H:i:s'), // date of first check
"Y", // агент активен
$dateAgent->format('d.m.Y H:i:s'), // date of first start
30
);
$this->CopyFiles(); */
$APPLICATION->IncludeAdminFile(
GetMessage('MODULE_INSTALL_TITLE'),
$_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/step3.php'
);
} else if ($step == 4) {
RegisterModule($this->MODULE_ID);
//agent
$dateAgent = new DateTime();
$intAgent = new DateInterval('PT60S');
$intAgent = new DateInterval('PT60S'); // PT60S - 60 sec;
$dateAgent->add($intAgent);
CAgent::AddAgent(
@ -322,7 +379,7 @@ class intaro_intarocrm extends CModule
$APPLICATION->IncludeAdminFile(
GetMessage('MODULE_INSTALL_TITLE'),
$_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/step3.php'
$_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/step4.php'
);
}
}

View File

@ -26,7 +26,8 @@ $defaultPayTypes = array (
$defaultPayStatuses = array (
'N' => 'in-processing',
'P' => 'approval',
'F' => 'complete'
'F' => 'complete',
'Y' => 'cancel-other'
);
$defaultPayment = array(

View File

@ -1,10 +1,185 @@
<?php
if(!check_bitrix_sessid()) return;
echo CAdminMessage::ShowNote(GetMessage("MOD_INST_OK")); ?>
if (!check_bitrix_sessid())
return;
IncludeModuleLangFile(__FILE__);
?>
<form action="<?php echo $APPLICATION->GetCurPage(); ?>">
<input type="hidden" name="lang" value="<?php echo LANG; ?>">
<input type="hidden" name="id" value="intaro.intarocrm">
<input type="hidden" name="install" value="Y">
<input type="submit" name="" value="<?php echo GetMessage("MOD_BACK"); ?>">
<form>
<style type="text/css">
.instal-load-block { /* */ }
.instal-load-label {
color: #000;
margin-bottom: 15px;
}
.instal-progress-bar-outer {
height: 32px;
border:1px solid;
border-color:#9ba6a8 #b1bbbe #bbc5c9 #b1bbbe;
-webkit-box-shadow: 1px 1px 0 #fff, inset 0 2px 2px #c0cbce;
box-shadow: 1px 1px 0 #fff, inset 0 2px 2px #c0cbce;
background-color:#cdd8da;
background-image:-webkit-linear-gradient(top, #cdd8da, #c3ced1);
background-image:-moz-linear-gradient(top, #cdd8da, #c3ced1);
background-image:-ms-linear-gradient(top, #cdd8da, #c3ced1);
background-image:-o-linear-gradient(top, #cdd8da, #c3ced1);
background-image:linear-gradient(top, #ced9db, #c3ced1);
border-radius: 2px;
text-align: center;
color: #6a808e;
text-shadow: 0 1px rgba(255,255,255,0.85);
font-size: 18px;
line-height: 35px;
font-weight: bold;
}
.instal-progress-bar-alignment {
height: 28px;
margin: 0 2px;
position: relative;
}
.instal-progress-bar-inner {
height: 28px;
border-radius: 2px;
border-top: solid 1px #52b9df;
background-color:#2396ce;
background-image:-webkit-linear-gradient(top, #27a8d7, #2396ce, #1c79c0);
background-image:-moz-linear-gradient(top, #27a8d7, #2396ce, #1c79c0);
background-image:-ms-linear-gradient(top, #27a8d7, #2396ce, #1c79c0);
background-image:-o-linear-gradient(top, #27a8d7, #2396ce, #1c79c0);
background-image:linear-gradient(top, #27a8d7, #2396ce, #1c79c0);
position: absolute;
overflow: hidden;
top: 2px;
left:0;
}
.instal-progress-bar-inner-text {
color: #fff;
text-shadow: 0 1px rgba(0,0,0,0.2);
font-size: 18px;
line-height: 32px;
font-weight: bold;
text-align: center;
position: absolute;
left: -2px;
top: -2px;
}
</style>
<script type="text/javascript" src="/bitrix/js/main/jquery/jquery-1.7.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var globStop = false;
// orderUpload function
function orderUpload(finish) {
if(globStop)
return false;
if(finish == 1) {
$('#status').text('<?php echo GetMessage('MESS_3'); ?>');
BX.closeWait();
$('input[name="inst"]').css('opacity', '1').removeAttr('disabled');
return true; // exit from function, end recursion
}
var handlerUrl = $(this).parents('form').attr('action');
var step = $('input[name="continue"]').val();
var id = $('input[name="id"]').val();
var install = $('input[name="install"]').val();
var sessid = BX.bitrix_sessid();
var data = 'install=' + install +'&step=' + step + '&sessid=' + sessid +
'&id=' + id + '&ajax=1&finish=' + finish;
// ajax request
$.ajax({
type: 'POST',
url: handlerUrl,
data: data,
dataType: 'json',
success: function(response) {
$('#indicator').css('width', response.percent + '%');
$('#percent').html(response.percent + '%');
$('#percent2').html(response.percent + '%');
orderUpload(response.finish); // wait until next response
}
});
}
$('input[name="start"]').live('click', function() {
BX.showWait();
$(this).attr('name', 'stop');
$(this).attr('value', '<?php echo GetMessage("START_2"); ?>');
$('#status').text('<?php echo GetMessage('MESS_2'); ?>');
if(globStop)
globStop = false;
// hide next step button
$('input[name="inst"]').css('opacity', '0.5').attr('disabled', 'disabled');
orderUpload(0);
return false;
});
$('input[name="stop"]').live('click', function() {
BX.closeWait();
// show next step button
$('input[name="inst"]').css('opacity', '1').removeAttr('disabled');
$(this).attr('name', 'start');
$(this).attr('value', '<?php echo GetMessage("START_3"); ?>');
$('#status').text('<?php echo GetMessage('MESS_4'); ?>');
globStop = true;
return false;
});
});
</script>
<form action="<?php echo $APPLICATION->GetCurPage() ?>" method="POST">
<?php echo bitrix_sessid_post(); ?>
<input type="hidden" name="lang" value="<?php echo LANGUAGE_ID ?>">
<input type="hidden" name="id" value="intaro.intarocrm">
<input type="hidden" name="install" value="Y">
<input type="hidden" name="step" value="4">
<input type="hidden" name="continue" value="3">
<div class="adm-detail-content-item-block">
<table class="adm-detail-content-table edit-table" id="edit1_edit_table">
<tbody>
<tr class="heading">
<td colspan="2"><b><?php echo GetMessage('STEP_NAME'); ?></b></td>
</tr>
</tbody>
</table>
<div class="instal-load-block" id="result">
<div class="instal-load-label" id="status"><?php echo GetMessage('MESS_1'); ?></div>
<div class="instal-progress-bar-outer">
<div class="instal-progress-bar-alignment" style="width: 980px;">
<div class="instal-progress-bar-inner" id="indicator" style="width: 0%;">
<div class="instal-progress-bar-inner-text" style="width: 980px;" id="percent">0%</div>
</div>
<span id="percent2">0%</span>
</div>
</div>
</div>
<br />
<div style="padding: 1px 13px 2px; height:28px;">
<div align="right" style="float:right; width:50%; position:relative;">
<input type="submit" name="inst" value="<?php echo GetMessage("MOD_NEXT_STEP"); ?>" class="adm-btn-save">
</div>
<div align="left" style="float:right; width:50%; position:relative; visible: none;">
<input type="submit" name="start" value="<?php echo GetMessage("START_1"); ?>" class="adm-btn-save">
</div>
</div>
</div>
</form>

View File

@ -0,0 +1,10 @@
<?php
if(!check_bitrix_sessid()) return;
echo CAdminMessage::ShowNote(GetMessage("MOD_INST_OK")); ?>
<form action="<?php echo $APPLICATION->GetCurPage(); ?>">
<input type="hidden" name="lang" value="<?php echo LANG; ?>">
<input type="hidden" name="id" value="intaro.intarocrm">
<input type="hidden" name="install" value="Y">
<input type="submit" name="" value="<?php echo GetMessage("MOD_BACK"); ?>">
<form>

View File

@ -1,5 +1,5 @@
<?
$arModuleVersion = array(
'VERSION' => '0.4.4',
'VERSION_DATE' => '2013-07-16 14:41:00',
);
'VERSION' => '0.3.5',
'VERSION_DATE' => '2013-07-23 17:01:00',
);

View File

@ -1,4 +1,12 @@
<?php
$MESS ['PATH_PROMPT'] = 'Введите путь для установки сайта для системы Intaro CRM';
$MESS ['PATH_FIELD'] = 'Путь';
$MESS ['STEP_NAME'] = 'Шаг 3';
$MESS ['MESS_1'] = 'Нажмите кнопку для экспорта заказов в IntaroCRM.';
$MESS ['MESS_2'] = 'Экспорт...';
$MESS ['MESS_3'] = 'Экспорт заказов успешно завершён.';
$MESS ['MESS_4'] = 'Экспорт заказов приостановлен.';
$MESS ['STOP'] = 'Приостановить выгрузку';
$MESS ['START_1'] = 'Начать выгрузку';
$MESS ['START_2'] = 'Приостановить выгрузку';
$MESS ['START_3'] = 'Вообновить выгрузку';
$MESS ['MOD_NEXT_STEP'] = 'Следующий шаг';
?>

View File

@ -119,13 +119,13 @@ if (isset($_POST['Update']) && $_POST['Update']=='Y') {
);
//form payment statuses ids arr
$paymentStatusesArr = array();
$paymentStatusesArr['Y'] = htmlspecialchars(trim($_POST['payment-status-Y']));
if ($arPaymentStatusesList = $dbPaymentStatusesList->Fetch()) {
do {
$paymentStatusesArr[$arPaymentStatusesList['ID']] = htmlspecialchars(trim($_POST['payment-status-' . $arPaymentStatusesList['ID']]));
} while ($arPaymentStatusesList = $dbPaymentStatusesList->Fetch());
}
//form payment ids arr
$paymentArr = array();
$paymentArr['Y'] = htmlspecialchars(trim($_POST['payment-Y']));
@ -226,6 +226,10 @@ if (isset($_POST['Update']) && $_POST['Update']=='Y') {
$arResult['bitrixPaymentStatusesList'][] = $arPaymentStatusesList;
} while ($arPaymentStatusesList = $dbPaymentStatusesList->Fetch());
}
$arResult['bitrixPaymentStatusesList'][] = array(
'ID' => 'Y',
'NAME' => 'Отменен'
);
//bitrix pyament Y/N
$arResult['bitrixPaymentList'][0]['NAME'] = GetMessage('PAYMENT_Y');