1
0
mirror of synced 2024-11-25 14:56:09 +03:00

multi site support

This commit is contained in:
Grisha Pomadchin 2013-09-02 15:48:12 +04:00
parent 2bb2331047
commit db6f1d7013
7 changed files with 73 additions and 8 deletions

View File

@ -11,6 +11,7 @@ class ICrmOrderActions
protected static $CRM_PAYMENT_STATUSES = 'pay_statuses_arr';
protected static $CRM_PAYMENT = 'payment_arr'; //order payment Y/N
protected static $CRM_ORDER_LAST_ID = 'order_last_id';
protected static $CRM_ORDER_SITES = 'sites_ids';
/**
* Mass order uploading, without repeating; always returns true, but writes error log
@ -55,6 +56,7 @@ class ICrmOrderActions
$optionsPayTypes = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT_TYPES, 0));
$optionsPayStatuses = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT_STATUSES, 0)); // --statuses
$optionsPayment = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT, 0));
$optionsSites = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_ORDER_SITES, 0));
$api = new IntaroCrm\RestApi($api_host, $api_key);
@ -63,7 +65,8 @@ class ICrmOrderActions
'optionsDelivTypes' => $optionsDelivTypes,
'optionsPayTypes' => $optionsPayTypes,
'optionsPayStatuses' => $optionsPayStatuses,
'optionsPayment' => $optionsPayment
'optionsPayment' => $optionsPayment,
'optionSites' => $optionsSites
);
//packmode
@ -72,6 +75,9 @@ class ICrmOrderActions
while ($arOrder = $dbOrder->GetNext()) { // here orders by id asc
if(is_array($optionsSites) && !empty($optionsSites) && !in_array($arOrder['LID'], $optionsSites))
continue;
$result = self::orderCreate($arOrder, $api, $arParams);
if (!$result['order'] || !$result['customer'])
@ -325,8 +331,12 @@ class ICrmOrderActions
'items' => $items
));
if(isset($arParams['optionsSites']) && is_array($arParams['optionsSites'])
&& in_array($arFields['LID'], $arParams['optionsSites']))
$resOrder['site'] = $arFields['LID'];
if($send)
return $api->createOrder($resOrder);
$api->createOrder($resOrder);
return array(
'order' => $resOrder,

View File

@ -31,6 +31,7 @@ class intaro_intarocrm extends CModule
var $CRM_PAYMENT_STATUSES = 'pay_statuses_arr';
var $CRM_PAYMENT = 'payment_arr'; //order payment Y/N
var $CRM_ORDER_LAST_ID = 'order_last_id';
var $CRM_ORDER_SITES = 'sites_ids';
var $INSTALL_PATH;
@ -83,11 +84,17 @@ class intaro_intarocrm extends CModule
$arResult['errCode'] = 'ERR_CATALOG';
}
$arResult['arSites'] = array();
$rsSites = CSite::GetList($by, $sort, array());
while ($ar = $rsSites->Fetch())
$arResult['arSites'][] = $ar;
$APPLICATION->IncludeAdminFile(
GetMessage('MODULE_INSTALL_TITLE'),
$_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/step1.php'
);
} else if ($step == 2) {
if(!CModule::IncludeModule("sale")) {
$arResult['errCode'] = 'ERR_SALE';
}
@ -100,7 +107,12 @@ class intaro_intarocrm extends CModule
$arResult['errCode'] = 'ERR_CATALOG';
}
if(isset($arResult['errCode']) && $arResult['errCode']) {
$arResult['arSites'] = array();
$rsSites = CSite::GetList($by, $sort, array());
while ($ar = $rsSites->Fetch())
$arResult['arSites'][] = $ar;
if (isset($arResult['errCode']) && $arResult['errCode']) {
$APPLICATION->IncludeAdminFile(
GetMessage('MODULE_INSTALL_TITLE'),
$_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/step1.php'
@ -364,6 +376,12 @@ class intaro_intarocrm extends CModule
$api_host = htmlspecialchars(trim($_POST[$this->CRM_API_HOST_OPTION]));
$api_key = htmlspecialchars(trim($_POST[$this->CRM_API_KEY_OPTION]));
// empty == select all
$orderSites = array();
foreach($_POST[$this->CRM_ORDER_SITES] as $site) {
$orderSites[] = htmlspecialchars(trim($site));
}
// form correct url
$api_host = parse_url($api_host);
$api_host = $api_host['scheme'] . '://' . $api_host['host'];
@ -395,6 +413,7 @@ class intaro_intarocrm extends CModule
COption::SetOptionString($this->MODULE_ID, $this->CRM_API_HOST_OPTION, $api_host);
COption::SetOptionString($this->MODULE_ID, $this->CRM_API_KEY_OPTION, $api_key);
COption::SetOptionString($this->MODULE_ID, $this->CRM_ORDER_SITES, serialize($orderSites));
//prepare crm lists
$arResult['orderTypesList'] = $this->INTARO_CRM_API->orderTypesList();

View File

@ -37,6 +37,16 @@
<td width="50%" class="adm-detail-content-cell-l"><?php echo GetMessage('ICRM_API_KEY'); ?></td>
<td width="50%" class="adm-detail-content-cell-r"><input type="text" id="api_key" name="api_key" value=""></td>
</tr>
<tr>
<td width="50%" class="adm-detail-content-cell-l"><?php echo GetMessage('ICRM_SITES'); ?></td>
<td width="50%" class="adm-detail-content-cell-r">
<select id="sites_ids" name="sites_ids[]" multiple="multiple" size="3">
<?php foreach ($arResult['arSites'] as $site): ?>
<option value="<?php echo $site['LID'] ?>" selected="selected"><?php echo $site['NAME'] . ' (' . $site['LID'] . ')' ?></option>
<?php endforeach; ?>
</select>
</td>
</tr>
</tbody>
</table>
<br />

View File

@ -1,5 +1,5 @@
<?
$arModuleVersion = array(
"VERSION" => "0.3.9",
"VERSION_DATE" => "2013-08-27 18:00:00",
"VERSION" => "0.4.0",
"VERSION_DATE" => "2013-09-02 15:46:00",
);

View File

@ -3,6 +3,7 @@ $MESS ['STEP_NAME'] = 'Шаг 1';
$MESS ['MOD_NEXT_STEP'] = 'Следующий шаг';
$MESS ['ICRM_API_HOST'] = 'Адрес IntaroCRM:';
$MESS ['ICRM_API_KEY'] = 'Ключ авторизации:';
$MESS ['ICRM_SITES'] = 'Активные сайты:';
$MESS ['ERR_404'] = 'Возможно неверно введен адрес IntaroCRM.';
$MESS ['ERR_403'] = 'Неверный apiKey.';
$MESS ['ERR_0'] = 'Превышено время ожидания ответа от сервера.';

View File

@ -4,6 +4,7 @@ $MESS ['ICRM_OPTIONS_IMPORT_TAB'] = 'Настройки импората';
$MESS ['ICRM_CONN_SETTINGS'] = 'Настройка соединения';
$MESS ['ICRM_API_HOST'] = 'Адрес Intaro CRM:';
$MESS ['ICRM_API_KEY'] = 'Ключ авторизации:';
$MESS ['ICRM_SITES'] = 'Активные сайты:';
$MESS ['ICRM_OPTIONS_CATALOG_TAB'] = 'Настройка справочников';
$MESS ['DELIVERY_TYPES_LIST'] = 'Способы доставки';

View File

@ -11,6 +11,7 @@ $CRM_PAYMENT_TYPES = 'pay_types_arr';
$CRM_PAYMENT_STATUSES = 'pay_statuses_arr';
$CRM_PAYMENT = 'payment_arr'; //order payment Y/N
$CRM_ORDER_LAST_ID = 'order_last_id';
$CRM_ORDER_SITES = 'sites_ids';
if(!CModule::IncludeModule('intaro.intarocrm')
|| !CModule::IncludeModule('sale'))
@ -29,6 +30,12 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
$api_host = htmlspecialchars(trim($_POST['api_host']));
$api_key = htmlspecialchars(trim($_POST['api_key']));
// if empty so select all? or exception --not obligatory
$orderSites = array();
foreach ($_POST[$CRM_ORDER_SITES] as $site) {
$orderSites[] = htmlspecialchars(trim($site));
}
if($api_host && $api_key) {
$api = new IntaroCrm\RestApi($api_host, $api_key);
@ -137,6 +144,7 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
COption::SetOptionString($mid, $CRM_PAYMENT_TYPES, serialize($paymentTypesArr));
COption::SetOptionString($mid, $CRM_PAYMENT_STATUSES, serialize($paymentStatusesArr));
COption::SetOptionString($mid, $CRM_PAYMENT, serialize($paymentArr));
COption::SetOptionString($mid, $CRM_ORDER_SITES, serialize($orderSites));
$uri .= '&ok=Y';
LocalRedirect($uri);
@ -146,6 +154,11 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
$api = new IntaroCrm\RestApi($api_host, $api_key);
$arResult['arSites'] = array();
$rsSites = CSite::GetList($by, $sort, array());
while ($ar = $rsSites->Fetch())
$arResult['arSites'][] = $ar;
//prepare crm lists
$arResult['orderTypesList'] = $api->orderTypesList();
$arResult['deliveryTypesList'] = $api->deliveryTypesList();
@ -249,6 +262,7 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
$optionsPayTypes = unserialize(COption::GetOptionString($mid, $CRM_PAYMENT_TYPES, 0));
$optionsPayStatuses = unserialize(COption::GetOptionString($mid, $CRM_PAYMENT_STATUSES, 0)); // --statuses
$optionsPayment = unserialize(COption::GetOptionString($mid, $CRM_PAYMENT, 0));
$optionsSites = unserialize(COption::GetOptionString($mid, $CRM_ORDER_SITES, 0));
$aTabs = array(
array(
@ -284,6 +298,16 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
<td width="50%" class="adm-detail-content-cell-l"><?php echo GetMessage('ICRM_API_KEY'); ?></td>
<td width="50%" class="adm-detail-content-cell-r"><input type="text" id="api_key" name="api_key" value="<?php echo $api_key; ?>"></td>
</tr>
<tr>
<td width="50%" class="adm-detail-content-cell-l"><?php echo GetMessage('ICRM_SITES'); ?></td>
<td width="50%" class="adm-detail-content-cell-r">
<select id="sites_ids" name="sites_ids[]" multiple="multiple" size="3">
<?php foreach ($arResult['arSites'] as $site): ?>
<option value="<?php echo $site['LID'] ?>" <?php if(in_array($site['LID'], $optionsSites)) echo 'selected="selected"'; ?>><?php echo $site['NAME'] . ' (' . $site['LID'] . ')' ?></option>
<?php endforeach; ?>
</select>
</td>
</tr>
<?php $tabControl->BeginNextTab(); ?>
<input type="hidden" name="tab" value="catalog">
<tr align="center">