1
0
mirror of synced 2024-11-29 16:56:07 +03:00

Merge branch 'master'

Conflicts:
	intaro.intarocrm/classes/general/ICMLLoader.php
This commit is contained in:
m.korolev 2013-09-23 17:44:26 +04:00
commit 62bbcc0f48
11 changed files with 375 additions and 218 deletions

View File

@ -1,5 +1,8 @@
<?php <?php
global $MESS;
IncludeModuleLangFile(__FILE__);
class ICMLLoader { class ICMLLoader {
public $iblocks; public $iblocks;
@ -148,7 +151,7 @@ class ICMLLoader {
$arRes = Array(); $arRes = Array();
$arRes['ID'] = $this->mainSection + $id; $arRes['ID'] = $this->mainSection + $id;
$arRes['IBLOCK_SECTION_ID'] = 0; $arRes['IBLOCK_SECTION_ID'] = 0;
$arRes['NAME'] = "Основной раздел каталога " . $iblock['NAME']; $arRes['NAME'] = sprintf(GetMessage('ROOT_CATEGORY_FOR_CATALOG'), $iblock['NAME']);
$categories[$arRes['ID']] = $arRes; $categories[$arRes['ID']] = $arRes;
} }
} }

View File

@ -13,12 +13,14 @@ class ICrmOrderActions
protected static $CRM_ORDER_LAST_ID = 'order_last_id'; protected static $CRM_ORDER_LAST_ID = 'order_last_id';
protected static $CRM_ORDER_SITES = 'sites_ids'; protected static $CRM_ORDER_SITES = 'sites_ids';
protected static $CRM_ORDER_PROPS = 'order_props'; protected static $CRM_ORDER_PROPS = 'order_props';
protected static $CRM_ORDER_FAILED_IDS = 'order_failed_ids';
/** /**
* Mass order uploading, without repeating; always returns true, but writes error log * Mass order uploading, without repeating; always returns true, but writes error log
* @param $failed -- flag to export failed orders
* @return boolean * @return boolean
*/ */
public static function uploadOrders($pSize = 50) { public static function uploadOrders($pSize = 50, $failed = false) {
//COption::SetOptionString(self::$MODULE_ID, self::$CRM_ORDER_LAST_ID, 0); // -- for test //COption::SetOptionString(self::$MODULE_ID, self::$CRM_ORDER_LAST_ID, 0); // -- for test
@ -46,7 +48,12 @@ class ICrmOrderActions
$lastUpOrderId = COption::GetOptionString(self::$MODULE_ID, self::$CRM_ORDER_LAST_ID, 0); $lastUpOrderId = COption::GetOptionString(self::$MODULE_ID, self::$CRM_ORDER_LAST_ID, 0);
$lastOrderId = 0; $lastOrderId = 0;
$failedIds = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_ORDER_FAILED_IDS, 0));
if (!$failedIds)
$failedIds = array();
$dbOrder = CSaleOrder::GetList(array("ID" => "ASC"), array('>ID' => $lastUpOrderId)); $dbOrder = CSaleOrder::GetList(array("ID" => "ASC"), array('>ID' => $lastUpOrderId));
$dbFailedOrder = CSaleOrder::GetList(array("ID" => "ASC"), array('ID' => $failedIds));
$api_host = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_HOST_OPTION, 0); $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); $api_key = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_KEY_OPTION, 0);
@ -63,48 +70,78 @@ class ICrmOrderActions
$api = new IntaroCrm\RestApi($api_host, $api_key); $api = new IntaroCrm\RestApi($api_host, $api_key);
$arParams = array( $arParams = array(
'optionsOrderTypes' => $optionsOrderTypes, 'optionsOrderTypes' => $optionsOrderTypes,
'optionsDelivTypes' => $optionsDelivTypes, 'optionsDelivTypes' => $optionsDelivTypes,
'optionsPayTypes' => $optionsPayTypes, 'optionsPayTypes' => $optionsPayTypes,
'optionsPayStatuses' => $optionsPayStatuses, 'optionsPayStatuses' => $optionsPayStatuses,
'optionsPayment' => $optionsPayment, 'optionsPayment' => $optionsPayment,
'optionSites' => $optionsSites, 'optionSites' => $optionsSites,
'optionsOrderProps' => $optionsOrderProps 'optionsOrderProps' => $optionsOrderProps
); );
//packmode if (!$failed) {
$orderCount = 0; //packmode
while ($arOrder = $dbOrder->GetNext()) { // here orders by id asc $orderCount = 0;
if(is_array($optionsSites)) while ($arOrder = $dbOrder->GetNext()) { // here orders by id asc
if(!empty($optionsSites)) if (is_array($optionsSites))
if(!in_array($arOrder['LID'], $optionsSites)) if (!empty($optionsSites))
continue; if (!in_array($arOrder['LID'], $optionsSites))
continue;
$result = self::orderCreate($arOrder, $api, $arParams); $result = self::orderCreate($arOrder, $api, $arParams);
if (!$result['order'] || !$result['customer']) if (!$result['order'] || !$result['customer'])
continue; continue;
$orderCount++; $orderCount++;
$resOrders[] = $result['order']; $resOrders[] = $result['order'];
$resCustomers[] = $result['customer']; $resCustomers[] = $result['customer'];
$lastOrderId = $arOrder['ID']; $lastOrderId = $arOrder['ID'];
if($orderCount >= $pSize) { if ($orderCount >= $pSize) {
$customers = $api->customerUpload($resCustomers);
// error pushing customers
if ($api->getStatusCode() != 201) {
//handle err
//self::eventLog('ICrmOrderActions::uploadOrders', 'IntaroCrm\RestApi::customerUpload', $api->getLastError());
if ($api->getStatusCode() != 460) // some orders were sent
return false; // in pack mode return errors
}
$orders = $api->orderUpload($resOrders);
// error pushing orders
if ($api->getStatusCode() != 201) {
//handle err
self::eventLog('ICrmOrderActions::uploadOrders', 'IntaroCrm\RestApi::orderUpload', $api->getLastError());
if ($api->getStatusCode() != 460) // some orders were sent
return false; // in pack mode return errors
}
if ($lastOrderId)
COption::SetOptionString(self::$MODULE_ID, self::$CRM_ORDER_LAST_ID, $lastOrderId);
return true; // end of pack
}
}
if (!empty($resOrders)) {
$customers = $api->customerUpload($resCustomers); $customers = $api->customerUpload($resCustomers);
// error pushing customers // error pushing customers
if ($api->getStatusCode() != 201) { if ($api->getStatusCode() != 201) {
//handle err //handle err
//self::eventLog('ICrmOrderActions::uploadOrders', 'IntaroCrm\RestApi::customerUpload', $api->getLastError()); //self::eventLog('ICrmOrderActions::uploadOrders', 'IntaroCrm\RestApi::customerUpload', $api->getLastError());
if($api->getStatusCode() != 460) // some orders were sent if ($api->getStatusCode() != 460) // some orders were sent
return false; // in pack mode return errors return false; // in pack mode return errors
} }
$orders = $api->orderUpload($resOrders); $orders = $api->orderUpload($resOrders);
@ -114,42 +151,98 @@ class ICrmOrderActions
//handle err //handle err
self::eventLog('ICrmOrderActions::uploadOrders', 'IntaroCrm\RestApi::orderUpload', $api->getLastError()); self::eventLog('ICrmOrderActions::uploadOrders', 'IntaroCrm\RestApi::orderUpload', $api->getLastError());
if($api->getStatusCode() != 460) // some orders were sent if ($api->getStatusCode() != 460) // some orders were sent
return false; // in pack mode return errors
}
}
if ($lastOrderId)
COption::SetOptionString(self::$MODULE_ID, self::$CRM_ORDER_LAST_ID, $lastOrderId);
} else {
// failed orders upload
$orderCount = 0;
$recOrders = array();
while ($arOrder = $dbFailedOrder->GetNext()) { // here orders by id asc
if (is_array($optionsSites))
if (!empty($optionsSites))
if (!in_array($arOrder['LID'], $optionsSites))
continue;
$result = self::orderCreate($arOrder, $api, $arParams);
if (!$result['order'] || !$result['customer'])
continue;
$orderCount++;
$resOrders[] = $result['order'];
$resCustomers[] = $result['customer'];
$recOrders[] = $arOrder['ID'];
if ($orderCount >= $pSize) {
$customers = $api->customerUpload($resCustomers);
// error pushing customers
if ($api->getStatusCode() != 201) {
//handle err
//self::eventLog('ICrmOrderActions::uploadOrders', 'IntaroCrm\RestApi::customerUpload', $api->getLastError());
if ($api->getStatusCode() != 460) // some orders were sent
return false; // in pack mode return errors
}
$orders = $api->orderUpload($resOrders);
// error pushing orders
if ($api->getStatusCode() != 201) {
//handle err
self::eventLog('ICrmOrderActions::uploadOrders', 'IntaroCrm\RestApi::orderUpload', $api->getLastError());
if ($api->getStatusCode() != 460) // some orders were sent
return false; // in pack mode return errors
}
if (!empty($recOrders)) {
$failedIds = array_merge(array_diff($failedIds, $recOrders)); // clear success ids
COption::SetOptionString(self::$MODULE_ID, self::$CRM_ORDER_FAILED_IDS, serialize($failedIds));
}
return true; // end of pack
}
}
if (!empty($resOrders)) {
$customers = $api->customerUpload($resCustomers);
// error pushing customers
if ($api->getStatusCode() != 201) {
//handle err
//self::eventLog('ICrmOrderActions::uploadOrders', 'IntaroCrm\RestApi::customerUpload', $api->getLastError());
if ($api->getStatusCode() != 460) // some orders were sent
return false; // in pack mode return errors return false; // in pack mode return errors
} }
if($lastOrderId) $orders = $api->orderUpload($resOrders);
COption::SetOptionString(self::$MODULE_ID, self::$CRM_ORDER_LAST_ID, $lastOrderId);
return true; // end of pack // error pushing orders
if ($api->getStatusCode() != 201) {
//handle err
self::eventLog('ICrmOrderActions::uploadOrders', 'IntaroCrm\RestApi::orderUpload', $api->getLastError());
if ($api->getStatusCode() != 460) // some orders were sent
return false; // in pack mode return errors
}
}
if (!empty($recOrders)) {
$failedIds = array_merge(array_diff($failedIds, $recOrders)); // clear success ids
COption::SetOptionString(self::$MODULE_ID, self::$CRM_ORDER_FAILED_IDS, serialize($failedIds));
} }
} }
if (!empty($resOrders)) {
$customers = $api->customerUpload($resCustomers);
// error pushing customers
if ($api->getStatusCode() != 201) {
//handle err
//self::eventLog('ICrmOrderActions::uploadOrders', 'IntaroCrm\RestApi::customerUpload', $api->getLastError());
if ($api->getStatusCode() != 460) // some orders were sent
return false; // in pack mode return errors
}
$orders = $api->orderUpload($resOrders);
// error pushing orders
if ($api->getStatusCode() != 201) {
//handle err
self::eventLog('ICrmOrderActions::uploadOrders', 'IntaroCrm\RestApi::orderUpload', $api->getLastError());
if ($api->getStatusCode() != 460) // some orders were sent
return false; // in pack mode return errors
}
}
if($lastOrderId)
COption::SetOptionString(self::$MODULE_ID, self::$CRM_ORDER_LAST_ID, $lastOrderId);
return true; //all ok! return true; //all ok!
} }
@ -249,7 +342,9 @@ class ICrmOrderActions
if(isset($order['customer']) && $order['customer']) $userId = $order['customer']; if(isset($order['customer']) && $order['customer']) $userId = $order['customer'];
$LID = $arFields['LID']; $LID = $arFields['LID'];
$rsOrderProps = CSaleOrderPropsValue::GetList(array(), array('ORDER_ID' => $arFields['ID'])); $rsOrderProps = CSaleOrderPropsValue::GetList(array(), array('ORDER_ID' => $arFields['ID']));
while ($ar = $rsOrderProps->Fetch()) { while ($ar = $rsOrderProps->Fetch()) {
if (isset($order['deliveryAddress']) && $order['deliveryAddress']) { if (isset($order['deliveryAddress']) && $order['deliveryAddress']) {
switch ($ar['CODE']) { switch ($ar['CODE']) {
@ -406,19 +501,23 @@ class ICrmOrderActions
// orderUpdate // orderUpdate
$arFields = self::clearArr(array( $arFields = self::clearArr(array(
'PRICE_DELIVERY' => $order['deliveryCost'], 'PRICE_DELIVERY' => $order['deliveryCost'],
'PRICE' => $order['summ'], 'PRICE' => $order['summ'],
'DATE_MARKED' => $order['markDatetime'], 'DATE_MARKED' => $order['markDatetime'],
'USER_ID' => $userId, //$order['customer'] 'USER_ID' => $userId, //$order['customer']
'PAY_SYSTEM_ID' => $optionsPayTypes[$order['paymentType']], 'PAY_SYSTEM_ID' => $optionsPayTypes[$order['paymentType']],
'PAYED' => $optionsPayment[$order['paymentStatus']], 'PAYED' => $optionsPayment[$order['paymentStatus']],
'PERSON_TYPE_ID' => $optionsOrderTypes[$order['orderType']], //'PERSON_TYPE_ID' => $optionsOrderTypes[$order['orderType']],
'DELIVERY_ID' => $optionsDelivTypes[$order['deliveryType']], 'DELIVERY_ID' => $optionsDelivTypes[$order['deliveryType']],
'STATUS_ID' => $optionsPayStatuses[$order['status']] 'STATUS_ID' => $optionsPayStatuses[$order['status']],
'REASON_CANCELED' => $order['statusComment'],
'USER_DESCRIPTION' => $order['customerComment'],
'COMMENTS' => $order['managerComment']
)); ));
CSaleOrder::Update($order['externalId'], $arFields); $GLOBALS['INTARO_CRM_FROM_HISTORY'] = true;
CSaleOrder::Update($order['externalId'], $arFields);
} }
} }
@ -450,6 +549,10 @@ class ICrmOrderActions
public static function uploadOrdersAgent() { public static function uploadOrdersAgent() {
self::uploadOrders(); self::uploadOrders();
$failedIds = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_ORDER_FAILED_IDS, 0));
if(is_array($failedIds) && !empty($failedIds))
self::uploadOrders(50, true); // upload failed orders
return 'ICrmOrderActions::uploadOrdersAgent();'; return 'ICrmOrderActions::uploadOrdersAgent();';
} }
@ -548,46 +651,46 @@ class ICrmOrderActions
$rsOrderProps = CSaleOrderPropsValue::GetList(array(), array('ORDER_ID' => $arFields['ID'])); $rsOrderProps = CSaleOrderPropsValue::GetList(array(), array('ORDER_ID' => $arFields['ID']));
while ($ar = $rsOrderProps->Fetch()) { while ($ar = $rsOrderProps->Fetch()) {
switch ($ar['CODE']) { 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; break;
case 'CITY': $resOrderDeliveryAddress['city'] = self::toJSON($ar['VALUE']); case 'CITY': $resOrderDeliveryAddress['city'] = self::toJSON($ar['VALUE']);
break; 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; break;
case 'LOCATION': if(!isset($resOrderDeliveryAddress['city']) && !$resOrderDeliveryAddress['city']) { case 'LOCATION': if(!isset($resOrderDeliveryAddress['city']) && !$resOrderDeliveryAddress['city']) {
$resOrderDeliveryAddress['city'] = CSaleLocation::GetByID($ar['VALUE']); $resOrderDeliveryAddress['city'] = CSaleLocation::GetByID($ar['VALUE']);
$resOrderDeliveryAddress['city'] = self::toJSON($resOrderDeliveryAddress['city']['CITY_NAME_LANG']); $resOrderDeliveryAddress['city'] = self::toJSON($resOrderDeliveryAddress['city']['CITY_NAME_LANG']);
} }
break; break;
case $arParams['optionsOrderProps']['fio']: $contactNameArr = self::explodeFIO($ar['VALUE']); case $arParams['optionsOrderProps'][$arFields['PERSON_TYPE_ID']]['fio']: $contactNameArr = self::explodeFIO($ar['VALUE']);
break; break;
case $arParams['optionsOrderProps']['phone']: $resOrder['phone'] = $ar['VALUE']; case $arParams['optionsOrderProps'][$arFields['PERSON_TYPE_ID']]['phone']: $resOrder['phone'] = $ar['VALUE'];
break; break;
case $arParams['optionsOrderProps']['email']: $resOrder['email'] = $ar['VALUE']; case $arParams['optionsOrderProps'][$arFields['PERSON_TYPE_ID']]['email']: $resOrder['email'] = $ar['VALUE'];
break; break;
} }
if (count($arParams['optionsOrderProps'] > 5)) { if (count($arParams['optionsOrderProps'][$arFields['PERSON_TYPE_ID']] > 5)) {
switch ($ar['CODE']) { 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; 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; 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; */ 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; 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; 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; 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; 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; 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; 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; break;
} }
} }
@ -624,6 +727,7 @@ class ICrmOrderActions
$createdAt = $createdAt->format('Y-m-d H:i:s'); $createdAt = $createdAt->format('Y-m-d H:i:s');
$resOrder = array( $resOrder = array(
'number' => $arFields['ACCOUNT_NUMBER'],
'phone' => $resOrder['phone'], 'phone' => $resOrder['phone'],
'email' => $resOrder['email'], 'email' => $resOrder['email'],
'deliveryCost' => $arFields['PRICE_DELIVERY'], 'deliveryCost' => $arFields['PRICE_DELIVERY'],
@ -636,7 +740,9 @@ class ICrmOrderActions
'orderType' => $arParams['optionsOrderTypes'][$arFields['PERSON_TYPE_ID']], 'orderType' => $arParams['optionsOrderTypes'][$arFields['PERSON_TYPE_ID']],
'deliveryType' => $arParams['optionsDelivTypes'][$resultDeliveryTypeId], 'deliveryType' => $arParams['optionsDelivTypes'][$resultDeliveryTypeId],
'status' => $arParams['optionsPayStatuses'][$arFields['STATUS_ID']], 'status' => $arParams['optionsPayStatuses'][$arFields['STATUS_ID']],
'statusComment' => $arFields['USER_DESCRIPTION'], 'statusComment' => $arFields['REASON_CANCELED'],
'customerComment' => $arFields['USER_DESCRIPTION'],
'managerComment' => $arFields['COMMENTS'],
'createdAt' => $createdAt, 'createdAt' => $createdAt,
'deliveryAddress' => $resOrderDeliveryAddress, 'deliveryAddress' => $resOrderDeliveryAddress,
'items' => $items 'items' => $items
@ -658,8 +764,6 @@ class ICrmOrderActions
$resOrder = self::clearArr($resOrder); $resOrder = self::clearArr($resOrder);
self::eventLog('ICrmOrderActions::orderHistory', 'iblock', json_encode($resOrder));
if($send) if($send)
return $api->orderEdit($resOrder); return $api->orderEdit($resOrder);
@ -749,4 +853,19 @@ class ICrmOrderActions
)); ));
} }
} }
public static function getLocationCityId($cityName) {
if(!$cityName)
return;
$dbLocation = CSaleLocation::GetList(
array(
"SORT" => "ASC",
"CITY_NAME_LANG" => "ASC"
),
array("LID" => "ru", "CITY_NAME" => $cityName), false, false, array());
if($location = $dbLocation->Fetch())
return $location['ID'];
}
} }

View File

@ -13,6 +13,18 @@ class ICrmOrderEvent {
protected static $CRM_PAYMENT_STATUSES = 'pay_statuses_arr'; protected static $CRM_PAYMENT_STATUSES = 'pay_statuses_arr';
protected static $CRM_PAYMENT = 'payment_arr'; //order payment Y/N protected static $CRM_PAYMENT = 'payment_arr'; //order payment Y/N
protected static $CRM_ORDER_LAST_ID = 'order_last_id'; protected static $CRM_ORDER_LAST_ID = 'order_last_id';
protected static $CRM_ORDER_PROPS = 'order_props';
protected static $CRM_ORDER_FAILED_IDS = 'order_failed_ids';
/**
* onBeforeOrderAdd
*
* @param mixed $arFields - Order arFields
*/
function onBeforeOrderAdd($arFields = array()) {
$GLOBALS['INTARO_CRM_ORDER_ADD'] = true;
return;
}
/** /**
* onUpdateOrder * onUpdateOrder
@ -20,8 +32,18 @@ class ICrmOrderEvent {
* @param mixed $ID - Order id * @param mixed $ID - Order id
* @param mixed $arFields - Order arFields * @param mixed $arFields - Order arFields
*/ */
function onUpdateOrder($ID, $arFields = array()) { function onUpdateOrder($ID, $arFields) {
self::writeDataOnOrderCreate($ID);
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;
if(isset($arFields['LOCKED_BY']) && $arFields['LOCKED_BY'])
return;
self::writeDataOnOrderCreate($ID, $arFields);
} }
@ -34,7 +56,17 @@ class ICrmOrderEvent {
* @param mixed $arFields - Order arFields for sending template * @param mixed $arFields - Order arFields for sending template
*/ */
function onSendOrderMail($ID, &$eventName, &$arFields) { function onSendOrderMail($ID, &$eventName, &$arFields) {
self::writeDataOnOrderCreate($ID); if(self::writeDataOnOrderCreate($ID))
COption::SetOptionString(self::$MODULE_ID, self::$CRM_ORDER_LAST_ID, $ID);
else {
$failedIds = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_ORDER_FAILED_IDS, 0));
if(!$failedIds)
$failedIds = array();
$failedIds[] = $ID;
COption::SetOptionString(self::$MODULE_ID, self::$CRM_ORDER_FAILED_IDS, serialize($failedIds));
}
} }
/** /**
@ -42,7 +74,8 @@ class ICrmOrderEvent {
* *
* @param integer $ID - Order Id * @param integer $ID - Order Id
*/ */
function writeDataOnOrderCreate($ID) { function writeDataOnOrderCreate($ID, $arFields) {
if (!CModule::IncludeModule('iblock')) { if (!CModule::IncludeModule('iblock')) {
//handle err //handle err
ICrmOrderActions::eventLog('ICrmOrderEvent::writeDataOnOrderCreate', 'iblock', 'module not found'); ICrmOrderActions::eventLog('ICrmOrderEvent::writeDataOnOrderCreate', 'iblock', 'module not found');
@ -61,6 +94,9 @@ class ICrmOrderEvent {
return true; 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_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); $api_key = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_KEY_OPTION, 0);
@ -70,27 +106,43 @@ class ICrmOrderEvent {
$optionsPayTypes = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT_TYPES, 0)); $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 $optionsPayStatuses = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT_STATUSES, 0)); // --statuses
$optionsPayment = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT, 0)); $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); $api = new IntaroCrm\RestApi($api_host, $api_key);
$arParams = array( $arParams = ICrmOrderActions::clearArr(array(
'optionsOrderTypes' => $optionsOrderTypes, 'optionsOrderTypes' => $optionsOrderTypes,
'optionsDelivTypes' => $optionsDelivTypes, 'optionsDelivTypes' => $optionsDelivTypes,
'optionsPayTypes' => $optionsPayTypes, 'optionsPayTypes' => $optionsPayTypes,
'optionsPayStatuses' => $optionsPayStatuses, 'optionsPayStatuses' => $optionsPayStatuses,
'optionsPayment' => $optionsPayment 'optionsPayment' => $optionsPayment,
); 'optionsOrderProps' => $optionsOrderProps
));
$arOrder = CSaleOrder::GetById($ID); $arOrder = CSaleOrder::GetById($ID);
if (is_array($arFields) && !empty($arFields)) {
$arFieldsNew = array(
'USER_ID' => $arOrder['USER_ID'],
'ID' => $ID,
'PERSON_TYPE_ID' => $arOrder['PERSON_TYPE_ID'],
'CANCELED' => $arOrder['CANCELED'],
'STATUS_ID' => $arOrder['STATUS_ID'],
'DATE_INSERT' => $arOrder['DATE_INSERT'],
'LID' => $arOrder['LID']
);
$arFieldsNew = array_merge($arFieldsNew, $arFields);
$arOrder = $arFieldsNew;
}
$result = ICrmOrderActions::orderCreate($arOrder, $api, $arParams, true); $result = ICrmOrderActions::orderCreate($arOrder, $api, $arParams, true);
if(!$result) { if(!$result) {
ICrmOrderActions::eventLog('ICrmOrderEvent::writeDataOnOrderCreate', 'ICrmOrderActions::orderCreate', 'error during creating order'); ICrmOrderActions::eventLog('ICrmOrderEvent::writeDataOnOrderCreate', 'ICrmOrderActions::orderCreate', 'error during creating order');
return true; return false;
} }
COption::SetOptionString(self::$MODULE_ID, self::$CRM_ORDER_LAST_ID, $ID);
return true; return true;
} }
@ -189,6 +241,7 @@ class ICrmOrderEvent {
$api->orderEdit($order); $api->orderEdit($order);
// error pushing order // error pushing order
if ($api->getStatusCode() != 201) if ($api->getStatusCode() != 201)
ICrmOrderActions::eventLog('ICrmOrderEvent::onSalePayOrder', 'IntaroCrm\RestApi::orderEdit', $api->getLastError()); ICrmOrderActions::eventLog('ICrmOrderEvent::onSalePayOrder', 'IntaroCrm\RestApi::orderEdit', $api->getLastError());

View File

@ -33,6 +33,7 @@ class intaro_intarocrm extends CModule {
var $CRM_ORDER_SITES = 'sites_ids'; var $CRM_ORDER_SITES = 'sites_ids';
var $CRM_ORDER_PROPS = 'order_props'; var $CRM_ORDER_PROPS = 'order_props';
var $CRM_ORDER_DISCHARGE = 'order_discharge'; var $CRM_ORDER_DISCHARGE = 'order_discharge';
var $CRM_ORDER_FAILED_IDS = 'order_failed_ids';
var $INSTALL_PATH; var $INSTALL_PATH;
function intaro_intarocrm() { function intaro_intarocrm() {
@ -77,27 +78,19 @@ class intaro_intarocrm extends CModule {
$arResult['orderProps'] = array( $arResult['orderProps'] = array(
array( array(
'NAME' => GetMessage('FIO'), 'NAME' => GetMessage('FIO'),
'ID' => 'fio' 'ID' => 'fio'
),
array(
'NAME' => GetMessage('ZIP'),
'ID' => 'index'
), ),
array( array(
'NAME' => GetMessage('PHONE'), 'NAME' => GetMessage('PHONE'),
'ID' => 'phone' 'ID' => 'phone'
), ),
array( array(
'NAME' => GetMessage('EMAIL'), 'NAME' => GetMessage('EMAIL'),
'ID' => 'email' 'ID' => 'email'
),
array(
'NAME' => GetMessage('ZIP'),
'ID' => 'index'
), ),
array( array(
'NAME' => GetMessage('ADDRESS'), 'NAME' => GetMessage('ADDRESS'),
'ID' => 'text' 'ID' => 'text'
), ),
// address // address
/* array( /* array(
@ -114,35 +107,35 @@ class intaro_intarocrm extends CModule {
), */ ), */
array( array(
'NAME' => GetMessage('ZIP'), 'NAME' => GetMessage('ZIP'),
'ID' => 'index' 'ID' => 'index'
), ),
array( array(
'NAME' => GetMessage('STREET'), 'NAME' => GetMessage('STREET'),
'ID' => 'street' 'ID' => 'street'
), ),
array( array(
'NAME' => GetMessage('BUILDING'), 'NAME' => GetMessage('BUILDING'),
'ID' => 'building' 'ID' => 'building'
), ),
array( array(
'NAME' => GetMessage('FLAT'), 'NAME' => GetMessage('FLAT'),
'ID' => 'flat' 'ID' => 'flat'
), ),
array( array(
'NAME' => GetMessage('INTERCOMCODE'), 'NAME' => GetMessage('INTERCOMCODE'),
'ID' => 'intercomcode' 'ID' => 'intercomcode'
), ),
array( array(
'NAME' => GetMessage('FLOOR'), 'NAME' => GetMessage('FLOOR'),
'ID' => 'floor' 'ID' => 'floor'
), ),
array( array(
'NAME' => GetMessage('BLOCK'), 'NAME' => GetMessage('BLOCK'),
'ID' => 'block' 'ID' => 'block'
), ),
array( array(
'NAME' => GetMessage('HOUSE'), 'NAME' => GetMessage('HOUSE'),
'ID' => 'house' 'ID' => 'house'
) )
); );
@ -698,7 +691,7 @@ class intaro_intarocrm extends CModule {
//form orderProps //form orderProps
$dbProp = CSaleOrderProps::GetList(array(), array()); $dbProp = CSaleOrderProps::GetList(array(), array());
while ($arProp = $dbProp->GetNext()) { while ($arProp = $dbProp->GetNext()) {
$arResult['arProp'][] = $arProp; $arResult['arProp'][$arProp['PERSON_TYPE_ID']][] = $arProp;
} }
COption::SetOptionString($this->MODULE_ID, $this->CRM_ORDER_TYPES_ARR, serialize($orderTypesArr)); COption::SetOptionString($this->MODULE_ID, $this->CRM_ORDER_TYPES_ARR, serialize($orderTypesArr));
@ -708,6 +701,7 @@ class intaro_intarocrm extends CModule {
COption::SetOptionString($this->MODULE_ID, $this->CRM_PAYMENT, serialize($paymentArr)); COption::SetOptionString($this->MODULE_ID, $this->CRM_PAYMENT, serialize($paymentArr));
COption::SetOptionString($this->MODULE_ID, $this->CRM_ORDER_LAST_ID, 0); COption::SetOptionString($this->MODULE_ID, $this->CRM_ORDER_LAST_ID, 0);
COption::SetOptionString($this->MODULE_ID, $this->CRM_ORDER_DISCHARGE, 0); COption::SetOptionString($this->MODULE_ID, $this->CRM_ORDER_DISCHARGE, 0);
COption::SetOptionString($this->MODULE_ID, $this->CRM_ORDER_FAILED_IDS, serialize(array()));
$APPLICATION->IncludeAdminFile( $APPLICATION->IncludeAdminFile(
GetMessage('MODULE_INSTALL_TITLE'), GetMessage('MODULE_INSTALL_TITLE'),
@ -772,7 +766,7 @@ class intaro_intarocrm extends CModule {
$propsCount = 0; $propsCount = 0;
$_orderPropsArr = array(); $_orderPropsArr = array();
foreach ($arResult['orderProps'] as $orderProp) { foreach ($arResult['orderProps'] as $orderProp) {
if ((!(int) htmlspecialchars(trim($_POST['address-detail-' . $orderType['ID']]))) && $propsCount > 5) if ((!(int) htmlspecialchars(trim($_POST['address-detail-' . $orderType['ID']]))) && $propsCount > 4)
break; break;
$_orderPropsArr[$orderProp['ID']] = htmlspecialchars(trim($_POST['order-prop-' . $orderProp['ID'] . '-' . $orderType['ID']])); $_orderPropsArr[$orderProp['ID']] = htmlspecialchars(trim($_POST['order-prop-' . $orderProp['ID'] . '-' . $orderType['ID']]));
$propsCount++; $propsCount++;
@ -879,6 +873,7 @@ class intaro_intarocrm extends CModule {
} }
RegisterModule($this->MODULE_ID); RegisterModule($this->MODULE_ID);
RegisterModuleDependences("sale", "OnSalePayOrder", $this->MODULE_ID, "ICrmOrderEvent", "onSalePayOrder");
RegisterModuleDependences("sale", "OnSaleCancelOrder", $this->MODULE_ID, "ICrmOrderEvent", "onSaleCancelOrder"); RegisterModuleDependences("sale", "OnSaleCancelOrder", $this->MODULE_ID, "ICrmOrderEvent", "onSaleCancelOrder");
$this->CopyFiles(); $this->CopyFiles();
if (isset($_POST['LOAD_NOW'])) { if (isset($_POST['LOAD_NOW'])) {
@ -1043,9 +1038,13 @@ class intaro_intarocrm extends CModule {
COption::RemoveOption($this->MODULE_ID, $this->CRM_ORDER_SITES); COption::RemoveOption($this->MODULE_ID, $this->CRM_ORDER_SITES);
COption::RemoveOption($this->MODULE_ID, $this->CRM_ORDER_PROPS); COption::RemoveOption($this->MODULE_ID, $this->CRM_ORDER_PROPS);
COption::RemoveOption($this->MODULE_ID, $this->CRM_ORDER_DISCHARGE); COption::RemoveOption($this->MODULE_ID, $this->CRM_ORDER_DISCHARGE);
COption::RemoveOption($this->MODULE_ID, $this->CRM_ORDER_FAILED_IDS);
UnRegisterModuleDependences("sale", "OnSalePayOrder", $this->MODULE_ID, "ICrmOrderEvent", "onSalePayOrder"); UnRegisterModuleDependences("sale", "OnSalePayOrder", $this->MODULE_ID, "ICrmOrderEvent", "onSalePayOrder");
UnRegisterModuleDependences("sale", "OnSaleCancelOrder", $this->MODULE_ID, "ICrmOrderEvent", "onSaleCancelOrder"); UnRegisterModuleDependences("sale", "OnSaleCancelOrder", $this->MODULE_ID, "ICrmOrderEvent", "onSaleCancelOrder");
UnRegisterModuleDependences("sale", "OnOrderNewSendEmail", $this->MODULE_ID, "ICrmOrderEvent", "onSendOrderMail");
UnRegisterModuleDependences("sale", "OnOrderUpdate", $this->MODULE_ID, "ICrmOrderEvent", "onUpdateOrder");
UnRegisterModuleDependences("sale", "OnBeforeOrderAdd", $this->MODULE_ID, "ICrmOrderEvent", "onBeforeOrderAdd");
if (CModule::IncludeModule("catalog")) { if (CModule::IncludeModule("catalog")) {
if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/bitrix/php_interface/include/catalog_export/' . $this->INTARO_CRM_EXPORT . '_run.php')) { if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/bitrix/php_interface/include/catalog_export/' . $this->INTARO_CRM_EXPORT . '_run.php')) {
$dbProfile = CCatalogExport::GetList(array(), array("FILE_NAME" => $this->INTARO_CRM_EXPORT)); $dbProfile = CCatalogExport::GetList(array(), array("FILE_NAME" => $this->INTARO_CRM_EXPORT));

View File

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

View File

@ -58,13 +58,12 @@ $defaultOrderProps = array(
</tr> </tr>
<?php foreach($arResult['bitrixOrderTypesList'] as $bitrixOrderType): ?> <?php foreach($arResult['bitrixOrderTypesList'] as $bitrixOrderType): ?>
<tr class="heading"> <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> </tr>
<?php $countProps = 0; foreach($arResult['orderProps'] as $orderProp): ?> <?php $countProps = 0; foreach($arResult['orderProps'] as $orderProp): ?>
<?php if($orderProp['ID'] == 'text'): ?> <?php if($orderProp['ID'] == 'text'): ?>
<tr class="heading"> <tr class="heading">
<td colspan="2"> <td colspan="2" style="background-color: transparent;">
<b> <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="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> <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>
@ -72,16 +71,16 @@ $defaultOrderProps = array(
</td> </td>
</tr> </tr>
<?php endif; ?> <?php endif; ?>
<tr <?php if ($countProps > 5) echo 'class="address-detail-' . $bitrixOrderType['ID'] . '"'; if(($countProps > 5) && (count($defaultOrderProps[$bitrixOrderType['ID']]) < 6)) echo 'style="display:none;"';?>> <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']; ?>"> <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>
<td width="50%" class="adm-detail-content-cell-r"> <td width="50%" class="adm-detail-content-cell-r">
<select name="order-prop-<?php echo $orderProp['ID'] . '-' . $bitrixOrderType['ID']; ?>" class="typeselect"> <select name="order-prop-<?php echo $orderProp['ID'] . '-' . $bitrixOrderType['ID']; ?>" class="typeselect">
<option value=""></option> <option value=""></option>
<?php foreach ($arResult['arProp'] as $arProp): ?> <?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'; ?>> <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> </option>
<?php endforeach; ?> <?php endforeach; ?>
</select> </select>

View File

@ -0,0 +1,2 @@
<?php
$MESS["ROOT_CATEGORY_FOR_CATALOG"] = "Корневой раздел для каталога \"%s\"";

View File

@ -15,7 +15,7 @@ $MESS ['ERR_ARTICLE_IBLOCK'] = 'Не установлены артикулы';
$MESS ['DATE_TIMEZONE_ERR'] = 'Не указана временная зона в настройках php.'; $MESS ['DATE_TIMEZONE_ERR'] = 'Не указана временная зона в настройках php.';
$MESS ['ORDER_PROPS'] = 'Настройки соответствия полей заказа IntaroCRM свойствам заказа 1С-Битрикс'; $MESS ['ORDER_PROPS'] = 'Настройки соответствия полей заказа IntaroCRM свойствам заказа 1С-Битрикс';
$MESS ['FIO'] = 'ф.И.О.'; $MESS ['FIO'] = 'Ф.И.О.';
$MESS ['ZIP'] = 'Индекс'; $MESS ['ZIP'] = 'Индекс';
$MESS ['ADDRESS'] = 'Адрес (строкой)'; $MESS ['ADDRESS'] = 'Адрес (строкой)';
$MESS ['PHONE'] = 'Телефон'; $MESS ['PHONE'] = 'Телефон';

View File

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

View File

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

View File

@ -32,10 +32,6 @@ $arResult['orderProps'] = array(
'NAME' => GetMessage('FIO'), 'NAME' => GetMessage('FIO'),
'ID' => 'fio' 'ID' => 'fio'
), ),
array(
'NAME' => GetMessage('ZIP'),
'ID' => 'index'
),
array( array(
'NAME' => GetMessage('PHONE'), 'NAME' => GetMessage('PHONE'),
'ID' => 'phone' 'ID' => 'phone'
@ -44,10 +40,6 @@ $arResult['orderProps'] = array(
'NAME' => GetMessage('EMAIL'), 'NAME' => GetMessage('EMAIL'),
'ID' => 'email' 'ID' => 'email'
), ),
array(
'NAME' => GetMessage('ZIP'),
'ID' => 'index'
),
array( array(
'NAME' => GetMessage('ADDRESS'), 'NAME' => GetMessage('ADDRESS'),
'ID' => 'text' 'ID' => 'text'
@ -227,36 +219,26 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
// remove depenedencies // remove depenedencies
UnRegisterModuleDependences("sale", "OnOrderNewSendEmail", $mid, "ICrmOrderEvent", "onSendOrderMail"); UnRegisterModuleDependences("sale", "OnOrderNewSendEmail", $mid, "ICrmOrderEvent", "onSendOrderMail");
UnRegisterModuleDependences("sale", "OnOrderUpdate", $mid, "ICrmOrderEvent", "onUpdateOrder"); UnRegisterModuleDependences("sale", "OnOrderUpdate", $mid, "ICrmOrderEvent", "onUpdateOrder");
// new agent UnRegisterModuleDependences("sale", "OnBeforeOrderAdd", $mid, "ICrmOrderEvent", "onBeforeOrderAdd");
$dateAgent = new DateTime();
$intAgent = new DateInterval('PT60S'); // PT60S - 60 sec;
$dateAgent->add($intAgent);
CAgent::AddAgent(
"ICrmOrderActions::uploadOrdersAgent();", $mid, "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
);
} else if (($orderDischarge != $previousDischarge) && ($orderDischarge == 1)) { } else if (($orderDischarge != $previousDischarge) && ($orderDischarge == 1)) {
// remove agent
CAgent::RemoveAgent("ICrmOrderActions::uploadOrdersAgent();", $mid);
// event dependencies // event dependencies
RegisterModuleDependences("sale", "OnOrderNewSendEmail", $mid, "ICrmOrderEvent", "onSendOrderMail"); RegisterModuleDependences("sale", "OnOrderNewSendEmail", $mid, "ICrmOrderEvent", "onSendOrderMail");
RegisterModuleDependences("sale", "OnOrderUpdate", $mid, "ICrmOrderEvent", "onUpdateOrder"); RegisterModuleDependences("sale", "OnOrderUpdate", $mid, "ICrmOrderEvent", "onUpdateOrder");
RegisterModuleDependences("sale", "OnBeforeOrderAdd", $mid, "ICrmOrderEvent", "onBeforeOrderAdd");
}
$orderPropsArr = array(); $orderPropsArr = array();
foreach ($orderTypesList as $orderType) { foreach ($orderTypesList as $orderType) {
$propsCount = 0; $propsCount = 0;
$_orderPropsArr = array(); $_orderPropsArr = array();
foreach ($arResult['orderProps'] as $orderProp) { foreach ($arResult['orderProps'] as $orderProp) {
if ((!(int) htmlspecialchars(trim($_POST['address-detail-' . $orderType['ID']]))) && $propsCount > 5) if ((!(int) htmlspecialchars(trim($_POST['address-detail-' . $orderType['ID']]))) && $propsCount > 4)
break; break;
$_orderPropsArr[$orderProp['ID']] = htmlspecialchars(trim($_POST['order-prop-' . $orderProp['ID'] . '-' . $orderType['ID']])); $_orderPropsArr[$orderProp['ID']] = htmlspecialchars(trim($_POST['order-prop-' . $orderProp['ID'] . '-' . $orderType['ID']]));
$propsCount++; $propsCount++;
}
$orderPropsArr[$orderType['ID']] = $_orderPropsArr;
} }
$orderPropsArr[$orderType['ID']] = $_orderPropsArr;
} }
COption::SetOptionString($mid, $CRM_ORDER_TYPES_ARR, serialize($orderTypesArr)); COption::SetOptionString($mid, $CRM_ORDER_TYPES_ARR, serialize($orderTypesArr));
@ -380,7 +362,7 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
$dbProp = CSaleOrderProps::GetList(array(), array()); $dbProp = CSaleOrderProps::GetList(array(), array());
while ($arProp = $dbProp->GetNext()) { while ($arProp = $dbProp->GetNext()) {
$arResult['arProp'][] = $arProp; $arResult['arProp'][$arProp['PERSON_TYPE_ID']][] = $arProp;
} }
//saved cat params //saved cat params
@ -583,13 +565,13 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
</tr> </tr>
<?php foreach($arResult['bitrixOrderTypesList'] as $bitrixOrderType): ?> <?php foreach($arResult['bitrixOrderTypesList'] as $bitrixOrderType): ?>
<tr class="heading"> <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> </tr>
<?php $countProps = 0; foreach($arResult['orderProps'] as $orderProp): ?> <?php $countProps = 0; foreach($arResult['orderProps'] as $orderProp): ?>
<?php if($orderProp['ID'] == 'text'): ?> <?php if($orderProp['ID'] == 'text'): ?>
<tr class="heading"> <tr class="heading">
<td colspan="2"> <td colspan="2" style="background-color: transparent;">
<b> <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="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> <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>
@ -597,16 +579,16 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
</td> </td>
</tr> </tr>
<?php endif; ?> <?php endif; ?>
<tr <?php if ($countProps > 5) echo 'class="address-detail-' . $bitrixOrderType['ID'] . '"'; if(($countProps > 5) && (count($optionsOrderProps[$bitrixOrderType['ID']]) < 6)) echo 'style="display:none;"';?>> <tr <?php if ($countProps > 4) echo 'class="address-detail-' . $bitrixOrderType['ID'] . '"'; if(($countProps > 4) && (count($optionsOrderProps[$bitrixOrderType['ID']]) < 6)) echo 'style="display:none;"';?>>
<td width="50%" class="adm-detail-content-cell-l" name="<?php echo $orderProp['ID']; ?>"> <td width="50%" class="adm-detail-content-cell-l" name="<?php echo $orderProp['ID']; ?>">
<?php echo $orderProp['NAME']; ?> <?php echo $orderProp['NAME']; ?>
</td> </td>
<td width="50%" class="adm-detail-content-cell-r"> <td width="50%" class="adm-detail-content-cell-r">
<select name="order-prop-<?php echo $orderProp['ID'] . '-' . $bitrixOrderType['ID']; ?>" class="typeselect"> <select name="order-prop-<?php echo $orderProp['ID'] . '-' . $bitrixOrderType['ID']; ?>" class="typeselect">
<option value=""></option> <option value=""></option>
<?php foreach ($arResult['arProp'] as $arProp): ?> <?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'; ?>> <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> </option>
<?php endforeach; ?> <?php endforeach; ?>
</select> </select>