1
0
mirror of synced 2024-11-22 13:26:10 +03:00
This commit is contained in:
Grisha Pomadchin 2013-09-02 16:03:27 +04:00
parent bb22ddb413
commit 8d883e407d
6 changed files with 15 additions and 519 deletions

View File

@ -1,195 +0,0 @@
<?php
/**
* OrderEvent
*/
class ICrmOrderEvent {
protected static $MODULE_ID = 'intaro.intarocrm';
protected static $CRM_API_HOST_OPTION = 'api_host';
protected static $CRM_API_KEY_OPTION = 'api_key';
protected static $CRM_ORDER_TYPES_ARR = 'order_types_arr';
protected static $CRM_DELIVERY_TYPES_ARR = 'deliv_types_arr';
protected static $CRM_PAYMENT_TYPES = 'pay_types_arr';
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';
/**
* onUpdateOrder
*
* @param mixed $ID - Order id
* @param mixed $arFields - Order arFields
*/
function onUpdateOrder($ID, $arFields = array()) {
//self::writeDataOnOrderCreate($ID);
}
/**
* onSendOrderMail
* in: sale.order.ajax, sale.order.full
*
* @param mixed $ID - Order id
* @param mixed $eventName - Event type
* @param mixed $arFields - Order arFields for sending template
*/
function onSendOrderMail($ID, &$eventName, &$arFields) {
self::writeDataOnOrderCreate($ID);
}
/**
* writeDataOnOrderCreate via api
*
* @param integer $ID - Order Id
*/
function writeDataOnOrderCreate($ID) {
if (!CModule::IncludeModule('iblock')) {
//handle err
ICrmOrderActions::eventLog('ICrmOrderEvent::writeDataOnOrderCreate', 'iblock', 'module not found');
return true;
}
if (!CModule::IncludeModule("sale")) {
//handle err
ICrmOrderActions::eventLog('ICrmOrderEvent::writeDataOnOrderCreate', 'sale', 'module not found');
return true;
}
if (!CModule::IncludeModule("catalog")) {
//handle err
ICrmOrderActions::eventLog('ICrmOrderEvent::writeDataOnOrderCreate', 'catalog', 'module not found');
return true;
}
$api_host = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_HOST_OPTION, 0);
$api_key = COption::GetOptionString(Iself::$MODULE_ID, self::$CRM_API_KEY_OPTION, 0);
//saved cat params
$optionsOrderTypes = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_ORDER_TYPES_ARR, 0));
$optionsDelivTypes = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_DELIVERY_TYPES_ARR, 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
$optionsPayment = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT, 0));
$api = new IntaroCrm\RestApi($api_host, $api_key);
$arParams = array(
'optionsOrderTypes' => $optionsOrderTypes,
'optionsDelivTypes' => $optionsDelivTypes,
'optionsPayTypes' => $optionsPayTypes,
'optionsPayStatuses' => $optionsPayStatuses,
'optionsPayment' => $optionsPayment
);
$arOrder = CSaleOrder::GetById($ID);
$result = ICrmOrderActions::orderCreate($arOrder, $api, $arParams, true);
if(!$result) {
ICrmOrderActions::eventLog('ICrmOrderEvent::writeDataOnOrderCreate', 'ICrmOrderActions::orderCreate', 'error during creating order');
return true;
}
return true;
}
/**
*
* @param type $ID -- orderId
* @param type $cancel -- Y / N - cancel order status
* @param type $reason -- cancel reason
* @return boolean
*/
function onSaleCancelOrder($ID, $cancel, $reason) {
if(!$ID || !$cancel || ($cancel != 'Y'))
return true;
if (!CModule::IncludeModule('iblock')) {
//handle err
ICrmOrderActions::eventLog('ICrmOrderEvent::onSaleCancelOrder', 'iblock', 'module not found');
return true;
}
if (!CModule::IncludeModule("sale")) {
//handle err
ICrmOrderActions::eventLog('ICrmOrderEvent::onSaleCancelOrder', 'sale', 'module not found');
return true;
}
if (!CModule::IncludeModule("catalog")) {
//handle err
ICrmOrderActions::eventLog('ICrmOrderEvent::onSaleCancelOrder', 'catalog', 'module not found');
return true;
}
$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);
//saved cat params
$optionsPayStatuses = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT_STATUSES, 0)); // --statuses
$api = new IntaroCrm\RestApi($api_host, $api_key);
$order = array(
'externalId' => (int) $ID,
'status' => $optionsPayStatuses[$cancel],
'statusComment' => ICrmOrderActions::toJSON($reason)
);
$api->orderEdit($order);
// error pushing order
if ($api->getStatusCode() != 201)
ICrmOrderActions::eventLog('ICrmOrderEvent::onSaleCancelOrder', 'IntaroCrm\RestApi::orderEdit', $api->getLastError());
return true;
}
/**
*
* @param type $ID -- orderId
* @param type $payed -- Y / N - pay order status
* @return boolean
*/
function onSalePayOrder($ID, $payed) {
if(!$ID || !$payed || ($payed != 'Y'))
return true;
if (!CModule::IncludeModule('iblock')) {
//handle err
ICrmOrderActions::eventLog('ICrmOrderEvent::onSalePayOrder', 'iblock', 'module not found');
return true;
}
if (!CModule::IncludeModule("sale")) {
//handle err
ICrmOrderActions::eventLog('ICrmOrderEvent::onSalePayOrder', 'sale', 'module not found');
return true;
}
if (!CModule::IncludeModule("catalog")) {
//handle err
ICrmOrderActions::eventLog('ICrmOrderEvent::onSalePayOrder', 'catalog', 'module not found');
return true;
}
$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);
//saved cat params
$optionsPayment = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT, 0));
$api = new IntaroCrm\RestApi($api_host, $api_key);
$order = array(
'externalId' => (int) $ID,
'paymentStatus' => $optionsPayment[$payed]
);
$api->orderEdit($order);
// error pushing order
if ($api->getStatusCode() != 201)
ICrmOrderActions::eventLog('ICrmOrderEvent::onSalePayOrder', 'IntaroCrm\RestApi::orderEdit', $api->getLastError());
return true;
}
}

View File

@ -0,0 +1,3 @@
* Доработан скрипт генерации ICML-файла в части работы со спецсимволами
* Добавлена поддержка многосайтовости
* Добавлена возможность выгрузки способов доставки на втором шаге установки

View File

@ -1,19 +0,0 @@
<?php
set_time_limit(0);
global $APPLICATION;
if (!CModule::IncludeModule("iblock"))
return;
if (!CModule::IncludeModule("catalog"))
return;
if (!CModule::IncludeModule("intaro.intarocrm"))
return;
$loader = new ICMLLoader();
$loader->iblocks = $IBLOCK_EXPORT;
$loader->articleProperties = $IBLOCK_PROPERTY_ARTICLE;
$loader->filename = $SETUP_FILE_NAME;
$loader->application = $APPLICATION;
$loader->Load();

View File

@ -1,295 +0,0 @@
<?
if(!check_bitrix_sessid()) return;
__IncludeLang(GetLangFileName($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/intaro.intarocrm/lang/", "/icml_export_setup.php"));
if (($ACTION == 'EXPORT_EDIT' || $ACTION == 'EXPORT_COPY') && $STEP == 1)
{
if (isset($arOldSetupVars['SETUP_FILE_NAME']))
$SETUP_FILE_NAME = $arOldSetupVars['SETUP_FILE_NAME'];
if (isset($arOldSetupVars['SETUP_PROFILE_NAME']))
$SETUP_PROFILE_NAME = $arOldSetupVars['SETUP_PROFILE_NAME'];
if (isset($arOldSetupVars['IBLOCK_EXPORT']))
$IBLOCK_EXPORT = $arOldSetupVars['IBLOCK_EXPORT'];
if (isset($arOldSetupVars['IBLOCK_PROPERTY_ARTICLE']))
$IBLOCK_PROPERTY_ARTICLE = $arOldSetupVars['IBLOCK_PROPERTY_ARTICLE'];
}
if ($STEP>1)
{
if (count($IBLOCK_EXPORT) < count($IBLOCK_PROPERTY_ARTICLE))
$arSetupErrors[] = GetMessage("ERROR_ARTICLE_NOT_SET");
if (strlen($SETUP_FILE_NAME)<=0)
{
$arSetupErrors[] = GetMessage("CET_ERROR_NO_FILENAME");
}
elseif ($APPLICATION->GetFileAccessPermission($SETUP_FILE_NAME) < "W")
{
$arSetupErrors[] = str_replace("#FILE#", $SETUP_FILE_NAME, GetMessage('CET_YAND_RUN_ERR_SETUP_FILE_ACCESS_DENIED'));
}
if (($ACTION=="EXPORT_SETUP" || $ACTION == 'EXPORT_EDIT' || $ACTION == 'EXPORT_COPY') && strlen($SETUP_PROFILE_NAME)<=0)
{
$arSetupErrors[] = GetMessage("CET_ERROR_NO_PROFILE_NAME");
}
if (!empty($arSetupErrors))
{
$STEP = 1;
}
}
if (!empty($arSetupErrors))
echo ShowError(implode('<br />', $arSetupErrors));
if ($STEP==1)
{
?>
<form method="post" action="<?php echo $APPLICATION->GetCurPage(); ?>" >
<?if ($ACTION == 'EXPORT_EDIT' || $ACTION == 'EXPORT_COPY')
{
?><input type="hidden" name="PROFILE_ID" value="<? echo intval($PROFILE_ID); ?>"><?
}
?>
<font class="text"><?=GetMessage("EXPORT_CATALOGS");?><br><br></font>
<?
if (!isset($IBLOCK_EXPORT) || !is_array($IBLOCK_EXPORT))
{
$IBLOCK_EXPORT = array();
}
$boolAll = false;
$intCountChecked = 0;
$intCountAvailIBlock = 0;
$arIBlockList = array();
$db_res = CIBlock::GetList(Array("IBLOCK_TYPE"=>"ASC", "NAME"=>"ASC"),array('CHECK_PERMISSIONS' => 'Y','MIN_PERMISSION' => 'W'));
while ($res = $db_res->Fetch())
{
if ($arCatalog = CCatalog::GetByIDExt($res["ID"]))
{
if($arCatalog['CATALOG_TYPE'] == "D" || $arCatalog['CATALOG_TYPE'] == "X" || $arCatalog['CATALOG_TYPE'] == "P")
{
$arSiteList = array();
$rsSites = CIBlock::GetSite($res["ID"]);
while ($arSite = $rsSites->Fetch())
{
$arSiteList[] = $arSite["SITE_ID"];
}
$db_properties = CIBlock::GetProperties($res['ID'], Array());
$properties = Array();
while($prop = $db_properties->Fetch())
$properties[] = $prop;
if (count($IBLOCK_EXPORT) != 0)
$boolExport = (in_array($res['ID'], $IBLOCK_EXPORT));
else
$boolExport = true;
$arIBlockList[] = array(
'ID' => $res['ID'],
'NAME' => $res['NAME'],
'IBLOCK_TYPE_ID' => $res['IBLOCK_TYPE_ID'],
'IBLOCK_EXPORT' => $boolExport,
'PROPERTIES' => $properties,
'OLD_PROPERTY_SELECT' => $IBLOCK_PROPERTY_ARTICLE[$res['ID']] != "" ? $IBLOCK_PROPERTY_ARTICLE[$res['ID']] : null,
'SITE_LIST' => '('.implode(' ',$arSiteList).')',
);
if ($boolExport)
$intCountChecked++;
$intCountAvailIBlock++;
}
}
}
if (count($IBLOCK_EXPORT) != 0) {
if ($intCountChecked == $intCountAvailIBlock)
$boolAll = true;
} else {
$intCountChecked = $intCountAvailIBlock;
$boolAll = true;
}
?>
<table class="adm-list-table" id="export_setup">
<thead>
<tr class="adm-list-table-header">
<td class="adm-list-table-cell">
<div class="adm-list-table-cell-inner"><?echo GetMessage("CATALOG");?></div>
</td>
<td class="adm-list-table-cell">
<div class="adm-list-table-cell-inner">
<?echo GetMessage("EXPORT2INTAROCML");?>&nbsp;
</div>
</td>
<td class="adm-list-table-cell">
<div class="adm-list-table-cell-inner"><?echo GetMessage("PROPERTY");?></div>
</td>
</tr>
</thead>
<tbody>
<tr class="adm-list-table-row">
<td class="adm-list-table-cell">
<?echo GetMessage("ALL_CATALOG");?>
</td>
<td class="adm-list-table-cell">
<input style="vertical-align: middle;" type="checkbox" name="icml_export_all" id="icml_export_all" value="Y" onclick="checkAll(this,<? echo $intCountAvailIBlock; ?>);"<? echo ($boolAll ? ' checked' : ''); ?>>
</td>
<td class="adm-list-table-cell">
&nbsp;
</td>
</tr>
<?
foreach ($arIBlockList as $key => $arIBlock)
{
?>
<tr class="adm-list-table-row">
<td class="adm-list-table-cell" style="padding-left: 5em">
<? echo htmlspecialcharsex("[".$arIBlock["IBLOCK_TYPE_ID"]."] ".$arIBlock["NAME"]." ".$arIBlock['SITE_LIST']); ?>
</td>
<td class="adm-list-table-cell">
<font class="tablebodytext">
<input
type="checkbox"
name="IBLOCK_EXPORT[<?=$arIBlock["ID"]?>]"
id="IBLOCK_EXPORT<?=$arIBlock["ID"]?>"
value="<?=$arIBlock["ID"]?>"
<? if ($arIBlock['IBLOCK_EXPORT']) echo " checked"; ?>
onclick="checkOne(this,<? echo $intCountAvailIBlock; ?>);"
>
</font>
</td>
<td class="adm-list-table-cell">
<select
style="width: 200px;"
id="IBLOCK_PROPERTY_ARTICLE<?=$arIBlock["ID"]?>"
name="IBLOCK_PROPERTY_ARTICLE[<?=$arIBlock["ID"]?>]"
class="property-export">
<option value=""></option>
<?
foreach ($arIBlock['PROPERTIES'] as $prop)
{
?>
<option value="<?=$prop['CODE'] ?>"
<?
if ($arIBlock['OLD_PROPERTY_SELECT'] == $prop["CODE"]){
echo " selected";
} else {
if ($arIBlock['OLD_PROPERTY_SELECT'] != "") {
if ($prop["CODE"] == "ARTICLE" ||
$prop["CODE"] == "ART" ||
$prop["CODE"] == "ARTNUMBER" )
echo " selected";
}
}
?>
>
<?=$prop["NAME"];?>
</option>
<?
}
?>
</select>
</td>
</tr>
<?
}
?>
</tbody>
</table>
<input type="hidden" name="count_checked" id="count_checked" value="<? echo $intCountChecked; ?>">
<br>
<br>
<br>
<font class="text"><?=GetMessage("FILENAME");?><br><br></font>
<input type="text" name="SETUP_FILE_NAME"
value="<?=htmlspecialcharsbx(strlen($SETUP_FILE_NAME) > 0 ?
$SETUP_FILE_NAME :
(COption::GetOptionString(
'catalog',
'export_default_path',
'/bitrix/catalog_export/'))
.'intarocrm'/* .mt_rand(0, 999999) */.'.xml'
); ?>" size="50">
<br>
<br>
<br>
<?if ($ACTION=="EXPORT_SETUP" || $ACTION == 'EXPORT_EDIT' || $ACTION == 'EXPORT_COPY'):?>
<font class="text"><?=GetMessage("PROFILE_NAME");?><br><br></font>
<input
type="text"
name="SETUP_PROFILE_NAME"
value="<?echo htmlspecialchars($SETUP_PROFILE_NAME)?>"
size="50">
<br>
<br>
<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)
{
var boolCheck = obj.checked;
for (i = 0; i < cnt; i++)
{
BX('IBLOCK_EXPORT'+i).checked = boolCheck;
}
BX('count_checked').value = (boolCheck ? cnt : 0);
};
function checkOne(obj,cnt)
{
var boolCheck = obj.checked;
var intCurrent = parseInt(BX('count_checked').value);
intCurrent += (boolCheck ? 1 : -1);
BX('icml_export_all').checked = (intCurrent < cnt ? false : true);
BX('count_checked').value = intCurrent;
if (!boolCheck)
BX(obj.id.replace('IBLOCK_EXPORT','IBLOCK_PROPERTY_ARTICLE')).value = 'none';
};
</script>
<?//Следующие переменные должны быть обязательно установлены?>
<?=bitrix_sessid_post();?>
<input type="hidden" name="lang" value="<?echo LANGUAGE_ID ?>">
<input type="hidden" name="ACT_FILE" value="<?echo htmlspecialcharsbx($_REQUEST["ACT_FILE"]) ?>">
<input type="hidden" name="ACTION" value="<?echo htmlspecialcharsbx($ACTION) ?>">
<input type="hidden" name="STEP" value="<?echo intval($STEP) + 1 ?>">
<input type="hidden" name="SETUP_FIELDS_LIST" value="SETUP_FILE_NAME,IBLOCK_EXPORT,IBLOCK_PROPERTY_ARTICLE">
<input type="submit" value="<?echo ($ACTION=="EXPORT")?GetMessage("CET_EXPORT"):GetMessage("CET_SAVE")?>">
</form>
<?
}
elseif ($STEP==2)
{
$FINITE = true;
}
?>

View File

@ -1,10 +0,0 @@
<?php
CModule::AddAutoloadClasses(
'intaro.intarocrm', // module name
array (
'IntaroCrm\RestApi' => 'classes/general/RestApi.php',
'ICrmOrderActions' => 'classes/general/ICrmOrderActions.php',
'ICMLLoader' => 'classes/general/ICMLLoader.php',
'ICrmOrderEvent' => 'classes/general/events/ICrmOrderEvent.php'
)
);

View File

@ -0,0 +1,12 @@
<?php
if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/bitrix/php_interface/include/catalog_export/intarocrm_run.php')) {
unlink($_SERVER['DOCUMENT_ROOT'] . '/bitrix/php_interface/include/catalog_export/intarocrm_run.php');
}
$updater->CopyFiles("install/export/intarocrm_run.php", "php_interface/include/catalog_export/intarocrm_run.php");
if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/bitrix/php_interface/include/catalog_export/intarocrm_setup.php')) {
unlink($_SERVER['DOCUMENT_ROOT'] . '/bitrix/php_interface/include/catalog_export/intarocrm_setup.php');
}
$updater->CopyFiles("install/export/intarocrm_setup.php", "php_interface/include/catalog_export/intarocrm_setup.php");
COption::SetOptionString('intaro.intarocrm', 'sites_ids', serialize(array()));