update icml
This commit is contained in:
parent
ebbc5d2763
commit
90ea4b3eab
@ -20,16 +20,17 @@ class ICMLLoader {
|
||||
if (count($this->iblocks) < count($this->articleProperties))
|
||||
return false;
|
||||
|
||||
$categories = $this->GetCategories();
|
||||
|
||||
$offers = $this->GetOffers();
|
||||
|
||||
$this->PrepareFile();
|
||||
|
||||
$this->PreWriteCatalog();
|
||||
|
||||
$categories = $this->GetCategories();
|
||||
|
||||
$this->WriteCategories($categories);
|
||||
$this->WriteOffers($offers);
|
||||
|
||||
$this->PreWriteOffers();
|
||||
$this->BuildOffers($categories);
|
||||
$this->PostWriteOffers();
|
||||
|
||||
$this->PostWriteCatalog();
|
||||
|
||||
@ -70,21 +71,29 @@ class ICMLLoader {
|
||||
|
||||
protected function WriteCategories($categories)
|
||||
{
|
||||
$stringCategories = "";
|
||||
@fwrite($this->fp, "<categories>\n");
|
||||
foreach ($categories as $category) {
|
||||
@fwrite($this->fp, $category . "\n");
|
||||
$stringCategories .= $this->BuildCategory($category);
|
||||
}
|
||||
@fwrite($this->fp, $stringCategories);
|
||||
@fwrite($this->fp, "</categories>\n");
|
||||
}
|
||||
protected function WriteOffers($offers)
|
||||
protected function PreWriteOffers()
|
||||
{
|
||||
@fwrite($this->fp, "<offers>\n");
|
||||
foreach ($offers as $offer) {
|
||||
@fwrite($this->fp, $offer . "\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");
|
||||
@ -109,19 +118,22 @@ class ICMLLoader {
|
||||
"GLOBAL_ACTIVE" => "Y"
|
||||
);
|
||||
|
||||
|
||||
$dbRes = CIBlockSection::GetList(array("left_margin" => "asc"), $filter);
|
||||
$hasCategories = false;
|
||||
while ($arRes = $dbRes->Fetch())
|
||||
{
|
||||
$categories[] = $this->BuildCategory($arRes);
|
||||
$categories[$arRes['ID']] = $arRes;
|
||||
$hasCategories = true;
|
||||
}
|
||||
if (count($categories) == 0)
|
||||
if (!$hasCategories)
|
||||
{
|
||||
$iblock = CIBlock::GetByID($id)->Fetch();
|
||||
|
||||
$arRes = Array();
|
||||
$arRes['ID'] = $this->mainSection + $id;
|
||||
$arRes['IBLOCK_SECTION_ID'] = 0;
|
||||
$arRes['NAME'] = "Основной раздел каталога";
|
||||
$categories[] = $this->BuildCategory($arRes);
|
||||
$arRes['NAME'] = "Основной раздел каталога " . $iblock['NAME'];
|
||||
$categories[$arRes['ID']] = $arRes;
|
||||
}
|
||||
}
|
||||
return $categories;
|
||||
@ -137,13 +149,12 @@ class ICMLLoader {
|
||||
:"")
|
||||
. ">"
|
||||
. $this->PrepareValue($arCategory["NAME"])
|
||||
. "</category>";
|
||||
. "</category>\n";
|
||||
|
||||
}
|
||||
|
||||
protected function GetOffers()
|
||||
protected function BuildOffers(&$allCategories)
|
||||
{
|
||||
$offers = Array();
|
||||
foreach ($this->iblocks as $key => $id)
|
||||
{
|
||||
|
||||
@ -177,20 +188,36 @@ class ICMLLoader {
|
||||
"ACTIVE" => "Y",
|
||||
"INCLUDE_SUBSECTIONS" => "Y"
|
||||
);
|
||||
|
||||
$count = 0;
|
||||
$dbResProducts = CIBlockElement::GetList(array(), $filter, false, false, $arSelect);
|
||||
$stringOffers = "";
|
||||
while ($product = $dbResProducts->GetNextElement()) {
|
||||
|
||||
$product = $product->GetFields();
|
||||
|
||||
$categoriesString = "";
|
||||
// Get categories in InfoBlock
|
||||
$categories = Array();
|
||||
$dbResCategories = CIBlockElement::GetElementGroups($product['ID'], true);
|
||||
while ($arResCategory = $dbResCategories->Fetch()) {
|
||||
$categories[$arResCategory["ID"]] = array(
|
||||
'ID' => $arResCategory["ID"],
|
||||
'NAME' => $arResCategory["NAME"],
|
||||
);
|
||||
}
|
||||
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"]
|
||||
'PROPERTY_' . $iblockOffer['SKU_PROPERTY_ID'] => $product["ID"]
|
||||
);
|
||||
$arSelectOffer = Array (
|
||||
'ID',
|
||||
@ -202,15 +229,10 @@ class ICMLLoader {
|
||||
if (isset($this->articleProperties[$id]))
|
||||
$arSelectOffer[] = "PROPERTY_" . $this->articleProperties[$id];
|
||||
|
||||
|
||||
$rsOffers = CIBlockElement::GetList(array(), $arFilterOffer, false, false, $arSelectOffer);
|
||||
while ($arOffer = $rsOffers->GetNext()) {
|
||||
|
||||
$dbResCategories = CIBlockElement::GetElementGroups($arOffer['ID'], true);
|
||||
while ($arResCategory = $dbResCategories->Fetch()) {
|
||||
$categoriesString .= "<categoryId>" . $arResCategory["ID"] . "</categoryId>\n";
|
||||
}
|
||||
if ($categoriesString == '')
|
||||
$categoriesString .= "<categoryId>" . ($this->mainSection + $id) . "</categoryId>\n";
|
||||
$offer = CCatalogProduct::GetByID($arOffer['ID']);
|
||||
$arOffer['QUANTITY'] = $offer["QUANTITY"];
|
||||
|
||||
@ -225,19 +247,11 @@ class ICMLLoader {
|
||||
$dbPrice = GetCatalogProductPrice($arOffer["ID"],1);
|
||||
$arOffer['PRICE'] = $dbPrice['PRICE'];
|
||||
|
||||
|
||||
|
||||
$offers[] = $this->BuildOffer($arOffer, $categoriesString, $iblock);
|
||||
$stringOffers .= $this->BuildOffer($arOffer, $categories, $iblock);
|
||||
$existOffer = true;
|
||||
}
|
||||
}
|
||||
if (!$existOffer) {
|
||||
$dbResCategories = CIBlockElement::GetElementGroups($product["ID"], true);
|
||||
while ($arResCategory = $dbResCategories->Fetch()) {
|
||||
$categoriesString .= "<categoryId>" . $arResCategory["ID"] . "</categoryId>\n";
|
||||
}
|
||||
if ($categoriesString == '')
|
||||
$categoriesString .= "<categoryId>" . ($this->mainSection + $id) . "</categoryId>\n";
|
||||
|
||||
$offer = CCatalogProduct::GetByID($product['ID']);
|
||||
$product['QUANTITY'] = $offer["QUANTITY"];
|
||||
@ -250,24 +264,38 @@ class ICMLLoader {
|
||||
$dbPrice = GetCatalogProductPrice($product["ID"],1);
|
||||
$product['PRICE'] = $dbPrice['PRICE'];
|
||||
|
||||
$offers[] = $this->BuildOffer($product, $categoriesString, $iblock);
|
||||
$stringOffers .= $this->BuildOffer($product, $categories, $iblock);
|
||||
}
|
||||
|
||||
$count++;
|
||||
if ($count == 1000) {
|
||||
$this->WriteOffers($stringOffers);
|
||||
$stringOffers = "";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ($stringOffers != "") {
|
||||
$this->WriteOffers($stringOffers);
|
||||
$stringOffers = "";
|
||||
}
|
||||
|
||||
}
|
||||
return $offers;
|
||||
}
|
||||
|
||||
|
||||
protected function BuildOffer($arOffer, $categoriesString, $iblock)
|
||||
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";
|
||||
$offer .= $categoriesString;
|
||||
foreach ($categories as $category)
|
||||
$offer .= "<categoryId>" . $category['ID'] . "</categoryId>\n";
|
||||
|
||||
$detailPicture = intval($arOffer["DETAIL_PICTURE"]);
|
||||
$previewPicture = intval($arOffer["PREVIEW_PICTURE"]);
|
||||
@ -302,6 +330,4 @@ class ICMLLoader {
|
||||
return $offer;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
19
intaro.intarocrm/export/export_run.php
Normal file
19
intaro.intarocrm/export/export_run.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
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();
|
Loading…
Reference in New Issue
Block a user