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

Extended properties add to export

This commit is contained in:
m.korolev 2013-09-13 16:15:54 +04:00
parent e8f55aa087
commit 596709946c
5 changed files with 619 additions and 309 deletions

View File

@ -4,12 +4,13 @@ class ICMLLoader {
public $iblocks;
public $filename;
public $articleProperties;
public $propertiesSKU;
public $propertiesProduct;
public $application;
public $encoding = 'utf-8';
protected $fp;
protected $mainSection = 1000000;
protected $mainSection = 1000000;
public function Load()
{
@ -20,6 +21,8 @@ class ICMLLoader {
if (count($this->iblocks) < count($this->articleProperties))
return false;
$this->PrepareSettings();
$this->PrepareFile();
$this->PreWriteCatalog();
@ -39,6 +42,20 @@ class ICMLLoader {
}
protected function PrepareSettings()
{
foreach ($this->propertiesSKU as $iblock => $arr) {
foreach ($arr as $id => $sku) {
$this->propertiesSKU[$iblock][$id] = strtoupper($sku);
}
}
foreach ($this->propertiesProduct as $iblock => $arr) {
foreach ($arr as $id => $prod) {
$this->propertiesProduct[$iblock][$id] = strtoupper($prod);
}
}
}
protected function PrepareValue($text)
{
$newText = $this->application->ConvertCharset($text, LANG_CHARSET, $this->encoding);
@ -60,12 +77,11 @@ class ICMLLoader {
protected function PreWriteCatalog()
{
@fwrite($this->fp, "<yml_catalog date=\"" . $this->PrepareValue(Date("Y-m-d H:i:s")) . "\">\n");
@fwrite($this->fp, "<shop>\n");
@fwrite($this->fp, "<name>". $this->PrepareValue(COption::GetOptionString("main", "site_name", ""))."</name>\n");
@fwrite($this->fp, "<company>".$this->PrepareValue(COption::GetOptionString("main", "site_name", ""))."</company>\n");
@fwrite($this->fp, "<yml_catalog date=\"" . $this->PrepareValue(Date("Y-m-d H:i:s")) . "\">\n
<shop>\n
<name>" . $this->PrepareValue(COption::GetOptionString("main", "site_name", ""))."</name>\n
<company>" . $this->PrepareValue(COption::GetOptionString("main", "site_name", ""))."</company>\n"
);
}
@ -96,8 +112,8 @@ class ICMLLoader {
protected function PostWriteCatalog()
{
@fwrite($this->fp, "</shop>\n");
@fwrite($this->fp, "</yml_catalog>\n");
@fwrite($this->fp, "</shop>\n
</yml_catalog>\n");
}
protected function CloseFile()
@ -157,11 +173,9 @@ class ICMLLoader {
{
foreach ($this->iblocks as $key => $id)
{
$iblock['IBLOCK_DB'] = CIBlock::GetByID($id)->Fetch();
$iblockOffer = CCatalogSKU::GetInfoByProductIBlock($id);
$arSelect = Array (
"ID",
"LID",
@ -178,8 +192,10 @@ class ICMLLoader {
"DETAIL_PAGE_URL"
);
if (isset($this->articleProperties[$id]))
$arSelect[] = "PROPERTY_" . $this->articleProperties[$id];
foreach ($this->propertiesProduct[$id] as $key => $propProduct) {
if ($this->propertiesProduct[$id][$key] != "")
$arSelect[] = "PROPERTY_" . $propProduct;
}
$filter = Array (
@ -195,7 +211,23 @@ class ICMLLoader {
$product = $product->GetFields();
// Get categories in InfoBlock
// Get properties of product
$resPropertiesProduct = Array();
foreach ($this->propertiesProduct[$id] as $key => $propProduct) {
$resPropertiesProduct[$key] = "";
if ($propProduct != "") {
$propDesc = CIBlockProperty::GetByID($propProduct, $id)->GetNext();
if ($propDesc['PROPERTY_TYPE'] == 'E') {
$el = CIBlockElement::GetById($product["PROPERTY_" . $propProduct . "_VALUE"])->Fetch();
$resPropertiesProduct[$key] = $el['NAME'];
} else {
$resPropertiesProduct[$key] = $product["PROPERTY_" . $propProduct . "_VALUE"];
}
}
}
// Get categories of product
$categories = Array();
$dbResCategories = CIBlockElement::GetElementGroups($product['ID'], true);
while ($arResCategory = $dbResCategories->Fetch()) {
@ -214,7 +246,6 @@ class ICMLLoader {
$existOffer = false;
if (!empty($iblockOffer['IBLOCK_ID'])) {
$arFilterOffer = Array (
'IBLOCK_ID' => $iblockOffer['IBLOCK_ID'],
'PROPERTY_' . $iblockOffer['SKU_PROPERTY_ID'] => $product["ID"]
@ -226,9 +257,11 @@ class ICMLLoader {
"DETAIL_PAGE_URL",
"DETAIL_PICTURE"
);
if (isset($this->articleProperties[$id]))
$arSelectOffer[] = "PROPERTY_" . $this->articleProperties[$id];
foreach ($this->propertiesSKU[$id] as $key => $propSKU) {
if ($this->propertiesSKU[$id][$key] != "")
$arSelectOffer[] = "PROPERTY_" . $propSKU;
}
$rsOffers = CIBlockElement::GetList(array(), $arFilterOffer, false, false, $arSelectOffer);
while ($arOffer = $rsOffers->GetNext()) {
@ -241,9 +274,27 @@ class ICMLLoader {
$arOffer['DETAIL_PICTURE'] = $product["DETAIL_PICTURE"];
$arOffer['PREVIEW_PICTURE'] = $product["PREVIEW_PICTURE"];
$arOffer['PRODUCT_NAME'] = $product["NAME"];
if (isset($this->articleProperties[$id]))
$arOffer['ARTICLE'] = $product["PROPERTY_" . $this->articleProperties[$id] . "_VALUE"];
// Get properties of offer
foreach ($this->propertiesSKU[$id] as $key => $propSKU) {
if ($propSKU != "") {
$propDesc = CIBlockProperty::GetByID($propSKU,$arOffer['ID'])->GetNext();
if ($propDesc['PROPERTY_TYPE'] == 'E') {
$el = CIBlockElement::GetById($product["PROPERTY_" . $propSKU . "_VALUE"])->Fetch();
$arOffer[$key] = $el['NAME'];
} else {
$arOffer[$key] = $arOffer["PROPERTY_" . $propSKU . "_VALUE"];
}
}
}
foreach ($resPropertiesProduct as $key => $propProduct) {
if ($this->propertiesProduct[$id][$key] != "")
$arOffer[$key] = $propProduct;
}
$dbPrice = GetCatalogProductPrice($arOffer["ID"],1);
$arOffer['PRICE'] = $dbPrice['PRICE'];
@ -258,8 +309,11 @@ class ICMLLoader {
$product['PRODUCT_ID'] = $product["ID"];
$product['PRODUCT_NAME'] = $product["NAME"];
if (isset($this->articleProperties[$id]))
$product['ARTICLE'] = $product["PROPERTY_" . $this->articleProperties[$id] . "_VALUE"];
foreach ($resPropertiesProduct as $key => $propProduct) {
if ($this->propertiesProduct[$id][$key] != "")
$product[$key] = $propProduct;
}
$dbPrice = GetCatalogProductPrice($product["ID"],1);
$product['PRICE'] = $dbPrice['PRICE'];
@ -323,9 +377,12 @@ class ICMLLoader {
$offer .= "<xmlId>" . $this->PrepareValue($arOffer["EXTERNAL_ID"]) . "</xmlId>\n";
$offer .= "<productName>" . $this->PrepareValue($arOffer["PRODUCT_NAME"]) . "</productName>\n";
if (isset($arOffer["ARTICLE"]))
$offer .= "<article>" . $this->PrepareValue($arOffer["ARTICLE"]) . "</article>\n";
foreach ($this->propertiesProduct[$iblock['IBLOCK_DB']['ID']] as $key => $propProduct) {
if ($propProduct != "" && $arOffer[$key] != null)
$offer .= "<" . $key . ">" . $this->PrepareValue($arOffer[$key]) . "</" . $key . ">\n";
}
$offer.= "</offer>\n";
return $offer;
}

View File

@ -2,7 +2,6 @@
set_time_limit(0);
global $APPLICATION;
if (!CModule::IncludeModule("iblock"))
return;
@ -13,7 +12,8 @@ if (!CModule::IncludeModule("intaro.intarocrm"))
$loader = new ICMLLoader();
$loader->iblocks = $IBLOCK_EXPORT;
$loader->articleProperties = $IBLOCK_PROPERTY_ARTICLE;
$loader->propertiesSKU = $IBLOCK_PROPERTY_SKU;
$loader->propertiesProduct = $IBLOCK_PROPERTY_PRODUCT;
$loader->filename = $SETUP_FILE_NAME;
$loader->application = $APPLICATION;
$loader->Load();

View File

@ -1,30 +1,29 @@
<?
<?
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 (($ACTION == 'EXPORT' || $ACTION == 'EXPORT_EDIT' || $ACTION == 'EXPORT_COPY') && $STEP == 1)
{
if (isset($arOldSetupVars['SETUP_FILE_NAME']))
$SETUP_FILE_NAME = $arOldSetupVars['SETUP_FILE_NAME'];
$SETUP_FILE_NAME = $arOldSetupVars['SETUP_FILE_NAME'];
if (isset($arOldSetupVars['SETUP_PROFILE_NAME']))
$SETUP_PROFILE_NAME = $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'];
$IBLOCK_EXPORT = $arOldSetupVars['IBLOCK_EXPORT'];
if (isset($arOldSetupVars['IBLOCK_PROPERTY_SKU']))
$IBLOCK_PROPERTY_SKU = $arOldSetupVars['IBLOCK_PROPERTY_SKU'];
if (isset($arOldSetupVars['IBLOCK_PROPERTY_PRODUCT']))
$IBLOCK_PROPERTY_PRODUCT = $arOldSetupVars['IBLOCK_PROPERTY_PRODUCT'];
}
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");
@ -54,18 +53,43 @@ if ($STEP==1)
?>
<style type="text/css">
.iblock-export-table-display-none {
display: none;
}
</style>
<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); ?>"><?
}
?>
<h3>Настройки инфоблоков</h3>
<font class="text"><?=GetMessage("EXPORT_CATALOGS");?><br><br></font>
<?
if (!isset($IBLOCK_EXPORT) || !is_array($IBLOCK_EXPORT))
{
$IBLOCK_EXPORT = array();
}
$iblockPropertiesName = Array(
"article" => "Артикул",
"manufacturer" => "Производитель",
"color" => "Цвет",
"weight" => "Вес",
"size" => "Размер",
);
$iblockPropertiesHint = Array(
"article" => Array("ARTICLE", "ART", "ARTNUMBER", "ARTICUL", "ARTIKUL"),
"manufacturer" => Array("MANUFACTURER", "PROISVODITEL", "PROISVOD", "PROISV"),
"color" => Array("COLOR", "CVET"),
"weight" => Array("WEIGHT", "VES", "VEC"),
"size" => Array("SIZE", "RAZMER"),
);
$boolAll = false;
@ -73,42 +97,70 @@ if ($STEP==1)
$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())
while ($iblock = $db_res->Fetch())
{
if ($arCatalog = CCatalog::GetByIDExt($res["ID"]))
if ($arCatalog = CCatalog::GetByIDExt($iblock["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();
$propertiesSKU = null;
if ($arCatalog['CATALOG_TYPE'] == "X" || $arCatalog['CATALOG_TYPE'] == "P")
{
$iblockOffer = CCatalogSKU::GetInfoByProductIBlock($iblock["ID"]);
$db_properties = CIBlock::GetProperties($iblockOffer['IBLOCK_ID'], Array());
while($prop = $db_properties->Fetch())
$properties[] = $prop;
$propertiesSKU[] = $prop;
$oldPropertySKU = null;
if (isset($IBLOCK_PROPERTY_SKU[$iblock['ID']])) {
foreach ($iblockPropertiesName as $key => $prop) {
$oldPropertySKU[$key] = $IBLOCK_PROPERTY_SKU[$iblock['ID']][$key];
}
}
}
$propertiesProduct = null;
$db_properties = CIBlock::GetProperties($iblock['ID'], Array());
while($prop = $db_properties->Fetch())
$propertiesProduct[] = $prop;
$oldPropertyProduct = null;
if (isset($IBLOCK_PROPERTY_PRODUCT[$iblock['ID']])) {
foreach ($iblockPropertiesName as $key => $prop) {
$oldPropertyProduct[$key] = $IBLOCK_PROPERTY_PRODUCT[$iblock['ID']][$key];
}
}
$arSiteList = array();
$rsSites = CIBlock::GetSite($iblock["ID"]);
while ($arSite = $rsSites->Fetch())
{
$arSiteList[] = $arSite["SITE_ID"];
}
if (count($IBLOCK_EXPORT) != 0)
$boolExport = (in_array($res['ID'], $IBLOCK_EXPORT));
else
$boolExport = true;
if (count($IBLOCK_EXPORT) != 0)
$boolExport = (in_array($iblock['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).')',
);
$arIBlockList[] = array(
'ID' => $iblock['ID'],
'NAME' => $iblock['NAME'],
'IBLOCK_TYPE_ID' => $iblock['IBLOCK_TYPE_ID'],
'IBLOCK_EXPORT' => $boolExport,
'PROPERTIES_SKU' => $propertiesSKU,
'PROPERTIES_PRODUCT' => $propertiesProduct,
'OLD_PROPERTY_SKU_SELECT' => $oldPropertySKU,
'OLD_PROPERTY_PRODUCT_SELECT' => $oldPropertyProduct,
'SITE_LIST' => '('.implode(' ',$arSiteList).')',
);
if ($boolExport)
$intCountChecked++;
$intCountAvailIBlock++;
if ($boolExport)
$intCountChecked++;
$intCountAvailIBlock++;
}
}
}
@ -120,105 +172,148 @@ if ($STEP==1)
$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>
<font class="text" style="font-weight: bold;">Выбрать все инфоблоки </font>
<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' : ''); ?>>
</br>
</br>
<div>
<? $checkBoxCounter = 0;?>
<? foreach ($arIBlockList as $key => $arIBlock):?>
<div>
<div>
<font class="text" style="font-weight: bold;"><? echo htmlspecialcharsex("[".$arIBlock["IBLOCK_TYPE_ID"]."] ".$arIBlock["NAME"]." ".$arIBlock['SITE_LIST']); ?></font>
<input
type="checkbox"
name="IBLOCK_EXPORT[<?=$arIBlock["ID"]?>]"
id="IBLOCK_EXPORT<?=++$checkBoxCounter?>"
value="<?=$arIBlock["ID"]?>"
<? if ($arIBlock['IBLOCK_EXPORT']) echo " checked"; ?>
onclick="checkOne(this,<? echo $intCountAvailIBlock; ?>);"
>
</div>
<br>
<div id="IBLOCK_EXPORT_TABLE<?=$checkBoxCounter?>">
<table class="adm-list-table" id="export_setup" <?=($arIBlock['PROPERTIES_SKU'] == null ? 'style="width: 66%;"': "" )?> >
<thead>
<tr class="adm-list-table-header">
<td class="adm-list-table-cell">
<div class="adm-list-table-cell-inner">Выгружаемое свойство</div>
</td>
<td class="adm-list-table-cell">
<div class="adm-list-table-cell-inner">
<?echo GetMessage("EXPORT2INTAROCML");?>&nbsp;
</div>
<div class="adm-list-table-cell-inner">Свойство товара</div>
</td>
<? if ($arIBlock['PROPERTIES_SKU'] != null): ?>
<td class="adm-list-table-cell">
<div class="adm-list-table-cell-inner">Свойство торгового предложения</div>
</td>
<? endif;?>
</tr>
</thead>
<tbody>
<? foreach ($iblockPropertiesName as $key => $property): ?>
<? $productSelected = false;?>
<tr class="adm-list-table-row">
<td class="adm-list-table-cell">
<? echo htmlspecialcharsex($property); ?>
</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)
{
?>
<select
style="width: 200px;"
id="IBLOCK_PROPERTY_PRODUCT_<?=$key?><?=$arIBlock["ID"]?>"
name="IBLOCK_PROPERTY_PRODUCT[<?=$arIBlock["ID"]?>][<?=$key?>]"
class="property-export"
onchange="propertyChange(this);">
<option value=""></option>
<? foreach ($arIBlock['PROPERTIES_PRODUCT'] 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" )
<?
if ($arIBlock['OLD_PROPERTY_PRODUCT_SELECT'] != null) {
if ($prop["CODE"] == $arIBlock['OLD_PROPERTY_PRODUCT_SELECT'][$key] ) {
echo " selected";
$productSelected = true;
}
} else {
foreach ($iblockPropertiesHint[$key] as $hint) {
if ($prop["CODE"] == $hint ) {
echo " selected";
$productSelected = true;
break;
}
}
}
}
?>
>
?>
>
<?=$prop["NAME"];?>
</option>
<?
}
?>
</select>
</td>
</tr>
<?
}
?>
</tbody>
</table>
<? endforeach;?>
</select>
</td>
<? if ($arIBlock['PROPERTIES_SKU'] != null): ?>
<td class="adm-list-table-cell">
<select
style="width: 200px;"
id="IBLOCK_PROPERTY_SKU_<?=$key?><?=$arIBlock["ID"]?>"
name="IBLOCK_PROPERTY_SKU[<?=$arIBlock["ID"]?>][<?=$key?>]"
class="property-export"
onchange="propertyChange(this);">
<option value=""></option>
<? foreach ($arIBlock['PROPERTIES_SKU'] as $prop): ?>
<option value="<?=$prop['CODE'] ?>"
<?
if (!$productSelected) {
if ($arIBlock['OLD_PROPERTY_SKU_SELECT'] != null) {
if ($prop["CODE"] == $arIBlock['OLD_PROPERTY_SKU_SELECT'][$key] ) {
echo " selected";
}
} else {
foreach ($iblockPropertiesHint[$key] as $hint) {
if ($prop["CODE"] == $hint ) {
echo " selected";
break;
}
}
}
}
?>
>
<?=$prop["NAME"];?>
</option>
<? endforeach;?>
</select>
</td>
<? endif;?>
</tr>
<? endforeach;?>
</tbody>
</table>
<br>
<br>
</div>
</div>
<? endforeach;?>
</div>
<input type="hidden" name="count_checked" id="count_checked" value="<? echo $intCountChecked; ?>">
<br>
<br>
<br>
<h3>Настройки экспорта</h3>
<font class="text"><?=GetMessage("FILENAME");?><br><br></font>
<input type="text" name="SETUP_FILE_NAME"
value="<?=htmlspecialcharsbx(strlen($SETUP_FILE_NAME) > 0 ?
@ -252,22 +347,74 @@ if ($STEP==1)
<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);
for (i = 0; i < cnt; i++)
{
if (obj.checked)
BX.removeClass('IBLOCK_EXPORT_TABLE'+(i+1),"iblock-export-table-display-none");
}
var table = BX(obj.id.replace('IBLOCK_EXPORT','IBLOCK_EXPORT_TABLE'));
if (obj.checked)
BX.removeClass(table,"iblock-export-table-display-none");
var easing = new BX.easing({
duration : 150,
start : {opacity : obj.checked ? 0 : 100 },
finish : {opacity: obj.checked ? 100 : 0 },
transition : BX.easing.transitions.linear,
step : function(state){
for (i = 0; i < cnt; i++)
{
BX('IBLOCK_EXPORT_TABLE'+(i+1)).style.opacity = state.opacity/100;
}
},
complete : function() {
for (i = 0; i < cnt; i++)
{
if (!obj.checked)
BX.addClass('IBLOCK_EXPORT_TABLE'+(i+1),"iblock-export-table-display-none");
}
}
});
easing.animate();
var boolCheck = obj.checked;
for (i = 0; i < cnt; i++)
{
BX('IBLOCK_EXPORT'+(i+1)).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';
var table = BX(obj.id.replace('IBLOCK_EXPORT','IBLOCK_EXPORT_TABLE'));
if (obj.checked)
BX.removeClass(table,"iblock-export-table-display-none");
var easing = new BX.easing({
duration : 150,
start : {opacity : obj.checked ? 0 : 100 },
finish : {opacity: obj.checked ? 100 : 0 },
transition : BX.easing.transitions.linear,
step : function(state){
table.style.opacity = state.opacity/100;
},
complete : function() {
if (!obj.checked)
BX.addClass(table,"iblock-export-table-display-none");
}
});
easing.animate();
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;
};
function propertyChange(obj)
{
if (BX(obj.id).value !== 'none') {
if (obj.id.indexOf("SKU") !== -1)
BX(obj.id.replace('SKU','PRODUCT')).value = 'none';
else
BX(obj.id.replace('PRODUCT','SKU')).value = 'none';
}
};
</script>
@ -279,7 +426,7 @@ if ($STEP==1)
<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="hidden" name="SETUP_FIELDS_LIST" value="SETUP_FILE_NAME,IBLOCK_EXPORT,IBLOCK_PROPERTY_SKU,IBLOCK_PROPERTY_PRODUCT">
<input type="submit" value="<?echo ($ACTION=="EXPORT")?GetMessage("CET_EXPORT"):GetMessage("CET_SAVE")?>">

View File

@ -828,21 +828,22 @@ class intaro_intarocrm extends CModule {
$arResult['errCode'] = 'ERR_FIELDS_IBLOCK';
else
$iblocks = $_POST['IBLOCK_EXPORT'];
if (!isset($_POST['IBLOCK_PROPERTY_ARTICLE']))
$arResult['errCode'] = 'ERR_FIELDS_ARTICLE';
if(!isset($_POST['IBLOCK_PROPERTY_SKU']))
$arResult['errCode'] = 'ERR_FIELDS_SKU';
else
$articleProperties = $_POST['IBLOCK_PROPERTY_ARTICLE'];
$propertiesSKU = $_POST['IBLOCK_PROPERTY_SKU'];
if(!isset($_POST['IBLOCK_PROPERTY_PRODUCT']))
$arResult['errCode'] = 'ERR_FIELDS_PRODUCT';
else
$propertiesProduct = $_POST['IBLOCK_PROPERTY_PRODUCT'];
if (!isset($_POST['SETUP_FILE_NAME']))
$arResult['errCode'] = 'ERR_FIELDS_FILE';
else
$filename = $_POST['SETUP_FILE_NAME'];
if (count($iblocks) < count($articleProperties))
$arResult['errCode'] = 'ERR_ARTICLE_IBLOCK';
if (!isset($_POST['TYPE_LOADING']))
$typeLoading = 0;
else
@ -863,15 +864,16 @@ class intaro_intarocrm extends CModule {
$arOldValues = Array(
'IBLOCK_EXPORT' => $iblocks,
'IBLOCK_PROPERTY_ARTICLE' => $articleProperties,
'IBLOCK_PROPERTY_SKU' => $propertiesSKU,
'IBLOCK_PROPERTY_PRODUCT' => $propertiesProduct,
'SETUP_FILE_NAME' => $filename,
'SETUP_PROFILE_NAME' => $profileName
);
global $oldValues;
$oldValues = $arOldValues;
$APPLICATION->IncludeAdminFile(
GetMessage('MODULE_INSTALL_TITLE'),
$_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/step5.php'
GetMessage('MODULE_INSTALL_TITLE'),
$_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/step4.php'
);
return;
}
@ -883,12 +885,14 @@ class intaro_intarocrm extends CModule {
$loader = new ICMLLoader();
$loader->iblocks = $iblocks;
$loader->articleProperties = $articleProperties;
$loader->propertiesProduct = $propertiesProduct;
$loader->propertiesSKU = $propertiesSKU;
$loader->filename = $filename;
$loader->application = $APPLICATION;
$loader->Load();
}
}
if ($typeLoading == 'agent' || $typeLoading == 'cron') {
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));
@ -900,18 +904,18 @@ class intaro_intarocrm extends CModule {
}
}
}
$ar = $this->GetProfileSetupVars($iblocks, $articleProperties, $filename);
$ar = $this->GetProfileSetupVars($iblocks, $propertiesProduct, $propertiesSKU, $filename);
$PROFILE_ID = CCatalogExport::Add(array(
"LAST_USE" => false,
"FILE_NAME" => $this->INTARO_CRM_EXPORT,
"NAME" => $profileName,
"DEFAULT_PROFILE" => "N",
"IN_MENU" => "N",
"IN_AGENT" => "N",
"IN_CRON" => "N",
"NEED_EDIT" => "N",
"SETUP_VARS" => $ar
));
"LAST_USE" => false,
"FILE_NAME" => $this->INTARO_CRM_EXPORT,
"NAME" => $profileName,
"DEFAULT_PROFILE" => "N",
"IN_MENU" => "N",
"IN_AGENT" => "N",
"IN_CRON" => "N",
"NEED_EDIT" => "N",
"SETUP_VARS" => $ar
));
if (intval($PROFILE_ID) <= 0) {
$arResult['errCode'] = 'ERR_IBLOCK';
return;
@ -1075,21 +1079,26 @@ class intaro_intarocrm extends CModule {
unlink($_SERVER['DOCUMENT_ROOT'] . '/bitrix/php_interface/include/catalog_export/intarocrm_setup.php');
}
function GetProfileSetupVars($iblocks, $articleProperties, $filename) {
function GetProfileSetupVars($iblocks, $propertiesProduct, $propertiesSKU, $filename) {
// Get string like IBLOCK_EXPORT[0]=3&
// IBLOCK_EXPORT[1]=6&
// IBLOCK_PROPERTY_ARTICLE[0]=ARTICLE&
// IBLOCK_PROPERTY_ARTICLE[1]=ARTNUMBER&
// SETUP_FILE_NAME=%2Fbitrix%2Fcatalog_export%2Ftestintarocrm.xml
//$arProfileFields = explode(",", $SETUP_FIELDS_LIST);
$strVars = "";
foreach ($iblocks as $key => $val)
foreach ($iblocks as $key => $val)
$strVars .= 'IBLOCK_EXPORT[' . $key . ']=' . $val . '&';
foreach ($articleProperties as $key => $val)
$strVars .= 'IBLOCK_PROPERTY_ARTICLE[' . $key . ']=' . $val . '&';
foreach ($propertiesSKU as $iblock => $arr)
foreach ($arr as $id => $val)
$strVars .= 'IBLOCK_PROPERTY_SKU[' . $iblock . '][' . $id . ']=' . $val . '&';
foreach ($propertiesProduct as $iblock => $arr)
foreach ($arr as $id => $val)
$strVars .= 'IBLOCK_PROPERTY_PRODUCT[' . $iblock . '][' . $id . ']=' . $val . '&';
$strVars .= 'SETUP_FILE_NAME=' . urlencode($filename);
return $strVars;
}

View File

@ -11,60 +11,115 @@ if(isset($arResult['errCode']) && $arResult['errCode'])
global $oldValues;
if (!empty($oldValues)) {
$IBLOCK_EXPORT = $oldValues['IBLOCK_EXPORT'];
$IBLOCK_PROPERTY_ARTICLE = $oldValues['IBLOCK_PROPERTY_ARTICLE'];
$IBLOCK_PROPERTY_SKU = $oldValues['IBLOCK_PROPERTY_SKU'];
$IBLOCK_PROPERTY_PRODUCT = $oldValues['IBLOCK_PROPERTY_PRODUCT'];
$SETUP_FILE_NAME = $oldValues['SETUP_FILE_NAME'];
$SETUP_PROFILE_NAME = $oldValues['SETUP_PROFILE_NAME'];
}
?>
<form method="post" action="<?php echo $APPLICATION->GetCurPage(); ?>" >
<style type="text/css">
.iblock-export-table-display-none {
display: none;
}
</style>
<form method="post" action="<?php echo $APPLICATION->GetCurPage(); ?>" >
<h3>Настройки инфоблоков</h3>
<font class="text"><?=GetMessage("EXPORT_CATALOGS");?><br><br></font>
<?
if (!isset($IBLOCK_EXPORT) || !is_array($IBLOCK_EXPORT))
{
$IBLOCK_EXPORT = array();
}
$iblockPropertiesName = Array(
"article" => "Артикул",
"manufacturer" => "Производитель",
"color" => "Цвет",
"weight" => "Вес",
"size" => "Размер",
);
$iblockPropertiesHint = Array(
"article" => Array("ARTICLE", "ART", "ARTNUMBER", "ARTICUL", "ARTIKUL"),
"manufacturer" => Array("MANUFACTURER", "PROISVODITEL", "PROISVOD", "PROISV"),
"color" => Array("COLOR", "CVET"),
"weight" => Array("WEIGHT", "VES", "VEC"),
"size" => Array("SIZE", "RAZMER"),
);
$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())
while ($iblock = $db_res->Fetch())
{
if ($arCatalog = CCatalog::GetByIDExt($res["ID"]))
if ($arCatalog = CCatalog::GetByIDExt($iblock["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();
$propertiesSKU = null;
if ($arCatalog['CATALOG_TYPE'] == "X" || $arCatalog['CATALOG_TYPE'] == "P")
{
$iblockOffer = CCatalogSKU::GetInfoByProductIBlock($iblock["ID"]);
$db_properties = CIBlock::GetProperties($iblockOffer['IBLOCK_ID'], Array());
while($prop = $db_properties->Fetch())
$properties[] = $prop;
$propertiesSKU[] = $prop;
$oldPropertySKU = null;
if (isset($IBLOCK_PROPERTY_SKU[$iblock['ID']])) {
foreach ($iblockPropertiesName as $key => $prop) {
$oldPropertySKU[$key] = $IBLOCK_PROPERTY_SKU[$iblock['ID']][$key];
}
}
}
$propertiesProduct = null;
$db_properties = CIBlock::GetProperties($iblock['ID'], Array());
while($prop = $db_properties->Fetch())
$propertiesProduct[] = $prop;
$oldPropertyProduct = null;
if (isset($IBLOCK_PROPERTY_PRODUCT[$iblock['ID']])) {
foreach ($iblockPropertiesName as $key => $prop) {
$oldPropertyProduct[$key] = $IBLOCK_PROPERTY_PRODUCT[$iblock['ID']][$key];
}
}
$arSiteList = array();
$rsSites = CIBlock::GetSite($iblock["ID"]);
while ($arSite = $rsSites->Fetch())
{
$arSiteList[] = $arSite["SITE_ID"];
}
if (count($IBLOCK_EXPORT) != 0)
$boolExport = (in_array($res['ID'], $IBLOCK_EXPORT));
else
$boolExport = true;
if (count($IBLOCK_EXPORT) != 0)
$boolExport = (in_array($iblock['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).')',
);
$arIBlockList[] = array(
'ID' => $iblock['ID'],
'NAME' => $iblock['NAME'],
'IBLOCK_TYPE_ID' => $iblock['IBLOCK_TYPE_ID'],
'IBLOCK_EXPORT' => $boolExport,
'PROPERTIES_SKU' => $propertiesSKU,
'PROPERTIES_PRODUCT' => $propertiesProduct,
'OLD_PROPERTY_SKU_SELECT' => $oldPropertySKU,
'OLD_PROPERTY_PRODUCT_SELECT' => $oldPropertyProduct,
'SITE_LIST' => '('.implode(' ',$arSiteList).')',
);
if ($boolExport)
$intCountChecked++;
$intCountAvailIBlock++;
if ($boolExport)
$intCountChecked++;
$intCountAvailIBlock++;
}
}
}
@ -78,99 +133,141 @@ if (!empty($oldValues)) {
?>
<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>
<font class="text" style="font-weight: bold;">Выбрать все инфоблоки </font>
<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' : ''); ?>>
</br>
</br>
<div>
<? $checkBoxCounter = 0;?>
<? foreach ($arIBlockList as $key => $arIBlock):?>
<div>
<div>
<font class="text" style="font-weight: bold;"><? echo htmlspecialcharsex("[".$arIBlock["IBLOCK_TYPE_ID"]."] ".$arIBlock["NAME"]." ".$arIBlock['SITE_LIST']); ?></font>
<input
type="checkbox"
name="IBLOCK_EXPORT[<?=$arIBlock["ID"]?>]"
id="IBLOCK_EXPORT<?=++$checkBoxCounter?>"
value="<?=$arIBlock["ID"]?>"
<? if ($arIBlock['IBLOCK_EXPORT']) echo " checked"; ?>
onclick="checkOne(this,<? echo $intCountAvailIBlock; ?>);"
>
</div>
<br>
<div id="IBLOCK_EXPORT_TABLE<?=$checkBoxCounter?>">
<table class="adm-list-table" id="export_setup" <?=($arIBlock['PROPERTIES_SKU'] == null ? 'style="width: 66%;"': "" )?> >
<thead>
<tr class="adm-list-table-header">
<td class="adm-list-table-cell">
<div class="adm-list-table-cell-inner">Выгружаемое свойство</div>
</td>
<td class="adm-list-table-cell">
<div class="adm-list-table-cell-inner">
<?echo GetMessage("EXPORT2INTAROCML");?>&nbsp;
</div>
<div class="adm-list-table-cell-inner">Свойство товара</div>
</td>
<? if ($arIBlock['PROPERTIES_SKU'] != null): ?>
<td class="adm-list-table-cell">
<div class="adm-list-table-cell-inner">Свойство торгового предложения</div>
</td>
<? endif;?>
</tr>
</thead>
<tbody>
<? foreach ($iblockPropertiesName as $key => $property): ?>
<? $productSelected = false;?>
<tr class="adm-list-table-row">
<td class="adm-list-table-cell">
<? echo htmlspecialcharsex($property); ?>
</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)
{
?>
<select
style="width: 200px;"
id="IBLOCK_PROPERTY_PRODUCT_<?=$key?><?=$arIBlock["ID"]?>"
name="IBLOCK_PROPERTY_PRODUCT[<?=$arIBlock["ID"]?>][<?=$key?>]"
class="property-export"
onchange="propertyChange(this);">
<option value=""></option>
<? foreach ($arIBlock['PROPERTIES_PRODUCT'] as $prop): ?>
<option value="<?=$prop['CODE'] ?>"
<?
if ($arIBlock['OLD_PROPERTY_SELECT'] == $prop["CODE"]){
echo " selected";
} else {
if ($prop["CODE"] == "ARTICLE" ||
$prop["CODE"] == "ART" ||
$prop["CODE"] == "ARTNUMBER" )
<?
if ($arIBlock['OLD_PROPERTY_PRODUCT_SELECT'] != null) {
if ($prop["CODE"] == $arIBlock['OLD_PROPERTY_PRODUCT_SELECT'][$key] ) {
echo " selected";
}
?>
>
$productSelected = true;
}
} else {
foreach ($iblockPropertiesHint[$key] as $hint) {
if ($prop["CODE"] == $hint ) {
echo " selected";
$productSelected = true;
break;
}
}
}
?>
>
<?=$prop["NAME"];?>
</option>
<?
}
?>
</select>
</td>
</tr>
<?
}
?>
</tbody>
</table>
<? endforeach;?>
</select>
</td>
<? if ($arIBlock['PROPERTIES_SKU'] != null): ?>
<td class="adm-list-table-cell">
<select
style="width: 200px;"
id="IBLOCK_PROPERTY_SKU_<?=$key?><?=$arIBlock["ID"]?>"
name="IBLOCK_PROPERTY_SKU[<?=$arIBlock["ID"]?>][<?=$key?>]"
class="property-export"
onchange="propertyChange(this);">
<option value=""></option>
<? foreach ($arIBlock['PROPERTIES_SKU'] as $prop): ?>
<option value="<?=$prop['CODE'] ?>"
<?
if (!$productSelected) {
if ($arIBlock['OLD_PROPERTY_SKU_SELECT'] != null) {
if ($prop["CODE"] == $arIBlock['OLD_PROPERTY_SKU_SELECT'][$key] ) {
echo " selected";
}
} else {
foreach ($iblockPropertiesHint[$key] as $hint) {
if ($prop["CODE"] == $hint ) {
echo " selected";
break;
}
}
}
}
?>
>
<?=$prop["NAME"];?>
</option>
<? endforeach;?>
</select>
</td>
<? endif;?>
</tr>
<? endforeach;?>
</tbody>
</table>
<br>
<br>
</div>
</div>
<? endforeach;?>
</div>
<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"