diff --git a/intaro.intarocrm/classes/general/ICMLLoader.php b/intaro.intarocrm/classes/general/ICMLLoader.php
index 4ba5659b..20285b5b 100644
--- a/intaro.intarocrm/classes/general/ICMLLoader.php
+++ b/intaro.intarocrm/classes/general/ICMLLoader.php
@@ -9,303 +9,271 @@ class ICMLLoader {
public $encoding = 'utf-8';
protected $fp;
- public static function AgentLoad3( $filename)
- {
- echo $filename;
- $arFilename = "'" . $filename . "'";
- return "ICMLLoader::AgentLoad( " . $arFilename . ");";
- }
- public static function AgentLoad($iblocks, $filename)
- {
-
- if (!CModule::IncludeModule("iblock")) {
- //handle err
- self::eventLog('ICMLLoader::AgentLoad', 'iblock', 'module not found');
- return true;
- }
-
- if (!CModule::IncludeModule("catalog")) {
- //handle err
- self::eventLog('ICMLLoader::AgentLoad', 'catalog', 'module not found');
- return true;
- }
-
- global $APPLICATION, $USER;
- if(!isset($USER)) {
- $USER = new CUser;
- }
- $loader = new ICMLLoader();
- $loader->iblocks = json_decode($iblocks, true);
- $loader->filename = $filename;
- $loader->application = $APPLICATION;
- $loader->Load();
- $arIblocks = "'" . $iblocks . "'";
- $arFilename = "'" . $filename . "'";
- return "ICMLLoader::AgentLoad(" . $arIblocks . ", " . $arFilename . ");";
- }
public function Load()
{
- $categories = $this->GetCategories();
-
- $offers = $this->GetOffers();
-
- $this->PrepareFile();
-
- $this->PreWriteCatalog();
-
- $this->WriteCategories($categories);
- $this->WriteOffers($offers);
-
- $this->PostWriteCatalog();
-
- $this->CloseFile();
+ global $USER;
+ if(!isset($USER))
+ $USER = new CUser;
+
+ $categories = $this->GetCategories();
+
+ $offers = $this->GetOffers();
+
+ $this->PrepareFile();
+
+ $this->PreWriteCatalog();
+
+ $this->WriteCategories($categories);
+ $this->WriteOffers($offers);
+
+ $this->PostWriteCatalog();
+
+ $this->CloseFile();
}
protected function PrepareValue($text)
{
- return $this->application->ConvertCharset($text, LANG_CHARSET, $this->encoding);
+ return $this->application->ConvertCharset($text, LANG_CHARSET, $this->encoding);
}
protected function PrepareFile()
{
- $fullFilename = $_SERVER["DOCUMENT_ROOT"] . $this->filename;
- CheckDirPath($fullFilename);
-
- if (!$this->fp = @fopen($fullFilename, "w"))
- return false;
- else
- return true;
+ $fullFilename = $_SERVER["DOCUMENT_ROOT"] . $this->filename;
+ CheckDirPath($fullFilename);
+
+ if (!$this->fp = @fopen($fullFilename, "w"))
+ return false;
+ else
+ return true;
}
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");
+ @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");
+
}
protected function WriteCategories($categories)
{
- @fwrite($this->fp, "\n");
- foreach ($categories as $category) {
- @fwrite($this->fp, $category . "\n");
- }
- @fwrite($this->fp, "\n");
+ @fwrite($this->fp, "\n");
+ foreach ($categories as $category) {
+ @fwrite($this->fp, $category . "\n");
+ }
+ @fwrite($this->fp, "\n");
}
protected function WriteOffers($offers)
{
- @fwrite($this->fp, "\n");
- foreach ($offers as $offer) {
- @fwrite($this->fp, $offer . "\n");
- }
- @fwrite($this->fp, "\n");
+ @fwrite($this->fp, "\n");
+ foreach ($offers as $offer) {
+ @fwrite($this->fp, $offer . "\n");
+ }
+ @fwrite($this->fp, "\n");
}
protected function PostWriteCatalog()
{
- @fwrite($this->fp, "\n");
- @fwrite($this->fp, "\n");
+ @fwrite($this->fp, "\n");
+ @fwrite($this->fp, "\n");
}
protected function CloseFile()
{
- @fclose($this->fp);
+ @fclose($this->fp);
}
protected function GetCategories()
{
- $categories = array();
- foreach ($this->iblocks as $id)
- {
- $filter = Array(
- "IBLOCK_ID" => $id,
- "ACTIVE" => "Y",
- "IBLOCK_ACTIVE" => "Y",
- "GLOBAL_ACTIVE" => "Y"
- );
-
-
- $dbRes = CIBlockSection::GetList(array("left_margin" => "asc"), $filter);
- while ($arRes = $dbRes->Fetch())
- {
- $categories[] = $this->BuildCategory($arRes);
- }
- }
- return $categories;
+ $categories = array();
+ foreach ($this->iblocks as $id)
+ {
+ $filter = Array(
+ "IBLOCK_ID" => $id,
+ "ACTIVE" => "Y",
+ "IBLOCK_ACTIVE" => "Y",
+ "GLOBAL_ACTIVE" => "Y"
+ );
+
+
+ $dbRes = CIBlockSection::GetList(array("left_margin" => "asc"), $filter);
+ while ($arRes = $dbRes->Fetch())
+ {
+ $categories[] = $this->BuildCategory($arRes);
+ }
+ }
+ return $categories;
}
protected function BuildCategory($arCategory)
{
- return "
- PrepareValue($arCategory["ID"]) . "\""
- . ( intval($arCategory["IBLOCK_SECTION_ID"] ) > 0 ?
- " parentId=\"" . $this->PrepareValue($arCategory["IBLOCK_SECTION_ID"]) . "\""
- :"")
- . ">"
- . $this->PrepareValue($arCategory["NAME"])
- . "";
+ return "
+ PrepareValue($arCategory["ID"]) . "\""
+ . ( intval($arCategory["IBLOCK_SECTION_ID"] ) > 0 ?
+ " parentId=\"" . $this->PrepareValue($arCategory["IBLOCK_SECTION_ID"]) . "\""
+ :"")
+ . ">"
+ . $this->PrepareValue($arCategory["NAME"])
+ . "";
}
protected function GetOffers()
{
- $offers = Array();
- foreach ($this->iblocks as $key => $id)
- {
-
- $iblock['IBLOCK_DB'] = CIBlock::GetByID($id)->Fetch();
- $iblockOffer = CCatalogSKU::GetInfoByProductIBlock($id);
-
-
- $arSelect = Array (
- "ID",
- "LID",
- "IBLOCK_ID",
- "IBLOCK_SECTION_ID",
- "ACTIVE",
- "ACTIVE_FROM",
- "ACTIVE_TO",
- "NAME",
- "DETAIL_PICTURE",
- "DETAIL_TEXT",
- "DETAIL_PICTURE",
- "LANG_DIR",
- "DETAIL_PAGE_URL",
- "PROPERTY_" . $this->articleProperties[$key]
- );
+ $offers = Array();
+ foreach ($this->iblocks as $key => $id)
+ {
- $filter = Array (
- "IBLOCK_ID" => $id,
- "ACTIVE_DATE" => "Y",
- "ACTIVE" => "Y",
- "INCLUDE_SUBSECTIONS" => "Y"
- );
-
- $dbResProducts = CIBlockElement::GetList(array(), $filter, false, false, $arSelect);
- while ($product = $dbResProducts->GetNextElement()) {
-
- $product = $product->GetFields();
-
- $categoriesString = "";
-
-
- $existOffer = false;
- if (!empty($iblockOffer['IBLOCK_ID'])) {
- $arFilterOffer = Array (
- 'IBLOCK_ID' => $iblockOffer['IBLOCK_ID'],
- 'PROPERTY_'.$iblockOffer['SKU_PROPERTY_ID'] => $product["ID"]
- );
- $arSelectOffer = Array (
- 'ID',
- "NAME",
- "DETAIL_TEXT",
- "DETAIL_PAGE_URL",
- "DETAIL_PICTURE",
- "PROPERTY_" . $this->articleProperties[$key]
- );
-
- $rsOffers = CIBlockElement::GetList(array(), $arFilterOffer, false, false, $arSelectOffer);
- while ($arOffer = $rsOffers->GetNext()) {
-
- $dbResCategories = CIBlockElement::GetElementGroups($arOffer['ID'], true);
- while ($arResCategory = $dbResCategories->Fetch()) {
- $categoriesString .= "" . $arResCategory["ID"] . "\n";
- }
- $offer = CCatalogProduct::GetByID($arOffer['ID']);
- $arOffer['QUANTITY'] = $offer["QUANTITY"];
-
- $arOffer['PRODUCT_ID'] = $product["ID"];
- $arOffer['DETAIL_PAGE_URL'] = $product["DETAIL_PAGE_URL"];
- $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"];
-
- $dbPrice = GetCatalogProductPrice($arOffer["ID"],1);
- $arOffer['PRICE'] = $dbPrice['PRICE'];
-
-
-
- $offers[] = $this->BuildOffer($arOffer, $categoriesString, $iblock);
- $existOffer = true;
- }
- }
- if (!$existOffer) {
- $dbResCategories = CIBlockElement::GetElementGroups($product["ID"], true);
- while ($arResCategory = $dbResCategories->Fetch()) {
- $categoriesString .= "" . $arResCategory["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"];
-
- $dbPrice = GetCatalogProductPrice($product["ID"],1);
- $product['PRICE'] = $dbPrice['PRICE'];
-
- $offers[] = $this->BuildOffer($product, $categoriesString, $iblock);
- }
- }
- }
- return $offers;
+ $iblock['IBLOCK_DB'] = CIBlock::GetByID($id)->Fetch();
+ $iblockOffer = CCatalogSKU::GetInfoByProductIBlock($id);
+
+
+ $arSelect = Array (
+ "ID",
+ "LID",
+ "IBLOCK_ID",
+ "IBLOCK_SECTION_ID",
+ "ACTIVE",
+ "ACTIVE_FROM",
+ "ACTIVE_TO",
+ "NAME",
+ "DETAIL_PICTURE",
+ "DETAIL_TEXT",
+ "DETAIL_PICTURE",
+ "LANG_DIR",
+ "DETAIL_PAGE_URL",
+ "PROPERTY_" . $this->articleProperties[$key]
+ );
+
+ $filter = Array (
+ "IBLOCK_ID" => $id,
+ "ACTIVE_DATE" => "Y",
+ "ACTIVE" => "Y",
+ "INCLUDE_SUBSECTIONS" => "Y"
+ );
+
+ $dbResProducts = CIBlockElement::GetList(array(), $filter, false, false, $arSelect);
+ while ($product = $dbResProducts->GetNextElement()) {
+
+ $product = $product->GetFields();
+
+ $categoriesString = "";
+
+
+ $existOffer = false;
+ if (!empty($iblockOffer['IBLOCK_ID'])) {
+ $arFilterOffer = Array (
+ 'IBLOCK_ID' => $iblockOffer['IBLOCK_ID'],
+ 'PROPERTY_'.$iblockOffer['SKU_PROPERTY_ID'] => $product["ID"]
+ );
+ $arSelectOffer = Array (
+ 'ID',
+ "NAME",
+ "DETAIL_TEXT",
+ "DETAIL_PAGE_URL",
+ "DETAIL_PICTURE",
+ "PROPERTY_" . $this->articleProperties[$key]
+ );
+
+ $rsOffers = CIBlockElement::GetList(array(), $arFilterOffer, false, false, $arSelectOffer);
+ while ($arOffer = $rsOffers->GetNext()) {
+
+ $dbResCategories = CIBlockElement::GetElementGroups($arOffer['ID'], true);
+ while ($arResCategory = $dbResCategories->Fetch()) {
+ $categoriesString .= "" . $arResCategory["ID"] . "\n";
+ }
+ $offer = CCatalogProduct::GetByID($arOffer['ID']);
+ $arOffer['QUANTITY'] = $offer["QUANTITY"];
+
+ $arOffer['PRODUCT_ID'] = $product["ID"];
+ $arOffer['DETAIL_PAGE_URL'] = $product["DETAIL_PAGE_URL"];
+ $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"];
+
+ $dbPrice = GetCatalogProductPrice($arOffer["ID"],1);
+ $arOffer['PRICE'] = $dbPrice['PRICE'];
+
+
+
+ $offers[] = $this->BuildOffer($arOffer, $categoriesString, $iblock);
+ $existOffer = true;
+ }
+ }
+ if (!$existOffer) {
+ $dbResCategories = CIBlockElement::GetElementGroups($product["ID"], true);
+ while ($arResCategory = $dbResCategories->Fetch()) {
+ $categoriesString .= "" . $arResCategory["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"];
+
+ $dbPrice = GetCatalogProductPrice($product["ID"],1);
+ $product['PRICE'] = $dbPrice['PRICE'];
+
+ $offers[] = $this->BuildOffer($product, $categoriesString, $iblock);
+ }
+ }
+ }
+ return $offers;
}
protected function BuildOffer($arOffer, $categoriesString, $iblock)
{
- $offer = "";
- $offer .= "PrepareValue($arOffer["ID"]) . "\" ".
- "productId=\"" . $this->PrepareValue($arOffer["PRODUCT_ID"]) . "\" ".
- "quantity=\"" . $this->PrepareValue(DoubleVal($arOffer['QUANTITY'])) . "\">\n";
- $offer .= "http://" . $this->PrepareValue($iblock['IBLOCK_DB']['SERVER_NAME']) . $this->PrepareValue($arOffer['DETAIL_PAGE_URL']) . "\n";
+ $offer = "";
+ $offer .= "PrepareValue($arOffer["ID"]) . "\" ".
+ "productId=\"" . $this->PrepareValue($arOffer["PRODUCT_ID"]) . "\" ".
+ "quantity=\"" . $this->PrepareValue(DoubleVal($arOffer['QUANTITY'])) . "\">\n";
+ $offer .= "http://" . $this->PrepareValue($iblock['IBLOCK_DB']['SERVER_NAME']) . $this->PrepareValue($arOffer['DETAIL_PAGE_URL']) . "\n";
- $offer .= "" . $this->PrepareValue($arOffer['PRICE']) . "\n";
- $offer .= $categoriesString;
-
- $detailPicture = intval($arOffer["DETAIL_PICTURE"]);
- $previewPicture = intval($arOffer["PREVIEW_PICTURE"]);
+ $offer .= "" . $this->PrepareValue($arOffer['PRICE']) . "\n";
+ $offer .= $categoriesString;
- if ($detailPicture > 0 || $previewPicture > 0)
- {
- $picture = $detailPicture;
- if ($picture <= 0) {
- $picture = $previewPicture;
- }
+ $detailPicture = intval($arOffer["DETAIL_PICTURE"]);
+ $previewPicture = intval($arOffer["PREVIEW_PICTURE"]);
- if ($arFile = CFile::GetFileArray($picture))
- {
- if(substr($arFile["SRC"], 0, 1) == "/")
- $strFile = "http://" . $this->PrepareValue($iblock['IBLOCK_DB']['SERVER_NAME']) . implode("/", array_map("rawurlencode", explode("/", $arFile["SRC"])));
- elseif(preg_match("/^(http|https):\\/\\/(.*?)\\/(.*)\$/", $arFile["SRC"], $match))
- $strFile = "http://" . $this->PrepareValue($match[2]) . '/' . implode("/", array_map("rawurlencode", explode("/", $this->PrepareValue($match[3]))));
- else
- $strFile = $arFile["SRC"];
- $offer .= "" . $this->PrepareValue($strFile) . "\n";
- }
- }
-
- $offer .= "" . $this->PrepareValue($arOffer["NAME"]) . "\n";
- $offer .= "" . (strip_tags( html_entity_decode(str_replace(" ", ' ', $this->PrepareValue($arOffer["DETAIL_TEXT"]))))) ."\n";
-
+ if ($detailPicture > 0 || $previewPicture > 0)
+ {
+ $picture = $detailPicture;
+ if ($picture <= 0) {
+ $picture = $previewPicture;
+ }
- $offer .= "" . $this->PrepareValue($arOffer["EXTERNAL_ID"]) . "\n";
- $offer .= "" . $this->PrepareValue($arOffer["PRODUCT_NAME"]) . "\n";
- $offer .= "" . $this->PrepareValue($arOffer["ARTICLE"]) . "\n";
-
- $offer.= "\n";
- return $offer;
+ if ($arFile = CFile::GetFileArray($picture))
+ {
+ if(substr($arFile["SRC"], 0, 1) == "/")
+ $strFile = "http://" . $this->PrepareValue($iblock['IBLOCK_DB']['SERVER_NAME']) . implode("/", array_map("rawurlencode", explode("/", $arFile["SRC"])));
+ elseif(preg_match("/^(http|https):\\/\\/(.*?)\\/(.*)\$/", $arFile["SRC"], $match))
+ $strFile = "http://" . $this->PrepareValue($match[2]) . '/' . implode("/", array_map("rawurlencode", explode("/", $this->PrepareValue($match[3]))));
+ else
+ $strFile = $arFile["SRC"];
+ $offer .= "" . $this->PrepareValue($strFile) . "\n";
+ }
+ }
+
+ $offer .= "" . $this->PrepareValue($arOffer["NAME"]) . "\n";
+
+ $offer .= "" . $this->PrepareValue($arOffer["EXTERNAL_ID"]) . "\n";
+ $offer .= "" . $this->PrepareValue($arOffer["PRODUCT_NAME"]) . "\n";
+ $offer .= "" . $this->PrepareValue($arOffer["ARTICLE"]) . "\n";
+
+ $offer.= "\n";
+ return $offer;
}