catalog export fix
This commit is contained in:
parent
0e5c9b5b6c
commit
6c2552881b
@ -1,33 +1,36 @@
|
||||
<?php
|
||||
|
||||
global $MESS;
|
||||
IncludeModuleLangFile(__FILE__);
|
||||
|
||||
class ICMLLoader {
|
||||
|
||||
|
||||
public $iblocks;
|
||||
public $filename;
|
||||
public $articleProperties;
|
||||
public $application;
|
||||
public $encoding = 'utf-8';
|
||||
|
||||
|
||||
protected $fp;
|
||||
protected $mainSection = 1000000;
|
||||
|
||||
|
||||
public function Load()
|
||||
{
|
||||
global $USER;
|
||||
if(!isset($USER))
|
||||
$USER = new CUser;
|
||||
|
||||
|
||||
if (count($this->iblocks) < count($this->articleProperties))
|
||||
return false;
|
||||
|
||||
|
||||
$this->PrepareFile();
|
||||
|
||||
$this->PreWriteCatalog();
|
||||
|
||||
|
||||
$categories = $this->GetCategories();
|
||||
|
||||
|
||||
$this->WriteCategories($categories);
|
||||
|
||||
|
||||
$this->PreWriteOffers();
|
||||
$this->BuildOffers($categories);
|
||||
$this->PostWriteOffers();
|
||||
@ -36,9 +39,9 @@ class ICMLLoader {
|
||||
|
||||
$this->CloseFile();
|
||||
return true;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected function PrepareValue($text)
|
||||
{
|
||||
$newText = $this->application->ConvertCharset($text, LANG_CHARSET, $this->encoding);
|
||||
@ -46,7 +49,7 @@ class ICMLLoader {
|
||||
$newText = str_replace("&", "&", $newText);
|
||||
return $newText;
|
||||
}
|
||||
|
||||
|
||||
protected function PrepareFile()
|
||||
{
|
||||
$fullFilename = $_SERVER["DOCUMENT_ROOT"] . $this->filename;
|
||||
@ -57,7 +60,7 @@ class ICMLLoader {
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
protected function PreWriteCatalog()
|
||||
{
|
||||
@fwrite($this->fp, "<yml_catalog date=\"" . $this->PrepareValue(Date("Y-m-d H:i:s")) . "\">\n");
|
||||
@ -68,7 +71,7 @@ class ICMLLoader {
|
||||
@fwrite($this->fp, "<company>".$this->PrepareValue(COption::GetOptionString("main", "site_name", ""))."</company>\n");
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected function WriteCategories($categories)
|
||||
{
|
||||
$stringCategories = "";
|
||||
@ -83,33 +86,33 @@ class ICMLLoader {
|
||||
{
|
||||
@fwrite($this->fp, "<offers>\n");
|
||||
}
|
||||
|
||||
|
||||
protected function PostWriteOffers()
|
||||
{
|
||||
@fwrite($this->fp, "</offers>\n");
|
||||
}
|
||||
|
||||
|
||||
protected function WriteOffers($offers)
|
||||
{
|
||||
@fwrite($this->fp, $offers);
|
||||
}
|
||||
|
||||
|
||||
protected function PostWriteCatalog()
|
||||
{
|
||||
@fwrite($this->fp, "</shop>\n");
|
||||
@fwrite($this->fp, "</yml_catalog>\n");
|
||||
}
|
||||
|
||||
|
||||
protected function CloseFile()
|
||||
{
|
||||
@fclose($this->fp);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
protected function GetCategories()
|
||||
{
|
||||
$categories = array();
|
||||
foreach ($this->iblocks as $id)
|
||||
foreach ($this->iblocks as $id)
|
||||
{
|
||||
$filter = Array(
|
||||
"IBLOCK_ID" => $id,
|
||||
@ -128,18 +131,18 @@ class ICMLLoader {
|
||||
if (!$hasCategories)
|
||||
{
|
||||
$iblock = CIBlock::GetByID($id)->Fetch();
|
||||
|
||||
|
||||
$arRes = Array();
|
||||
$arRes['ID'] = $this->mainSection + $id;
|
||||
$arRes['IBLOCK_SECTION_ID'] = 0;
|
||||
$arRes['NAME'] = "Основной раздел каталога " . $iblock['NAME'];
|
||||
$arRes['NAME'] = sprintf(GetMessage('ROOT_CATEGORY_FOR_CATALOG'), $iblock['NAME']);
|
||||
$categories[$arRes['ID']] = $arRes;
|
||||
}
|
||||
}
|
||||
return $categories;
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected function BuildCategory($arCategory)
|
||||
{
|
||||
return "
|
||||
@ -150,12 +153,12 @@ class ICMLLoader {
|
||||
. ">"
|
||||
. $this->PrepareValue($arCategory["NAME"])
|
||||
. "</category>\n";
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected function BuildOffers(&$allCategories)
|
||||
{
|
||||
foreach ($this->iblocks as $key => $id)
|
||||
foreach ($this->iblocks as $key => $id)
|
||||
{
|
||||
|
||||
$iblock['IBLOCK_DB'] = CIBlock::GetByID($id)->Fetch();
|
||||
@ -177,10 +180,10 @@ class ICMLLoader {
|
||||
"LANG_DIR",
|
||||
"DETAIL_PAGE_URL"
|
||||
);
|
||||
|
||||
|
||||
if (isset($this->articleProperties[$id]))
|
||||
$arSelect[] = "PROPERTY_" . $this->articleProperties[$id];
|
||||
|
||||
|
||||
|
||||
$filter = Array (
|
||||
"IBLOCK_ID" => $id,
|
||||
@ -192,7 +195,7 @@ class ICMLLoader {
|
||||
$dbResProducts = CIBlockElement::GetList(array(), $filter, false, false, $arSelect);
|
||||
$stringOffers = "";
|
||||
while ($product = $dbResProducts->GetNextElement()) {
|
||||
|
||||
|
||||
$product = $product->GetFields();
|
||||
|
||||
// Get categories in InfoBlock
|
||||
@ -205,16 +208,16 @@ class ICMLLoader {
|
||||
);
|
||||
}
|
||||
if (count($categories) == 0) {
|
||||
|
||||
|
||||
$catId = $this->mainSection + $id;
|
||||
$categories[$catId] = $allCategories[$catId];
|
||||
}
|
||||
|
||||
|
||||
|
||||
$existOffer = false;
|
||||
if (!empty($iblockOffer['IBLOCK_ID'])) {
|
||||
|
||||
|
||||
|
||||
|
||||
$arFilterOffer = Array (
|
||||
'IBLOCK_ID' => $iblockOffer['IBLOCK_ID'],
|
||||
'PROPERTY_' . $iblockOffer['SKU_PROPERTY_ID'] => $product["ID"]
|
||||
@ -252,7 +255,7 @@ class ICMLLoader {
|
||||
}
|
||||
}
|
||||
if (!$existOffer) {
|
||||
|
||||
|
||||
$offer = CCatalogProduct::GetByID($product['ID']);
|
||||
$product['QUANTITY'] = $offer["QUANTITY"];
|
||||
|
||||
@ -266,15 +269,15 @@ class ICMLLoader {
|
||||
|
||||
$stringOffers .= $this->BuildOffer($product, $categories, $iblock);
|
||||
}
|
||||
|
||||
|
||||
$count++;
|
||||
if ($count == 1000) {
|
||||
$this->WriteOffers($stringOffers);
|
||||
$stringOffers = "";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
if ($stringOffers != "") {
|
||||
$this->WriteOffers($stringOffers);
|
||||
$stringOffers = "";
|
||||
@ -282,15 +285,15 @@ class ICMLLoader {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
protected function BuildOffer($arOffer, $categories, $iblock)
|
||||
{
|
||||
$offer = "";
|
||||
$offer .= "<offer id=\"" .$this->PrepareValue($arOffer["ID"]) . "\" ".
|
||||
"productId=\"" . $this->PrepareValue($arOffer["PRODUCT_ID"]) . "\" ".
|
||||
"quantity=\"" . $this->PrepareValue(DoubleVal($arOffer['QUANTITY'])) . "\">\n";
|
||||
|
||||
|
||||
$offer .= "<url>http://" . $this->PrepareValue($iblock['IBLOCK_DB']['SERVER_NAME']) . $this->PrepareValue($arOffer['DETAIL_PAGE_URL']) . "</url>\n";
|
||||
|
||||
$offer .= "<price>" . $this->PrepareValue($arOffer['PRICE']) . "</price>\n";
|
||||
@ -329,5 +332,5 @@ class ICMLLoader {
|
||||
$offer.= "</offer>\n";
|
||||
return $offer;
|
||||
}
|
||||
|
||||
|
||||
}
|
2
intaro.intarocrm/lang/ru/classes/general/ICMLLoader.php
Normal file
2
intaro.intarocrm/lang/ru/classes/general/ICMLLoader.php
Normal file
@ -0,0 +1,2 @@
|
||||
<?php
|
||||
$MESS["ROOT_CATEGORY_FOR_CATALOG"] = "Корневой раздел для каталога \"%s\"";
|
Loading…
Reference in New Issue
Block a user