diff --git a/intaro.intarocrm/classes/general/ICMLLoader.php b/intaro.intarocrm/classes/general/ICMLLoader.php
index b28e36ce..af3ea5ac 100644
--- a/intaro.intarocrm/classes/general/ICMLLoader.php
+++ b/intaro.intarocrm/classes/general/ICMLLoader.php
@@ -7,13 +7,14 @@ 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()
{
global $USER;
@@ -22,7 +23,9 @@ class ICMLLoader {
if (count($this->iblocks) < count($this->articleProperties))
return false;
-
+
+ $this->PrepareSettings();
+
$this->PrepareFile();
$this->PreWriteCatalog();
@@ -41,7 +44,21 @@ class ICMLLoader {
return true;
}
-
+
+ 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);
@@ -63,12 +80,11 @@ class ICMLLoader {
protected function PreWriteCatalog()
{
- @fwrite($this->fp, "PrepareValue(Date("Y-m-d H:i:s")) . "\">\n");
- @fwrite($this->fp, "\n");
-
- @fwrite($this->fp, "". $this->PrepareValue(COption::GetOptionString("main", "site_name", ""))."\n");
-
- @fwrite($this->fp, "".$this->PrepareValue(COption::GetOptionString("main", "site_name", ""))."\n");
+ @fwrite($this->fp, "PrepareValue(Date("Y-m-d H:i:s")) . "\">\n
+ \n
+ " . $this->PrepareValue(COption::GetOptionString("main", "site_name", ""))."\n
+ " . $this->PrepareValue(COption::GetOptionString("main", "site_name", ""))."\n"
+ );
}
@@ -99,8 +115,8 @@ class ICMLLoader {
protected function PostWriteCatalog()
{
- @fwrite($this->fp, "\n");
- @fwrite($this->fp, "\n");
+ @fwrite($this->fp, "\n
+ \n");
}
protected function CloseFile()
@@ -160,11 +176,9 @@ class ICMLLoader {
{
foreach ($this->iblocks as $key => $id)
{
-
$iblock['IBLOCK_DB'] = CIBlock::GetByID($id)->Fetch();
$iblockOffer = CCatalogSKU::GetInfoByProductIBlock($id);
-
$arSelect = Array (
"ID",
"LID",
@@ -180,10 +194,12 @@ class ICMLLoader {
"LANG_DIR",
"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 (
"IBLOCK_ID" => $id,
@@ -198,7 +214,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()) {
@@ -216,8 +248,7 @@ class ICMLLoader {
$existOffer = false;
if (!empty($iblockOffer['IBLOCK_ID'])) {
-
-
+
$arFilterOffer = Array (
'IBLOCK_ID' => $iblockOffer['IBLOCK_ID'],
'PROPERTY_' . $iblockOffer['SKU_PROPERTY_ID'] => $product["ID"]
@@ -229,9 +260,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()) {
@@ -244,9 +277,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'];
@@ -261,8 +312,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'];
@@ -326,9 +380,12 @@ class ICMLLoader {
$offer .= "" . $this->PrepareValue($arOffer["EXTERNAL_ID"]) . "\n";
$offer .= "" . $this->PrepareValue($arOffer["PRODUCT_NAME"]) . "\n";
- if (isset($arOffer["ARTICLE"]))
- $offer .= "" . $this->PrepareValue($arOffer["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.= "\n";
return $offer;
}
diff --git a/intaro.intarocrm/export/export_run.php b/intaro.intarocrm/export/export_run.php
index ea2d7464..b0ddb912 100644
--- a/intaro.intarocrm/export/export_run.php
+++ b/intaro.intarocrm/export/export_run.php
@@ -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();
\ No newline at end of file
diff --git a/intaro.intarocrm/export/export_setup.php b/intaro.intarocrm/export/export_setup.php
index 1fafdeee..008ddf9a 100644
--- a/intaro.intarocrm/export/export_setup.php
+++ b/intaro.intarocrm/export/export_setup.php
@@ -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)
?>
+
+
+