Merge branch 'master'
Conflicts: intaro.intarocrm/classes/general/ICMLLoader.php
This commit is contained in:
commit
62bbcc0f48
@ -1,5 +1,8 @@
|
||||
<?php
|
||||
|
||||
global $MESS;
|
||||
IncludeModuleLangFile(__FILE__);
|
||||
|
||||
class ICMLLoader {
|
||||
|
||||
public $iblocks;
|
||||
@ -148,7 +151,7 @@ class ICMLLoader {
|
||||
$arRes = Array();
|
||||
$arRes['ID'] = $this->mainSection + $id;
|
||||
$arRes['IBLOCK_SECTION_ID'] = 0;
|
||||
$arRes['NAME'] = "Основной раздел каталога " . $iblock['NAME'];
|
||||
$arRes['NAME'] = sprintf(GetMessage('ROOT_CATEGORY_FOR_CATALOG'), $iblock['NAME']);
|
||||
$categories[$arRes['ID']] = $arRes;
|
||||
}
|
||||
}
|
||||
|
@ -13,12 +13,14 @@ class ICrmOrderActions
|
||||
protected static $CRM_ORDER_LAST_ID = 'order_last_id';
|
||||
protected static $CRM_ORDER_SITES = 'sites_ids';
|
||||
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
|
||||
* @param $failed -- flag to export failed orders
|
||||
* @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
|
||||
|
||||
@ -46,7 +48,12 @@ class ICrmOrderActions
|
||||
$lastUpOrderId = COption::GetOptionString(self::$MODULE_ID, self::$CRM_ORDER_LAST_ID, 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));
|
||||
$dbFailedOrder = CSaleOrder::GetList(array("ID" => "ASC"), array('ID' => $failedIds));
|
||||
|
||||
$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);
|
||||
@ -72,12 +79,13 @@ class ICrmOrderActions
|
||||
'optionsOrderProps' => $optionsOrderProps
|
||||
);
|
||||
|
||||
if (!$failed) {
|
||||
|
||||
//packmode
|
||||
|
||||
$orderCount = 0;
|
||||
|
||||
while ($arOrder = $dbOrder->GetNext()) { // here orders by id asc
|
||||
|
||||
if (is_array($optionsSites))
|
||||
if (!empty($optionsSites))
|
||||
if (!in_array($arOrder['LID'], $optionsSites))
|
||||
@ -151,6 +159,91 @@ class ICrmOrderActions
|
||||
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
|
||||
}
|
||||
|
||||
$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; //all ok!
|
||||
}
|
||||
|
||||
@ -249,7 +342,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']) {
|
||||
@ -412,13 +507,17 @@ class ICrmOrderActions
|
||||
'USER_ID' => $userId, //$order['customer']
|
||||
'PAY_SYSTEM_ID' => $optionsPayTypes[$order['paymentType']],
|
||||
'PAYED' => $optionsPayment[$order['paymentStatus']],
|
||||
'PERSON_TYPE_ID' => $optionsOrderTypes[$order['orderType']],
|
||||
//'PERSON_TYPE_ID' => $optionsOrderTypes[$order['orderType']],
|
||||
'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() {
|
||||
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();';
|
||||
}
|
||||
|
||||
@ -548,46 +651,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;
|
||||
}
|
||||
}
|
||||
@ -624,6 +727,7 @@ class ICrmOrderActions
|
||||
$createdAt = $createdAt->format('Y-m-d H:i:s');
|
||||
|
||||
$resOrder = array(
|
||||
'number' => $arFields['ACCOUNT_NUMBER'],
|
||||
'phone' => $resOrder['phone'],
|
||||
'email' => $resOrder['email'],
|
||||
'deliveryCost' => $arFields['PRICE_DELIVERY'],
|
||||
@ -636,7 +740,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
|
||||
@ -658,8 +764,6 @@ class ICrmOrderActions
|
||||
|
||||
$resOrder = self::clearArr($resOrder);
|
||||
|
||||
self::eventLog('ICrmOrderActions::orderHistory', 'iblock', json_encode($resOrder));
|
||||
|
||||
if($send)
|
||||
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'];
|
||||
}
|
||||
}
|
@ -13,6 +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';
|
||||
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
|
||||
@ -20,8 +32,18 @@ class ICrmOrderEvent {
|
||||
* @param mixed $ID - Order id
|
||||
* @param mixed $arFields - Order arFields
|
||||
*/
|
||||
function onUpdateOrder($ID, $arFields = array()) {
|
||||
self::writeDataOnOrderCreate($ID);
|
||||
function onUpdateOrder($ID, $arFields) {
|
||||
|
||||
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
|
||||
*/
|
||||
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
|
||||
*/
|
||||
function writeDataOnOrderCreate($ID) {
|
||||
function writeDataOnOrderCreate($ID, $arFields) {
|
||||
|
||||
if (!CModule::IncludeModule('iblock')) {
|
||||
//handle err
|
||||
ICrmOrderActions::eventLog('ICrmOrderEvent::writeDataOnOrderCreate', 'iblock', 'module not found');
|
||||
@ -61,6 +94,9 @@ class ICrmOrderEvent {
|
||||
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);
|
||||
|
||||
@ -70,27 +106,43 @@ 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);
|
||||
|
||||
$arParams = array(
|
||||
$arParams = ICrmOrderActions::clearArr(array(
|
||||
'optionsOrderTypes' => $optionsOrderTypes,
|
||||
'optionsDelivTypes' => $optionsDelivTypes,
|
||||
'optionsPayTypes' => $optionsPayTypes,
|
||||
'optionsPayStatuses' => $optionsPayStatuses,
|
||||
'optionsPayment' => $optionsPayment
|
||||
);
|
||||
'optionsPayment' => $optionsPayment,
|
||||
'optionsOrderProps' => $optionsOrderProps
|
||||
));
|
||||
|
||||
$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);
|
||||
|
||||
if(!$result) {
|
||||
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;
|
||||
}
|
||||
|
||||
@ -189,6 +241,7 @@ class ICrmOrderEvent {
|
||||
|
||||
$api->orderEdit($order);
|
||||
|
||||
|
||||
// error pushing order
|
||||
if ($api->getStatusCode() != 201)
|
||||
ICrmOrderActions::eventLog('ICrmOrderEvent::onSalePayOrder', 'IntaroCrm\RestApi::orderEdit', $api->getLastError());
|
||||
|
@ -33,6 +33,7 @@ class intaro_intarocrm extends CModule {
|
||||
var $CRM_ORDER_SITES = 'sites_ids';
|
||||
var $CRM_ORDER_PROPS = 'order_props';
|
||||
var $CRM_ORDER_DISCHARGE = 'order_discharge';
|
||||
var $CRM_ORDER_FAILED_IDS = 'order_failed_ids';
|
||||
var $INSTALL_PATH;
|
||||
|
||||
function intaro_intarocrm() {
|
||||
@ -79,10 +80,6 @@ class intaro_intarocrm extends CModule {
|
||||
'NAME' => GetMessage('FIO'),
|
||||
'ID' => 'fio'
|
||||
),
|
||||
array(
|
||||
'NAME' => GetMessage('ZIP'),
|
||||
'ID' => 'index'
|
||||
),
|
||||
array(
|
||||
'NAME' => GetMessage('PHONE'),
|
||||
'ID' => 'phone'
|
||||
@ -91,10 +88,6 @@ class intaro_intarocrm extends CModule {
|
||||
'NAME' => GetMessage('EMAIL'),
|
||||
'ID' => 'email'
|
||||
),
|
||||
array(
|
||||
'NAME' => GetMessage('ZIP'),
|
||||
'ID' => 'index'
|
||||
),
|
||||
array(
|
||||
'NAME' => GetMessage('ADDRESS'),
|
||||
'ID' => 'text'
|
||||
@ -698,7 +691,7 @@ class intaro_intarocrm extends CModule {
|
||||
//form orderProps
|
||||
$dbProp = CSaleOrderProps::GetList(array(), array());
|
||||
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));
|
||||
@ -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_ORDER_LAST_ID, 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(
|
||||
GetMessage('MODULE_INSTALL_TITLE'),
|
||||
@ -772,7 +766,7 @@ class intaro_intarocrm extends CModule {
|
||||
$propsCount = 0;
|
||||
$_orderPropsArr = array();
|
||||
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;
|
||||
$_orderPropsArr[$orderProp['ID']] = htmlspecialchars(trim($_POST['order-prop-' . $orderProp['ID'] . '-' . $orderType['ID']]));
|
||||
$propsCount++;
|
||||
@ -879,6 +873,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'])) {
|
||||
@ -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_PROPS);
|
||||
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", "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 (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));
|
||||
|
@ -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"> </td>
|
||||
</tr>
|
||||
|
@ -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>
|
||||
@ -72,16 +71,16 @@ $defaultOrderProps = array(
|
||||
</td>
|
||||
</tr>
|
||||
<?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']; ?>">
|
||||
<?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'] 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'; ?>>
|
||||
<?php echo $arProp['NAME']; ?>
|
||||
<?php echo $APPLICATION->ConvertCharset($arProp['NAME'], 'utf-8', SITE_CHARSET); ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
|
2
intaro.intarocrm/lang/ru/classes/general/ICMLLoader.php
Normal file
2
intaro.intarocrm/lang/ru/classes/general/ICMLLoader.php
Normal file
@ -0,0 +1,2 @@
|
||||
<?php
|
||||
$MESS["ROOT_CATEGORY_FOR_CATALOG"] = "Корневой раздел для каталога \"%s\"";
|
@ -15,7 +15,7 @@ $MESS ['ERR_ARTICLE_IBLOCK'] = 'Не установлены артикулы';
|
||||
$MESS ['DATE_TIMEZONE_ERR'] = 'Не указана временная зона в настройках php.';
|
||||
|
||||
$MESS ['ORDER_PROPS'] = 'Настройки соответствия полей заказа IntaroCRM свойствам заказа 1С-Битрикс';
|
||||
$MESS ['FIO'] = 'ф.И.О.';
|
||||
$MESS ['FIO'] = 'Ф.И.О.';
|
||||
$MESS ['ZIP'] = 'Индекс';
|
||||
$MESS ['ADDRESS'] = 'Адрес (строкой)';
|
||||
$MESS ['PHONE'] = 'Телефон';
|
||||
|
@ -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'] = 'Ф.И.О.';
|
||||
|
@ -51,3 +51,5 @@ $MESS ['BLOCK'] = 'Подъезд';
|
||||
$MESS ['HOUSE'] = 'Строение / корпус';
|
||||
$MESS ['ADDRESS_SHORT'] = 'Краткий адрес';
|
||||
$MESS ['ADDRESS_FULL'] = 'Детальный адрес';
|
||||
|
||||
$MESS ['ORDER_TYPE_INFO'] = 'Тип заказа:';
|
@ -32,10 +32,6 @@ $arResult['orderProps'] = array(
|
||||
'NAME' => GetMessage('FIO'),
|
||||
'ID' => 'fio'
|
||||
),
|
||||
array(
|
||||
'NAME' => GetMessage('ZIP'),
|
||||
'ID' => 'index'
|
||||
),
|
||||
array(
|
||||
'NAME' => GetMessage('PHONE'),
|
||||
'ID' => 'phone'
|
||||
@ -44,10 +40,6 @@ $arResult['orderProps'] = array(
|
||||
'NAME' => GetMessage('EMAIL'),
|
||||
'ID' => 'email'
|
||||
),
|
||||
array(
|
||||
'NAME' => GetMessage('ZIP'),
|
||||
'ID' => 'index'
|
||||
),
|
||||
array(
|
||||
'NAME' => GetMessage('ADDRESS'),
|
||||
'ID' => 'text'
|
||||
@ -227,37 +219,27 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
|
||||
// remove depenedencies
|
||||
UnRegisterModuleDependences("sale", "OnOrderNewSendEmail", $mid, "ICrmOrderEvent", "onSendOrderMail");
|
||||
UnRegisterModuleDependences("sale", "OnOrderUpdate", $mid, "ICrmOrderEvent", "onUpdateOrder");
|
||||
// new agent
|
||||
$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
|
||||
);
|
||||
UnRegisterModuleDependences("sale", "OnBeforeOrderAdd", $mid, "ICrmOrderEvent", "onBeforeOrderAdd");
|
||||
|
||||
} else if (($orderDischarge != $previousDischarge) && ($orderDischarge == 1)) {
|
||||
// remove agent
|
||||
CAgent::RemoveAgent("ICrmOrderActions::uploadOrdersAgent();", $mid);
|
||||
// event dependencies
|
||||
RegisterModuleDependences("sale", "OnOrderNewSendEmail", $mid, "ICrmOrderEvent", "onSendOrderMail");
|
||||
RegisterModuleDependences("sale", "OnOrderUpdate", $mid, "ICrmOrderEvent", "onUpdateOrder");
|
||||
RegisterModuleDependences("sale", "OnBeforeOrderAdd", $mid, "ICrmOrderEvent", "onBeforeOrderAdd");
|
||||
}
|
||||
|
||||
$orderPropsArr = array();
|
||||
foreach ($orderTypesList as $orderType) {
|
||||
$propsCount = 0;
|
||||
$_orderPropsArr = array();
|
||||
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;
|
||||
$_orderPropsArr[$orderProp['ID']] = htmlspecialchars(trim($_POST['order-prop-' . $orderProp['ID'] . '-' . $orderType['ID']]));
|
||||
$propsCount++;
|
||||
}
|
||||
$orderPropsArr[$orderType['ID']] = $_orderPropsArr;
|
||||
}
|
||||
}
|
||||
|
||||
COption::SetOptionString($mid, $CRM_ORDER_TYPES_ARR, serialize($orderTypesArr));
|
||||
COption::SetOptionString($mid, $CRM_DELIVERY_TYPES_ARR, serialize($deliveryTypesArr));
|
||||
@ -380,7 +362,7 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
|
||||
|
||||
$dbProp = CSaleOrderProps::GetList(array(), array());
|
||||
while ($arProp = $dbProp->GetNext()) {
|
||||
$arResult['arProp'][] = $arProp;
|
||||
$arResult['arProp'][$arProp['PERSON_TYPE_ID']][] = $arProp;
|
||||
}
|
||||
|
||||
//saved cat params
|
||||
@ -583,13 +565,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>
|
||||
@ -597,16 +579,16 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
|
||||
</td>
|
||||
</tr>
|
||||
<?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']; ?>">
|
||||
<?php echo $orderProp['NAME']; ?>
|
||||
</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'] 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'; ?>>
|
||||
<?php echo $arProp['NAME']; ?>
|
||||
<?php echo $APPLICATION->ConvertCharset($arProp['NAME'], 'utf-8', SITE_CHARSET); ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
|
Loading…
Reference in New Issue
Block a user