diff --git a/intaro.intarocrm/classes/general/ICMLLoader.php b/intaro.intarocrm/classes/general/ICMLLoader.php
index 20285b5b..b976454e 100644
--- a/intaro.intarocrm/classes/general/ICMLLoader.php
+++ b/intaro.intarocrm/classes/general/ICMLLoader.php
@@ -9,6 +9,7 @@ class ICMLLoader {
public $encoding = 'utf-8';
protected $fp;
+ protected $mainSection = 1000000;
public function Load()
{
@@ -16,6 +17,9 @@ class ICMLLoader {
if(!isset($USER))
$USER = new CUser;
+ if (count($this->iblocks) != count($this->articleProperties))
+ return false;
+
$categories = $this->GetCategories();
$offers = $this->GetOffers();
@@ -30,6 +34,7 @@ class ICMLLoader {
$this->PostWriteCatalog();
$this->CloseFile();
+ return true;
}
@@ -107,6 +112,14 @@ class ICMLLoader {
{
$categories[] = $this->BuildCategory($arRes);
}
+ if (count($categories) == 0)
+ {
+ $arRes = Array();
+ $arRes['ID'] = $this->mainSection + $id;
+ $arRes['IBLOCK_SECTION_ID'] = 0;
+ $arRes['NAME'] = "Основной раздел каталога";
+ $categories[] = $this->BuildCategory($arRes);
+ }
}
return $categories;
@@ -149,7 +162,7 @@ class ICMLLoader {
"DETAIL_PICTURE",
"LANG_DIR",
"DETAIL_PAGE_URL",
- "PROPERTY_" . $this->articleProperties[$key]
+ "PROPERTY_" . $this->articleProperties[$id]
);
$filter = Array (
@@ -179,7 +192,7 @@ class ICMLLoader {
"DETAIL_TEXT",
"DETAIL_PAGE_URL",
"DETAIL_PICTURE",
- "PROPERTY_" . $this->articleProperties[$key]
+ "PROPERTY_" . $this->articleProperties[$id]
);
$rsOffers = CIBlockElement::GetList(array(), $arFilterOffer, false, false, $arSelectOffer);
@@ -189,6 +202,8 @@ class ICMLLoader {
while ($arResCategory = $dbResCategories->Fetch()) {
$categoriesString .= "" . $arResCategory["ID"] . "\n";
}
+ if ($categoriesString == '')
+ $categoriesString .= "" . ($this->mainSection + $id) . "\n";
$offer = CCatalogProduct::GetByID($arOffer['ID']);
$arOffer['QUANTITY'] = $offer["QUANTITY"];
@@ -197,7 +212,7 @@ class ICMLLoader {
$arOffer['DETAIL_PICTURE'] = $product["DETAIL_PICTURE"];
$arOffer['PREVIEW_PICTURE'] = $product["PREVIEW_PICTURE"];
$arOffer['PRODUCT_NAME'] = $product["NAME"];
- $arOffer['ARTICLE'] = $arOffer["PROPERTY_" . $this->articleProperties[$key] . "_VALUE"];
+ $arOffer['ARTICLE'] = $arOffer["PROPERTY_" . $this->articleProperties[$id] . "_VALUE"];
$dbPrice = GetCatalogProductPrice($arOffer["ID"],1);
$arOffer['PRICE'] = $dbPrice['PRICE'];
@@ -213,14 +228,15 @@ class ICMLLoader {
while ($arResCategory = $dbResCategories->Fetch()) {
$categoriesString .= "" . $arResCategory["ID"] . "\n";
}
-
+ if ($categoriesString == '')
+ $categoriesString .= "" . ($this->mainSection + $id) . "\n";
$offer = CCatalogProduct::GetByID($product['ID']);
$product['QUANTITY'] = $offer["QUANTITY"];
$product['PRODUCT_ID'] = $product["ID"];
$product['PRODUCT_NAME'] = $product["NAME"];
- $product['ARTICLE'] = $product["PROPERTY_" . $this->articleProperties[$key] . "_VALUE"];
+ $product['ARTICLE'] = $product["PROPERTY_" . $this->articleProperties[$id] . "_VALUE"];
$dbPrice = GetCatalogProductPrice($product["ID"],1);
$product['PRICE'] = $dbPrice['PRICE'];
diff --git a/intaro.intarocrm/export/export_run.php b/intaro.intarocrm/export/export_run.php
new file mode 100644
index 00000000..ea2d7464
--- /dev/null
+++ b/intaro.intarocrm/export/export_run.php
@@ -0,0 +1,19 @@
+iblocks = $IBLOCK_EXPORT;
+$loader->articleProperties = $IBLOCK_PROPERTY_ARTICLE;
+$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
new file mode 100644
index 00000000..40925907
--- /dev/null
+++ b/intaro.intarocrm/export/export_setup.php
@@ -0,0 +1,286 @@
+
+
+
+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('
', $arSetupErrors));
+
+
+if ($STEP==1)
+{
+
+
+?>
+
+
+
+}
+elseif ($STEP==2)
+{
+
+ $FINITE = true;
+}
+
+?>
\ No newline at end of file
diff --git a/intaro.intarocrm/install/export/intarocrm_run.php b/intaro.intarocrm/install/export/intarocrm_run.php
index 23091100..5d73dc38 100644
--- a/intaro.intarocrm/install/export/intarocrm_run.php
+++ b/intaro.intarocrm/install/export/intarocrm_run.php
@@ -1,18 +1,3 @@
//IntaroCRM
-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();
\ No newline at end of file
+require($_SERVER["DOCUMENT_ROOT"]."/bitrix/intaro.intarocrm/export/load/export_run.php");
\ No newline at end of file
diff --git a/intaro.intarocrm/install/export/intarocrm_setup.php b/intaro.intarocrm/install/export/intarocrm_setup.php
index c567272a..b9feee9f 100644
--- a/intaro.intarocrm/install/export/intarocrm_setup.php
+++ b/intaro.intarocrm/install/export/intarocrm_setup.php
@@ -1,255 +1,3 @@
//IntaroCRM
-
-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 ($STEP>1)
-{
-
- 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('
', $arSetupErrors));
-
-
-if ($STEP==1)
-{
-
-
-?>
-
-
-
-}
-elseif ($STEP==2)
-{
- $FINITE = true;
-}
-
-?>
\ No newline at end of file
+require($_SERVER["DOCUMENT_ROOT"]."/bitrix/intaro.intarocrm/export/load/export_setup.php");
\ No newline at end of file
diff --git a/intaro.intarocrm/install/index.php b/intaro.intarocrm/install/index.php
index c79ddce8..9d061bf0 100755
--- a/intaro.intarocrm/install/index.php
+++ b/intaro.intarocrm/install/index.php
@@ -662,7 +662,7 @@ class intaro_intarocrm extends CModule
);
}
- if(!isset($_POST['IBLOCK_EXPORT']))
+ if(!isset($_POST['IBLOCK_EXPORT']))
$arResult['errCode'] = 'ERR_FIELDS_IBLOCK';
else
$iblocks = $_POST['IBLOCK_EXPORT'];
@@ -677,6 +677,9 @@ class intaro_intarocrm extends CModule
else
$filename = $_POST['SETUP_FILE_NAME'];
+ if (count($iblocks) != count($articleProperties))
+ $arResult['errCode'] = 'ERR_ARTICLE_IBLOCK';
+
if(!isset($_POST['TYPE_LOADING']))
$typeLoading = 0;
@@ -691,7 +694,18 @@ class intaro_intarocrm extends CModule
if ($typeLoading != 'none' && $profileName == "")
$arResult['errCode'] = 'ERR_FIELDS_PROFILE';
+
if(isset($arResult['errCode']) && $arResult['errCode']) {
+
+
+ $arOldValues = Array(
+ 'IBLOCK_EXPORT' => $iblocks,
+ 'IBLOCK_PROPERTY_ARTICLE' => $articleProperties,
+ '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/step4.php'
@@ -839,7 +853,10 @@ class intaro_intarocrm extends CModule
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);
+ $this->INTARO_CRM_API = new \IntaroCrm\RestApi($api_host, $api_key);
+ $this->INTARO_CRM_API->statisticUpdate();
$APPLICATION->IncludeAdminFile(
GetMessage('MODULE_INSTALL_TITLE'),
@@ -918,4 +935,4 @@ class intaro_intarocrm extends CModule
return $strVars;
}
-}
+}
\ No newline at end of file
diff --git a/intaro.intarocrm/install/step4.php b/intaro.intarocrm/install/step4.php
index 00a72f55..fa6a5c65 100644
--- a/intaro.intarocrm/install/step4.php
+++ b/intaro.intarocrm/install/step4.php
@@ -8,6 +8,13 @@ __IncludeLang(GetLangFileName($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/intaro.