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

histore update fixes

This commit is contained in:
Grisha Pomadchin 2013-09-19 00:18:32 +04:00
parent e13fddda75
commit e210a7a26f
8 changed files with 75 additions and 53 deletions

View File

@ -200,7 +200,7 @@ class ICrmOrderActions
$api = new IntaroCrm\RestApi($api_host, $api_key);
$orderHistory = $api->orderHistory();
// pushing existing orders
foreach ($orderHistory as $order) {
@ -249,7 +249,9 @@ class ICrmOrderActions
if(isset($order['customer']) && $order['customer']) $userId = $order['customer'];
$LID = $arFields['LID'];
$rsOrderProps = CSaleOrderPropsValue::GetList(array(), array('ORDER_ID' => $arFields['ID']));
while ($ar = $rsOrderProps->Fetch()) {
if (isset($order['deliveryAddress']) && $order['deliveryAddress']) {
switch ($ar['CODE']) {
@ -403,24 +405,26 @@ class ICrmOrderActions
CSaleBasket::Update($p['ID'], $arProduct);
}*/
// orderUpdate
$arFields = self::clearArr(array(
'PRICE_DELIVERY' => $order['deliveryCost'],
'PRICE' => $order['summ'],
'DATE_MARKED' => $order['markDatetime'],
'USER_ID' => $userId, //$order['customer']
'PAY_SYSTEM_ID' => $optionsPayTypes[$order['paymentType']],
'PAYED' => $optionsPayment[$order['paymentStatus']],
'PRICE_DELIVERY' => $order['deliveryCost'],
'PRICE' => $order['summ'],
'DATE_MARKED' => $order['markDatetime'],
'USER_ID' => $userId, //$order['customer']
'PAY_SYSTEM_ID' => $optionsPayTypes[$order['paymentType']],
'PAYED' => $optionsPayment[$order['paymentStatus']],
//'PERSON_TYPE_ID' => $optionsOrderTypes[$order['orderType']],
'DELIVERY_ID' => $optionsDelivTypes[$order['deliveryType']],
'STATUS_ID' => $optionsPayStatuses[$order['status']]
'DELIVERY_ID' => $optionsDelivTypes[$order['deliveryType']],
'STATUS_ID' => $optionsPayStatuses[$order['status']],
'REASON_CANCELED' => $order['statusComment'],
'USER_DESCRIPTION' => $order['customerComment'],
'COMMENTS' => $order['managerComment']
));
$GLOBALS['FROM_HISTORY'] = true;
$GLOBALS['INTARO_CRM_FROM_HISTORY'] = true;
CSaleOrder::Update($order['externalId'], $arFields);
}
}
@ -550,46 +554,46 @@ class ICrmOrderActions
$rsOrderProps = CSaleOrderPropsValue::GetList(array(), array('ORDER_ID' => $arFields['ID']));
while ($ar = $rsOrderProps->Fetch()) {
switch ($ar['CODE']) {
case $arParams['optionsOrderProps']['index']: $resOrderDeliveryAddress['index'] = self::toJSON($ar['VALUE']);
case $arParams['optionsOrderProps'][$arFields['PERSON_TYPE_ID']]['index']: $resOrderDeliveryAddress['index'] = self::toJSON($ar['VALUE']);
break;
case 'CITY': $resOrderDeliveryAddress['city'] = self::toJSON($ar['VALUE']);
break;
case $arParams['optionsOrderProps']['text']: $resOrderDeliveryAddress['text'] = self::toJSON($ar['VALUE']);
case $arParams['optionsOrderProps'][$arFields['PERSON_TYPE_ID']]['text']: $resOrderDeliveryAddress['text'] = self::toJSON($ar['VALUE']);
break;
case 'LOCATION': if(!isset($resOrderDeliveryAddress['city']) && !$resOrderDeliveryAddress['city']) {
$resOrderDeliveryAddress['city'] = CSaleLocation::GetByID($ar['VALUE']);
$resOrderDeliveryAddress['city'] = self::toJSON($resOrderDeliveryAddress['city']['CITY_NAME_LANG']);
}
break;
case $arParams['optionsOrderProps']['fio']: $contactNameArr = self::explodeFIO($ar['VALUE']);
case $arParams['optionsOrderProps'][$arFields['PERSON_TYPE_ID']]['fio']: $contactNameArr = self::explodeFIO($ar['VALUE']);
break;
case $arParams['optionsOrderProps']['phone']: $resOrder['phone'] = $ar['VALUE'];
case $arParams['optionsOrderProps'][$arFields['PERSON_TYPE_ID']]['phone']: $resOrder['phone'] = $ar['VALUE'];
break;
case $arParams['optionsOrderProps']['email']: $resOrder['email'] = $ar['VALUE'];
case $arParams['optionsOrderProps'][$arFields['PERSON_TYPE_ID']]['email']: $resOrder['email'] = $ar['VALUE'];
break;
}
if (count($arParams['optionsOrderProps'] > 5)) {
if (count($arParams['optionsOrderProps'][$arFields['PERSON_TYPE_ID']] > 5)) {
switch ($ar['CODE']) {
/*case $arParams['optionsOrderProps']['country']: $resOrderDeliveryAddress['country'] = self::toJSON($ar['VALUE']);
/*case $arParams['optionsOrderProps'][$arFields['PERSON_TYPE_ID']]['country']: $resOrderDeliveryAddress['country'] = self::toJSON($ar['VALUE']);
break;
case $arParams['optionsOrderProps']['region']: $resOrderDeliveryAddress['region'] = self::toJSON($ar['VALUE']);
case $arParams['optionsOrderProps'][$arFields['PERSON_TYPE_ID']]['region']: $resOrderDeliveryAddress['region'] = self::toJSON($ar['VALUE']);
break;
case $arParams['optionsOrderProps']['city']: $resOrderDeliveryAddress['city'] = self::toJSON($ar['VALUE']);
case $arParams['optionsOrderProps'][$arFields['PERSON_TYPE_ID']]['city']: $resOrderDeliveryAddress['city'] = self::toJSON($ar['VALUE']);
break; */
case $arParams['optionsOrderProps']['street']: $resOrderDeliveryAddress['street'] = self::toJSON($ar['VALUE']);
case $arParams['optionsOrderProps'][$arFields['PERSON_TYPE_ID']]['street']: $resOrderDeliveryAddress['street'] = self::toJSON($ar['VALUE']);
break;
case $arParams['optionsOrderProps']['building']: $resOrderDeliveryAddress['building'] = self::toJSON($ar['VALUE']);
case $arParams['optionsOrderProps'][$arFields['PERSON_TYPE_ID']]['building']: $resOrderDeliveryAddress['building'] = self::toJSON($ar['VALUE']);
break;
case $arParams['optionsOrderProps']['flat']: $resOrderDeliveryAddress['flat'] = self::toJSON($ar['VALUE']);
case $arParams['optionsOrderProps'][$arFields['PERSON_TYPE_ID']]['flat']: $resOrderDeliveryAddress['flat'] = self::toJSON($ar['VALUE']);
break;
case $arParams['optionsOrderProps']['inercomcode']: $resOrderDeliveryAddress['intercomcode'] = self::toJSON($ar['VALUE']);
case $arParams['optionsOrderProps'][$arFields['PERSON_TYPE_ID']]['inercomcode']: $resOrderDeliveryAddress['intercomcode'] = self::toJSON($ar['VALUE']);
break;
case $arParams['optionsOrderProps']['floor']: $resOrderDeliveryAddress['floor'] = self::toJSON($ar['VALUE']);
case $arParams['optionsOrderProps'][$arFields['PERSON_TYPE_ID']]['floor']: $resOrderDeliveryAddress['floor'] = self::toJSON($ar['VALUE']);
break;
case $arParams['optionsOrderProps']['block']: $resOrderDeliveryAddress['block'] = self::toJSON($ar['VALUE']);
case $arParams['optionsOrderProps'][$arFields['PERSON_TYPE_ID']]['block']: $resOrderDeliveryAddress['block'] = self::toJSON($ar['VALUE']);
break;
case $arParams['optionsOrderProps']['house']: $resOrderDeliveryAddress['house'] = self::toJSON($ar['VALUE']);
case $arParams['optionsOrderProps'][$arFields['PERSON_TYPE_ID']]['house']: $resOrderDeliveryAddress['house'] = self::toJSON($ar['VALUE']);
break;
}
}
@ -626,6 +630,7 @@ class ICrmOrderActions
$createdAt = $createdAt->format('Y-m-d H:i:s');
$resOrder = array(
'number' => $resOrder['ACCOUNT_NUMBER'],
'phone' => $resOrder['phone'],
'email' => $resOrder['email'],
'deliveryCost' => $arFields['PRICE_DELIVERY'],
@ -638,7 +643,9 @@ class ICrmOrderActions
'orderType' => $arParams['optionsOrderTypes'][$arFields['PERSON_TYPE_ID']],
'deliveryType' => $arParams['optionsDelivTypes'][$resultDeliveryTypeId],
'status' => $arParams['optionsPayStatuses'][$arFields['STATUS_ID']],
'statusComment' => $arFields['USER_DESCRIPTION'],
'statusComment' => $arFields['REASON_CANCELED'],
'customerComment' => $arFields['USER_DESCRIPTION'],
'managerComment' => $arFields['COMMENTS'],
'createdAt' => $createdAt,
'deliveryAddress' => $resOrderDeliveryAddress,
'items' => $items

View File

@ -13,7 +13,18 @@ class ICrmOrderEvent {
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_PROPS = 'order_props';
/**
* onBeforeOrderAdd
*
* @param mixed $arFields - Order arFields
*/
function onBeforeOrderAdd($arFields = array()) {
$GLOBALS['INTARO_CRM_ORDER_ADD'] = true;
return;
}
/**
* onUpdateOrder
*
@ -21,7 +32,10 @@ class ICrmOrderEvent {
* @param mixed $arFields - Order arFields
*/
function onUpdateOrder($ID, $arFields = array()) {
if(isset($GLOBALS['FROM_HISTORY']) && $GLOBALS['FROM_HISTORY'])
if(isset($GLOBALS['INTARO_CRM_ORDER_ADD']) && $GLOBALS['INTARO_CRM_ORDER_ADD'])
return;
if(isset($GLOBALS['INTARO_CRM_FROM_HISTORY']) && $GLOBALS['INTARO_CRM_FROM_HISTORY'])
return;
self::writeDataOnOrderCreate($ID);
@ -47,6 +61,7 @@ class ICrmOrderEvent {
* @param integer $ID - Order Id
*/
function writeDataOnOrderCreate($ID) {
if (!CModule::IncludeModule('iblock')) {
//handle err
ICrmOrderActions::eventLog('ICrmOrderEvent::writeDataOnOrderCreate', 'iblock', 'module not found');
@ -64,6 +79,9 @@ class ICrmOrderEvent {
ICrmOrderActions::eventLog('ICrmOrderEvent::writeDataOnOrderCreate', 'catalog', 'module not found');
return true;
}
$GLOBALS['INTARO_CRM_ORDER_ADD'] = false;
$GLOBALS['INTARO_CRM_FROM_HISTORY'] = false;
$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);
@ -74,6 +92,7 @@ class ICrmOrderEvent {
$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));
$optionsOrderProps = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_ORDER_PROPS, 0));
$api = new IntaroCrm\RestApi($api_host, $api_key);
@ -82,7 +101,8 @@ class ICrmOrderEvent {
'optionsDelivTypes' => $optionsDelivTypes,
'optionsPayTypes' => $optionsPayTypes,
'optionsPayStatuses' => $optionsPayStatuses,
'optionsPayment' => $optionsPayment
'optionsPayment' => $optionsPayment,
'optionsOrderProps' => $optionsOrderProps
);
$arOrder = CSaleOrder::GetById($ID);
@ -190,6 +210,7 @@ class ICrmOrderEvent {
);
$api->orderEdit($order);
// error pushing order
if ($api->getStatusCode() != 201)

View File

@ -68,13 +68,6 @@ class intaro_intarocrm extends CModule {
}
}
if (!date_default_timezone_get()) {
if (!ini_get('date.timezone')) {
$APPLICATION->ThrowException(GetMessage("DATE_TIMEZONE_ERR"));
return false;
}
}
include($this->INSTALL_PATH . '/../classes/general/RestApi.php');
include($this->INSTALL_PATH . '/../classes/general/ICrmOrderActions.php');
include($this->INSTALL_PATH . '/../classes/general/ICMLLoader.php');
@ -697,7 +690,7 @@ class intaro_intarocrm extends CModule {
//form orderProps
$dbProp = CSaleOrderProps::GetList(array(), array());
while ($arProp = $dbProp->GetNext()) {
$arResult['arProp'][$arProp['PERSON_TYPE_ID']] = $arProp;
$arResult['arProp'][$arProp['PERSON_TYPE_ID']][] = $arProp;
}
COption::SetOptionString($this->MODULE_ID, $this->CRM_ORDER_TYPES_ARR, serialize($orderTypesArr));
@ -876,6 +869,7 @@ class intaro_intarocrm extends CModule {
}
RegisterModule($this->MODULE_ID);
RegisterModuleDependences("sale", "OnSalePayOrder", $this->MODULE_ID, "ICrmOrderEvent", "onSalePayOrder");
RegisterModuleDependences("sale", "OnSaleCancelOrder", $this->MODULE_ID, "ICrmOrderEvent", "onSaleCancelOrder");
$this->CopyFiles();
if (isset($_POST['LOAD_NOW'])) {

View File

@ -29,9 +29,6 @@
<!--<tr align="center">
<td colspan="2"><b><?php echo GetMessage('INFO_3'); ?></b></td>
</tr>-->
<tr align="center">
<td colspan="2"><b><?php echo GetMessage('INFO_3'); ?></b></td>
</tr>
<tr align="center">
<td colspan="2">&nbsp;</td>
</tr>

View File

@ -58,13 +58,12 @@ $defaultOrderProps = array(
</tr>
<?php foreach($arResult['bitrixOrderTypesList'] as $bitrixOrderType): ?>
<tr class="heading">
<td colspan="2"><b><?php echo $bitrixOrderType['NAME']; ?></b></td>
<td colspan="2"><b><?php echo GetMessage('ORDER_TYPE_INFO') . ' ' . $bitrixOrderType['NAME']; ?></b></td>
</tr>
<?php $countProps = 0; foreach($arResult['orderProps'] as $orderProp): ?>
<?php if($orderProp['ID'] == 'text'): ?>
<tr class="heading">
<td colspan="2">
<td colspan="2" style="background-color: transparent;">
<b>
<label><input class="addr" type="radio" name="address-detail-<?php echo $bitrixOrderType['ID'];; ?>" value="0" <?php if(count($defaultOrderProps[$bitrixOrderType['ID']]) < 6) echo "checked"; ?>><?php echo GetMessage('ADDRESS_SHORT'); ?></label>
<label><input class="addr" type="radio" name="address-detail-<?php echo $bitrixOrderType['ID']; ?>" value="1" <?php if(count($defaultOrderProps[$bitrixOrderType['ID']]) > 5) echo "checked"; ?>><?php echo GetMessage('ADDRESS_FULL'); ?></label>
@ -74,14 +73,14 @@ $defaultOrderProps = array(
<?php endif; ?>
<tr <?php if ($countProps > 4) echo 'class="address-detail-' . $bitrixOrderType['ID'] . '"'; if(($countProps > 4) && (count($defaultOrderProps[$bitrixOrderType['ID']]) < 6)) echo 'style="display:none;"';?>>
<td width="50%" class="adm-detail-content-cell-l" name="<?php echo $orderProp['ID']; ?>">
<?php echo $orderProp['NAME']; ?>
<?php echo $APPLICATION->ConvertCharset($orderProp['NAME'], 'utf-8', SITE_CHARSET);; ?>
</td>
<td width="50%" class="adm-detail-content-cell-r">
<select name="order-prop-<?php echo $orderProp['ID'] . '-' . $bitrixOrderType['ID']; ?>" class="typeselect">
<option value=""></option>
<?php foreach ($arResult['arProp'][$bitrixOrderType['ID']] as $arProp): ?>
<option value="<?php echo $arProp['CODE']; ?>" <?php if ($defaultOrderProps[$bitrixOrderType['ID']][$orderProp['ID']] == $arProp['CODE']) echo 'selected'; ?>>
<?php echo $arProp['NAME']; ?>
<?php echo $APPLICATION->ConvertCharset($arProp['NAME'], 'utf-8', SITE_CHARSET); ?>
</option>
<?php endforeach; ?>
</select>

View File

@ -12,6 +12,7 @@ $MESS ['START_3'] = 'Возобновить выгрузку';
$MESS ['MOD_NEXT_STEP'] = 'Следующий шаг';
$MESS ['MOD_PREV_STEP'] = 'Предыдущий шаг';
$MESS ['INFO_2'] = ' Задайте соответствие между полями заказа 1C-Битрикс и IntaroCRM.';
$MESS ['ORDER_TYPE_INFO'] = 'Тип заказа:';
$MESS ['ORDER_PROPS'] = 'Настройки соответствия полей заказа IntaroCRM свойствам заказа 1С-Битрикс';
$MESS ['FIO'] = 'Ф.И.О.';

View File

@ -50,4 +50,6 @@ $MESS ['FLOOR'] = 'Этаж';
$MESS ['BLOCK'] = 'Подъезд';
$MESS ['HOUSE'] = 'Строение / корпус';
$MESS ['ADDRESS_SHORT'] = 'Краткий адрес';
$MESS ['ADDRESS_FULL'] = 'Детальный адрес';
$MESS ['ADDRESS_FULL'] = 'Детальный адрес';
$MESS ['ORDER_TYPE_INFO'] = 'Тип заказа:';

View File

@ -219,6 +219,7 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
// remove depenedencies
UnRegisterModuleDependences("sale", "OnOrderNewSendEmail", $mid, "ICrmOrderEvent", "onSendOrderMail");
UnRegisterModuleDependences("sale", "OnOrderUpdate", $mid, "ICrmOrderEvent", "onUpdateOrder");
UnRegisterModuleDependences("sale", "OnBeforeOrderAdd", $mid, "ICrmOrderEvent", "onBeforeOrderAdd");
// new agent
$dateAgent = new DateTime();
$intAgent = new DateInterval('PT60S'); // PT60S - 60 sec;
@ -236,7 +237,7 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
// event dependencies
RegisterModuleDependences("sale", "OnOrderNewSendEmail", $mid, "ICrmOrderEvent", "onSendOrderMail");
RegisterModuleDependences("sale", "OnOrderUpdate", $mid, "ICrmOrderEvent", "onUpdateOrder");
RegisterModuleDependences("sale", "OnBeforeOrderAdd", $mid, "ICrmOrderEvent", "onBeforeOrderAdd");
}
$orderPropsArr = array();
@ -576,13 +577,13 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
</tr>
<?php foreach($arResult['bitrixOrderTypesList'] as $bitrixOrderType): ?>
<tr class="heading">
<td colspan="2"><b><?php echo $bitrixOrderType['NAME']; ?></b></td>
<td colspan="2"><b><?php echo GetMessage('ORDER_TYPE_INFO') . ' ' . $bitrixOrderType['NAME']; ?></b></td>
</tr>
<?php $countProps = 0; foreach($arResult['orderProps'] as $orderProp): ?>
<?php if($orderProp['ID'] == 'text'): ?>
<tr class="heading">
<td colspan="2">
<td colspan="2" style="background-color: transparent;">
<b>
<label><input class="addr" type="radio" name="address-detail-<?php echo $bitrixOrderType['ID'];; ?>" value="0" <?php if(count($optionsOrderProps[$bitrixOrderType['ID']]) < 6) echo "checked"; ?>><?php echo GetMessage('ADDRESS_SHORT'); ?></label>
<label><input class="addr" type="radio" name="address-detail-<?php echo $bitrixOrderType['ID']; ?>" value="1" <?php if(count($optionsOrderProps[$bitrixOrderType['ID']]) > 5) echo "checked"; ?>><?php echo GetMessage('ADDRESS_FULL'); ?></label>
@ -599,7 +600,7 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
<option value=""></option>
<?php foreach ($arResult['arProp'][$bitrixOrderType['ID']] as $arProp): ?>
<option value="<?php echo $arProp['CODE']; ?>" <?php if ($optionsOrderProps[$bitrixOrderType['ID']][$orderProp['ID']] == $arProp['CODE']) echo 'selected'; ?>>
<?php echo $arProp['NAME']; ?>
<?php echo $APPLICATION->ConvertCharset($arProp['NAME'], 'utf-8', SITE_CHARSET); ?>
</option>
<?php endforeach; ?>
</select>