From 04ea0ea00eb95a30a1c1ce4d52b7b4ef758889b0 Mon Sep 17 00:00:00 2001 From: "m.korolev" Date: Tue, 20 Aug 2013 12:53:32 +0400 Subject: [PATCH] refactoring export run and setup --- .../classes/general/ICMLLoader.php | 26 +- intaro.intarocrm/export/export_run.php | 19 ++ intaro.intarocrm/export/export_setup.php | 286 ++++++++++++++++++ .../install/export/intarocrm_run.php | 17 +- .../install/export/intarocrm_setup.php | 254 +--------------- intaro.intarocrm/install/index.php | 23 +- intaro.intarocrm/install/step4.php | 64 ++-- .../lang/ru/icml_export_setup.php | 5 + intaro.intarocrm/lang/ru/install/index.php | 3 +- 9 files changed, 402 insertions(+), 295 deletions(-) create mode 100644 intaro.intarocrm/export/export_run.php create mode 100644 intaro.intarocrm/export/export_setup.php 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 @@ +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) +{ + + +?> +
+

+ "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; + } + + ?> + + + + + + + + + + + + + + + + + + $arIBlock) + { + ?> + + + + + + + +
+
+
+
+   +
+
+
+
+ + + > + + +   +
+ + + + " + + onclick="checkOne(this,);" + > + + + +
+ +
+
+
+ +

+ + +
+
+
+ + + +

+ +
+
+
+ + + + + + + + + + + + "> + + + + "> + + +
+ + \ 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) -{ - - -?> -
-

- "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; - - - $boolExport = (in_array($res['ID'],$IBLOCK_EXPORT)); - $arIBlockList[] = array( - 'ID' => $res['ID'], - 'NAME' => $res['NAME'], - 'IBLOCK_TYPE_ID' => $res['IBLOCK_TYPE_ID'], - 'IBLOCK_EXPORT' => $boolExport, - 'PROPERTIES' => $properties, - 'SITE_LIST' => '('.implode(' ',$arSiteList).')', - ); - - if ($boolExport) - $intCountChecked++; - $intCountAvailIBlock++; - } - } - } - $intCountChecked = $intCountAvailIBlock; - $boolAll = true; - - ?> - - - - - - - - - - - - - - - - - - $arIBlock) - { - ?> - - - - - - - -
-
-
-
-   -
-
-
-
- - - > - - -   -
- - - - " - - onclick="checkOne(this,);" - > - - - -
- -
-
-
- -

- - -
-
-
- - - -

- -
-
-
- - - - - - - - - - - - "> - - - - "> - - -
- - \ 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.


@@ -40,14 +47,18 @@ if(isset($arResult['errCode']) && $arResult['errCode']) while($prop = $db_properties->Fetch()) $properties[] = $prop; + if (count($IBLOCK_EXPORT) != 0) + $boolExport = (in_array($res['ID'], $IBLOCK_EXPORT)); + else + $boolExport = true; - $boolExport = (in_array($res['ID'],$IBLOCK_EXPORT)); $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).')', ); @@ -57,8 +68,13 @@ if(isset($arResult['errCode']) && $arResult['errCode']) } } } - $intCountChecked = $intCountAvailIBlock; - $boolAll = true; + if (count($IBLOCK_EXPORT) != 0) { + if ($intCountChecked == $intCountAvailIBlock) + $boolAll = true; + } else { + $intCountChecked = $intCountAvailIBlock; + $boolAll = true; + } ?> @@ -104,10 +120,9 @@ if(isset($arResult['errCode']) && $arResult['errCode']) ]" + id="IBLOCK_EXPORT" value="" onclick="checkOne(this,);" @@ -115,16 +130,28 @@ if(isset($arResult['errCode']) && $arResult['errCode']) - " + name="IBLOCK_PROPERTY_ARTICLE[]" + class="property-export"> @@ -176,7 +203,7 @@ if(isset($arResult['errCode']) && $arResult['errCode']) " + value="" size="30">

@@ -196,11 +223,13 @@ if(isset($arResult['errCode']) && $arResult['errCode']) }; 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; + 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'; }; function checkProfile(obj) { @@ -230,3 +259,4 @@ if(isset($arResult['errCode']) && $arResult['errCode'])
+ diff --git a/intaro.intarocrm/lang/ru/icml_export_setup.php b/intaro.intarocrm/lang/ru/icml_export_setup.php index de7d80b4..7f93c1af 100644 --- a/intaro.intarocrm/lang/ru/icml_export_setup.php +++ b/intaro.intarocrm/lang/ru/icml_export_setup.php @@ -9,4 +9,9 @@ $MESS["PROPERTY"] = "Свойство, содержащее артикул то $MESS["ALL_CATALOG"] = "Все каталоги"; $MESS["CET_EXPORT"] = "Экспортировать"; $MESS["CET_SAVE"] = "Сохранить"; +$MESS["ERROR_IBLOCK_MODULE"] = "Модуль Инфоблоки не установлен"; +$MESS["ERROR_IBLOCK_CATALOG"] = "Модуль Каталог не установлен"; +$MESS["ERROR_IBLOCK_INTAROCRM"] = "Модуль IntaroCRM не установлен"; +$MESS["ERROR_ARTICLE_NOT_SET"] = "Не установлены поля артикулов"; + ?> \ No newline at end of file diff --git a/intaro.intarocrm/lang/ru/install/index.php b/intaro.intarocrm/lang/ru/install/index.php index f277e56c..4637485b 100755 --- a/intaro.intarocrm/lang/ru/install/index.php +++ b/intaro.intarocrm/lang/ru/install/index.php @@ -10,4 +10,5 @@ $MESS ['ERR_SALE'] = 'Отсутствует модуль sale! Дальнейш $MESS ['ERR_IBLOCK'] = 'Отсутствует модуль iblock! Дальнейшая установка невозможна.'; $MESS ['ERR_CATALOG'] = 'Отсутствует модуль catalog! Дальнейшая установка невозможна.'; $MESS ['ERR_CATALOG'] = 'Отсутствует модуль catalog! Дальнейшая установка невозможна.'; -$MESS ['INTAROCRM_CURL_ERR'] = 'Для работы модуля интеграции с IntaroCRM требуется PHP-расширение CURL.'; \ No newline at end of file +$MESS ['INTAROCRM_CURL_ERR'] = 'Для работы модуля интеграции с IntaroCRM требуется PHP-расширение CURL.'; +$MESS ['ERR_ARTICLE_IBLOCK'] = 'Не установлены артикулы'; \ No newline at end of file