1
0
mirror of synced 2024-11-22 05:16:09 +03:00

+orderAgent(); +reserveOrderEvents; +basePrice selection on export; +event intarocrm_before_order_send; +fix issues with incorrect order status changing.

This commit is contained in:
Grisha Pomadchin 2014-06-20 16:03:46 +04:00
parent c4ce5da2fe
commit 400e8c4958
9 changed files with 152 additions and 48 deletions

View File

@ -25,6 +25,8 @@ class ICMLLoader {
protected $logFile = '/bitrix/catalog_export/i_crm_load_log.txt';
protected $fpLog;
protected $MODULE_ID = 'intaro.intarocrm';
protected $CRM_CATALOG_BASE_PRICE = 'catalog_base_price';
protected $measurement = array (
'mm' => 1, // 1 mm = 1 mm
@ -218,6 +220,10 @@ class ICMLLoader {
protected function BuildOffers(&$allCategories)
{
$basePriceId = COption::GetOptionString($this->MODULE_ID, $this->CRM_CATALOG_BASE_PRICE, 1);
foreach ($this->iblocks as $key => $id)
{
// Get Info by infoblocks
@ -238,7 +244,7 @@ class ICMLLoader {
"DETAIL_PICTURE",
"LANG_DIR",
"DETAIL_PAGE_URL",
"CATALOG_GROUP_1"
"CATALOG_GROUP_" . $basePriceId
);
// Set selected properties
foreach ($this->propertiesProduct[$id] as $key => $propProduct) {
@ -256,7 +262,7 @@ class ICMLLoader {
"DETAIL_PAGE_URL",
"DETAIL_PICTURE",
'PROPERTY_' . $iblockOffer['SKU_PROPERTY_ID'],
"CATALOG_GROUP_1"
"CATALOG_GROUP_" . $basePriceId
);
// Set selected properties
foreach ($this->propertiesSKU[$id] as $key => $propSKU) {
@ -394,7 +400,7 @@ class ICMLLoader {
$offer['PICTURE'] = $product["PICTURE"];
$offer['PRODUCT_NAME'] = $product["NAME"];
$offer['PRODUCT_ACTIVE'] = $product["ACTIVE"];
$offer['PRICE'] = $offer['CATALOG_PRICE_1'];
$offer['PRICE'] = $offer['CATALOG_PRICE_' . $basePriceId];
$offer['PURCHASE_PRICE'] = $offer['CATALOG_PURCHASING_PRICE'];
$offer['QUANTITY'] = $offer["CATALOG_QUANTITY"];

View File

@ -600,7 +600,7 @@ class ICrmOrderActions
if(isset($order['externalId']) && $order['externalId']) {
// custom orderType functunion
// custom orderType function
if(function_exists('intarocrm_set_order_type')) {
$orderType = intarocrm_set_order_type($order);
if($orderType)
@ -969,22 +969,23 @@ class ICrmOrderActions
'COMMENTS' => self::fromJSON($order['managerComment'])
));
CSaleOrder::Update($order['externalId'], $arFields);
if(!empty($arFields))
CSaleOrder::Update($order['externalId'], $arFields);
// set STATUS_ID
if($order['status'] && $optionsPayStatuses[$order['status']])
if(isset($order['status']) && $order['status'] && $optionsPayStatuses[$order['status']])
CSaleOrder::StatusOrder($order['externalId'], $optionsPayStatuses[$order['status']]);
// uncancel order
if($wasCanaceled && ($optionsPayStatuses[$order['status']] != 'YY'))
if(isset($order['status']) && $order['status'] && $wasCanaceled && ($optionsPayStatuses[$order['status']] != 'YY'))
CSaleOrder::CancelOrder($order['externalId'], "N", $order['statusComment']);
// cancel order
if($optionsPayStatuses[$order['status']] == 'YY')
if(isset($order['status']) && $order['status'] && $optionsPayStatuses[$order['status']] == 'YY')
CSaleOrder::CancelOrder($order['externalId'], "Y", $order['statusComment']);
// set PAYED
if($optionsPayment[$order['paymentStatus']])
if(isset($order['paymentStatus']) && $order['paymentStatus'] && $optionsPayment[$order['paymentStatus']])
CSaleOrder::PayOrder($order['externalId'], $optionsPayment[$order['paymentStatus']]);
}
}
@ -1044,6 +1045,19 @@ class ICrmOrderActions
return 'ICrmOrderActions::orderHistoryAgent();';
}
/**
*
* Agent function
*
* @return self name
*/
public static function orderAgent() {
self::uploadOrdersAgent();
self::orderHistory();
return 'ICrmOrderActions::orderAgent();';
}
/**
*
* creates order or returns array of order and customer for mass upload
@ -1110,26 +1124,6 @@ class ICrmOrderActions
'createdAt' => $createdAt
));
if($send) {
try {
$customer = $api->customerEdit($customer);
} catch (\IntaroCrm\Exception\ApiException $e) {
self::eventLog(
'ICrmOrderActions::orderCreate', 'IntaroCrm\RestApi::customerEdit',
$e->getCode() . ': ' . $e->getMessage()
);
return false;
} catch (\IntaroCrm\Exception\CurlException $e) {
self::eventLog(
'ICrmOrderActions::orderCreate', 'IntaroCrm\RestApi::customerEdit::CurlException',
$e->getCode() . ': ' . $e->getMessage()
);
return false;
}
}
// delivery types
$arId = array();
if (strpos($arFields['DELIVERY_ID'], ":") !== false)
@ -1275,6 +1269,7 @@ class ICrmOrderActions
$createdAt = $createdAt->format('Y-m-d H:i:s');
$resOrder = array(
'customer' => $customer,
'number' => $arFields['ACCOUNT_NUMBER'],
'phone' => $resOrder['phone'],
'email' => $resOrder['email'],
@ -1298,7 +1293,6 @@ class ICrmOrderActions
'items' => $items
);
if(isset($arParams['optionsSites']) && is_array($arParams['optionsSites'])
&& in_array($arFields['LID'], $arParams['optionsSites']))
$resOrder['site'] = $arFields['LID'];
@ -1312,7 +1306,7 @@ class ICrmOrderActions
$resOrder['patronymic'] = $contactNameArr[2];
}
// custom orderType functunion
// custom orderType function
if(function_exists('intarocrm_get_order_type')) {
$orderType = intarocrm_get_order_type($arFields);
if($orderType)
@ -1321,9 +1315,42 @@ class ICrmOrderActions
$orderType['orderType'] = 'new';
}
// custom order & customer fields function
if(function_exists('intarocrm_before_order_send')) {
$newResOrder = intarocrm_before_order_send($resOrder);
if(is_array($newResOrder) && !empty($newResOrder))
$resOrder = $newResOrder;
}
$resOrder = self::clearArr($resOrder);
if(isset($resOrder['customer']) && is_array($resOrder['customer']) && !empty($resOrder['customer'])) {
$customer = $resOrder['customer'];
unset($resOrder['customer']);
}
if($send) {
try {
$customer = $api->customerEdit($customer);
} catch (\IntaroCrm\Exception\ApiException $e) {
self::eventLog(
'ICrmOrderActions::orderCreate', 'IntaroCrm\RestApi::customerEdit',
$e->getCode() . ': ' . $e->getMessage()
);
return false;
} catch (\IntaroCrm\Exception\CurlException $e) {
self::eventLog(
'ICrmOrderActions::orderCreate', 'IntaroCrm\RestApi::customerEdit::CurlException',
$e->getCode() . ': ' . $e->getMessage()
);
return false;
}
try {
return $api->orderEdit($resOrder);
} catch (\IntaroCrm\Exception\ApiException $e) {

View File

@ -25,6 +25,27 @@ class ICrmOrderEvent {
$GLOBALS['INTARO_CRM_ORDER_ADD'] = true;
return;
}
/**
* OnSaleBeforeReserveOrder
*
* @param mixed $arFields - Order arFields
*/
function OnSaleBeforeReserveOrder($arFields = array()) {
$GLOBALS['INTARO_CRM_ORDER_RESERVE'] = true;
return;
}
/**
* OnSaleReserveOrder
*
* @param mixed $arFields - Order arFields
*/
function OnSaleReserveOrder($arFields = array()) {
if(isset($GLOBALS['INTARO_CRM_ORDER_RESERVE']) && $GLOBALS['INTARO_CRM_ORDER_RESERVE'])
unset($GLOBALS['INTARO_CRM_ORDER_RESERVE']);
return;
}
/**
* onUpdateOrder

View File

@ -15,6 +15,19 @@ if(!check_bitrix_sessid()) return;
__IncludeLang(GetLangFileName($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/intaro.intarocrm/lang/", "/icml_export_setup.php"));
$MODULE_ID = 'intaro.intarocrm';
$CRM_CATALOG_BASE_PRICE = 'catalog_base_price';
$basePriceId = COption::GetOptionString($MODULE_ID, $CRM_CATALOG_BASE_PRICE, 1);
$arResult['PRICE_TYPES'] = array();
$dbPriceType = CCatalogGroup::GetList(
array("SORT" => "ASC"), array(), array(), array(), array("ID", "NAME", "BASE")
);
while ($arPriceType = $dbPriceType->Fetch()) {
$arResult['PRICE_TYPES'][$arPriceType['ID']] = $arPriceType;
}
if (($ACTION == 'EXPORT' || $ACTION == 'EXPORT_EDIT' || $ACTION == 'EXPORT_COPY') && $STEP == 1)
{
@ -550,6 +563,20 @@ if ($STEP==1)
<br>
<br>
<font class="text"><?=GetMessage("BASE_PRICE");?>&nbsp;</font>
<select name="price-types" class="typeselect">
<option value=""></option>
<?php foreach($arResult['PRICE_TYPES'] as $priceType): ?>
<option value="<?php echo $priceType['ID']; ?>"
<?php if($priceType['ID'] == $basePriceId) echo 'selected'; ?>>
<?php echo $priceType['NAME']; ?>
</option>
<?php endforeach; ?>
</select>
<br>
<br>
<br>
<?if ($ACTION=="EXPORT_SETUP" || $ACTION == 'EXPORT_EDIT' || $ACTION == 'EXPORT_COPY'):?>
<font class="text"><?=GetMessage("PROFILE_NAME");?><br><br></font>
@ -563,7 +590,6 @@ if ($STEP==1)
<br>
<?endif;?>
<script type="text/javascript" src="/bitrix/js/main/jquery/jquery-1.7.min.js"></script>
<script type="text/javascript">
function checkAll(obj,cnt)
@ -667,6 +693,7 @@ if ($STEP==1)
}
elseif ($STEP==2)
{
COption::SetOptionString($MODULE_ID, $CRM_CATALOG_BASE_PRICE, htmlspecialchars(trim($_POST['price-types'])));
$FINITE = true;
}

View File

@ -36,6 +36,7 @@ class intaro_intarocrm extends CModule {
var $CRM_ORDER_DISCHARGE = 'order_discharge';
var $CRM_ORDER_FAILED_IDS = 'order_failed_ids';
var $CRM_ORDER_HISTORY_DATE = 'order_history_date';
var $CRM_CATALOG_BASE_PRICE = 'catalog_base_price';
var $INSTALL_PATH;
function intaro_intarocrm() {
@ -980,6 +981,17 @@ class intaro_intarocrm extends CModule {
if (!CModule::IncludeModule("catalog")) {
$arResult['errCode'] = 'ERR_CATALOG';
}
$arResult['PRICE_TYPES'] = array();
$dbPriceType = CCatalogGroup::GetList(
array("SORT" => "ASC"), array(), array(), array(), array("ID", "NAME", "BASE")
);
while ($arPriceType = $dbPriceType->Fetch()) {
$arResult['PRICE_TYPES'][$arPriceType['ID']] = $arPriceType;
}
$APPLICATION->IncludeAdminFile(
GetMessage('MODULE_INSTALL_TITLE'),
$_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/step5.php'
@ -1095,6 +1107,11 @@ class intaro_intarocrm extends CModule {
RegisterModuleDependences("sale", "OnOrderNewSendEmail", $this->MODULE_ID, "ICrmOrderEvent", "onSendOrderMail");
RegisterModuleDependences("sale", "OnOrderUpdate", $this->MODULE_ID, "ICrmOrderEvent", "onUpdateOrder");
RegisterModuleDependences("sale", "OnBeforeOrderAdd", $this->MODULE_ID, "ICrmOrderEvent", "onBeforeOrderAdd");
RegisterModuleDependences("sale", "OnSaleBeforeReserveOrder", $this->MODULE_ID, "ICrmOrderEvent", "OnSaleBeforeReserveOrder");
RegisterModuleDependences("sale", "OnSaleReserveOrder", $this->MODULE_ID, "ICrmOrderEvent", "onSaleReserveOrder");
COption::SetOptionString($this->MODULE_ID, $this->CRM_CATALOG_BASE_PRICE, htmlspecialchars(trim($_POST['price-types'])));
$this->CopyFiles();
if (isset($_POST['LOAD_NOW'])) {
@ -1208,29 +1225,17 @@ class intaro_intarocrm extends CModule {
}
//agent
$dateAgent = new DateTime();
$intAgent = new DateInterval('PT60S'); // PT60S - 60 sec;
$dateAgent->add($intAgent);
CAgent::AddAgent(
"ICrmOrderActions::uploadOrdersAgent();", $this->MODULE_ID, "N", 600, // interval - 10 mins
"ICrmOrderActions::orderAgent();", $this->MODULE_ID, "N", 600, // interval - 10 mins
$dateAgent->format('d.m.Y H:i:s'), // date of first check
"Y", // agent is active
$dateAgent->format('d.m.Y H:i:s'), // date of first start
30
);
CAgent::AddAgent(
"ICrmOrderActions::orderHistoryAgent();",
$this->MODULE_ID,
"N",
600, // interval - 10 mins
$dateAgent->format('d.m.Y H:i:s'), // date of first check
"Y", // agent is active
$dateAgent->format('d.m.Y H:i:s'), // date of first start
30
);
$api_host = COption::GetOptionString($this->MODULE_ID, $this->CRM_API_HOST_OPTION, 0);
$api_key = COption::GetOptionString($this->MODULE_ID, $this->CRM_API_KEY_OPTION, 0);
@ -1264,6 +1269,7 @@ class intaro_intarocrm extends CModule {
CAgent::RemoveAgent("ICrmOrderActions::uploadOrdersAgent();", $this->MODULE_ID);
CAgent::RemoveAgent("ICrmOrderActions::orderHistoryAgent();", $this->MODULE_ID);
CAgent::RemoveAgent("ICrmOrderActions::orderAgent();", $this->MODULE_ID);
COption::RemoveOption($this->MODULE_ID, $this->CRM_API_HOST_OPTION);
COption::RemoveOption($this->MODULE_ID, $this->CRM_API_KEY_OPTION);
@ -1277,6 +1283,7 @@ class intaro_intarocrm extends CModule {
COption::RemoveOption($this->MODULE_ID, $this->CRM_ORDER_DISCHARGE);
COption::RemoveOption($this->MODULE_ID, $this->CRM_ORDER_FAILED_IDS);
COption::RemoveOption($this->MODULE_ID, $this->CRM_ORDER_HISTORY_DATE);
COption::RemoveOption($this->MODULE_ID, $this->CRM_CATALOG_BASE_PRICE);
UnRegisterModuleDependences("sale", "OnSalePayOrder", $this->MODULE_ID, "ICrmOrderEvent", "onSalePayOrder");
UnRegisterModuleDependences("sale", "OnSaleCancelOrder", $this->MODULE_ID, "ICrmOrderEvent", "onSaleCancelOrder");
@ -1284,6 +1291,8 @@ class intaro_intarocrm extends CModule {
UnRegisterModuleDependences("sale", "OnOrderUpdate", $this->MODULE_ID, "ICrmOrderEvent", "onUpdateOrder");
UnRegisterModuleDependences("sale", "OnBeforeOrderAdd", $this->MODULE_ID, "ICrmOrderEvent", "onBeforeOrderAdd");
UnRegisterModuleDependences("sale", "OnBeforeOrderAccountNumberSet", $this->MODULE_ID, "ICrmOrderEvent", "onBeforeOrderAccountNumberSet");
UnRegisterModuleDependences("sale", "OnSaleBeforeReserveOrder", $this->MODULE_ID, "ICrmOrderEvent", "onSaleBeforeReserveOrder");
UnRegisterModuleDependences("sale", "OnSaleReserveOrder", $this->MODULE_ID, "ICrmOrderEvent", "onSaleReserveOrder");
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));

View File

@ -477,6 +477,18 @@ if (!empty($oldValues)) {
<input id="load-now" type="checkbox" name="LOAD_NOW" value="now" checked >
<br>
<br>
<font class="text"><?=GetMessage("BASE_PRICE");?>&nbsp;</font>
<select name="price-types" class="typeselect">
<option value=""></option>
<?php foreach($arResult['PRICE_TYPES'] as $priceType): ?>
<option value="<?php echo $priceType['ID']; ?>"
<?php if($priceType['BASE'] == 'Y') echo 'selected'; ?>>
<?php echo $priceType['NAME']; ?>
</option>
<?php endforeach; ?>
</select>
<br>
<br>
<br>
<div id="profile-field" >

View File

@ -1,5 +1,5 @@
<?
$arModuleVersion = array(
"VERSION" => "1.0.6",
"VERSION" => "1.0.7",
"VERSION_DATE" => "2014-05-29 19:33:00",
);

View File

@ -40,4 +40,5 @@ $MESS["UNIT_MEASUREMENT_CM"] = "см.";
$MESS["UNIT_MEASUREMENT_M"] = "м.";
$MESS["UNIT_MEASUREMENT_MG"] = "мг.";
$MESS["UNIT_MEASUREMENT_G"] = "г.";
$MESS["UNIT_MEASUREMENT_KG"] = "кг.";
$MESS["UNIT_MEASUREMENT_KG"] = "кг.";
$MESS['BASE_PRICE'] = 'Базовая цена';

View File

@ -21,4 +21,5 @@ $MESS ['PROFILE_NAME_EXAMPLE'] = 'Выгрузка каталога IntaroCRM';
$MESS ['ERR_FIELDS_PROFILE'] = 'Неверно заполнено поле имени профиля';
$MESS ['ERR_FIELDS_IBLOCK'] = 'Не выбрано ни одного информационного блока';
$MESS ['ERR_FIELDS_ARTICLE'] = 'Не выбраны артикулы';
$MESS ['ERR_FIELDS_FILE'] = 'Не указано имя файла';
$MESS ['ERR_FIELDS_FILE'] = 'Не указано имя файла';
$MESS ['BASE_PRICE'] = 'Базовая цена';