2013-08-06 19:13:49 +04:00
|
|
|
<?php
|
|
|
|
|
2013-09-22 20:03:35 +04:00
|
|
|
global $MESS;
|
|
|
|
IncludeModuleLangFile(__FILE__);
|
|
|
|
|
2013-08-06 19:13:49 +04:00
|
|
|
class ICMLLoader {
|
2013-09-22 20:03:35 +04:00
|
|
|
|
2013-09-12 17:31:32 +04:00
|
|
|
public $iblocks;
|
|
|
|
public $filename;
|
2013-09-13 16:15:54 +04:00
|
|
|
public $propertiesSKU;
|
|
|
|
public $propertiesProduct;
|
2013-09-12 17:31:32 +04:00
|
|
|
public $application;
|
|
|
|
public $encoding = 'utf-8';
|
2013-09-22 20:03:35 +04:00
|
|
|
|
2013-09-12 17:31:32 +04:00
|
|
|
protected $fp;
|
2013-09-13 16:15:54 +04:00
|
|
|
protected $mainSection = 1000000;
|
2013-10-10 17:46:14 +04:00
|
|
|
protected $pageSize = 500;
|
|
|
|
|
|
|
|
protected $isLogged = false;
|
|
|
|
protected $logFile = '/bitrix/catalog_export/i_crm_load_log.txt';
|
|
|
|
protected $fpLog;
|
|
|
|
|
2013-09-12 17:31:32 +04:00
|
|
|
public function Load()
|
|
|
|
{
|
2013-08-19 15:14:36 +04:00
|
|
|
global $USER;
|
|
|
|
if(!isset($USER))
|
|
|
|
$USER = new CUser;
|
2013-10-10 17:46:14 +04:00
|
|
|
|
|
|
|
$this->isLogged = true;
|
|
|
|
|
2013-08-20 12:53:32 +04:00
|
|
|
|
2013-09-13 16:15:54 +04:00
|
|
|
$this->PrepareSettings();
|
2013-10-10 17:46:14 +04:00
|
|
|
|
|
|
|
$this->fp = $this->PrepareFile($this->filename);
|
2013-09-13 16:15:54 +04:00
|
|
|
|
2013-10-10 17:46:14 +04:00
|
|
|
if ($this->isLogged) {
|
|
|
|
$this->fpLog = $this->PrepareFile($this->logFile);
|
|
|
|
$this->WriteLog("Start Loading");
|
|
|
|
}
|
2013-08-19 15:14:36 +04:00
|
|
|
|
|
|
|
$this->PreWriteCatalog();
|
2013-09-22 20:03:35 +04:00
|
|
|
|
2013-09-12 17:31:32 +04:00
|
|
|
$categories = $this->GetCategories();
|
2013-09-22 20:03:35 +04:00
|
|
|
|
2013-08-19 15:14:36 +04:00
|
|
|
$this->WriteCategories($categories);
|
2013-09-22 20:03:35 +04:00
|
|
|
|
2013-09-12 17:31:32 +04:00
|
|
|
$this->PreWriteOffers();
|
|
|
|
$this->BuildOffers($categories);
|
|
|
|
$this->PostWriteOffers();
|
2013-08-19 15:14:36 +04:00
|
|
|
|
|
|
|
$this->PostWriteCatalog();
|
|
|
|
|
2013-10-10 17:46:14 +04:00
|
|
|
if ($this->isLogged) {
|
|
|
|
$this->WriteLog("Loading was ended successfully (peek memory usage: " . memory_get_peak_usage() . ")");
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->CloseFile($this->fp);
|
|
|
|
$this->CloseFile($this->fpLog);
|
|
|
|
|
|
|
|
|
2013-08-20 12:53:32 +04:00
|
|
|
return true;
|
2013-09-22 20:03:35 +04:00
|
|
|
|
2013-09-12 17:31:32 +04:00
|
|
|
}
|
2013-10-10 17:46:14 +04:00
|
|
|
|
2013-09-13 16:15:54 +04:00
|
|
|
protected function PrepareSettings()
|
|
|
|
{
|
|
|
|
foreach ($this->propertiesSKU as $iblock => $arr) {
|
|
|
|
foreach ($arr as $id => $sku) {
|
|
|
|
$this->propertiesSKU[$iblock][$id] = strtoupper($sku);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
foreach ($this->propertiesProduct as $iblock => $arr) {
|
|
|
|
foreach ($arr as $id => $prod) {
|
|
|
|
$this->propertiesProduct[$iblock][$id] = strtoupper($prod);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-10-10 17:46:14 +04:00
|
|
|
|
2013-09-12 17:31:32 +04:00
|
|
|
protected function PrepareValue($text)
|
2013-08-06 19:13:49 +04:00
|
|
|
{
|
2013-08-20 13:06:31 +04:00
|
|
|
$newText = $this->application->ConvertCharset($text, LANG_CHARSET, $this->encoding);
|
|
|
|
$newText = strip_tags($newText);
|
|
|
|
$newText = str_replace("&", "&", $newText);
|
|
|
|
return $newText;
|
2013-08-06 19:13:49 +04:00
|
|
|
}
|
2013-09-22 20:03:35 +04:00
|
|
|
|
2013-10-10 17:46:14 +04:00
|
|
|
protected function PrepareFile($filename)
|
2013-09-12 17:31:32 +04:00
|
|
|
{
|
2013-10-10 17:46:14 +04:00
|
|
|
$fullFilename = $_SERVER["DOCUMENT_ROOT"] . $filename;
|
2013-08-19 15:14:36 +04:00
|
|
|
CheckDirPath($fullFilename);
|
|
|
|
|
2013-10-10 17:46:14 +04:00
|
|
|
if ($fp = @fopen($fullFilename, "w"))
|
|
|
|
return $fp;
|
2013-08-19 15:14:36 +04:00
|
|
|
else
|
2013-10-10 17:46:14 +04:00
|
|
|
return false;
|
2013-09-12 17:31:32 +04:00
|
|
|
}
|
2013-09-22 20:03:35 +04:00
|
|
|
|
2013-09-12 17:31:32 +04:00
|
|
|
protected function PreWriteCatalog()
|
|
|
|
{
|
2013-09-13 16:15:54 +04:00
|
|
|
@fwrite($this->fp, "<yml_catalog date=\"" . $this->PrepareValue(Date("Y-m-d H:i:s")) . "\">\n
|
|
|
|
<shop>\n
|
|
|
|
<name>" . $this->PrepareValue(COption::GetOptionString("main", "site_name", ""))."</name>\n
|
|
|
|
<company>" . $this->PrepareValue(COption::GetOptionString("main", "site_name", ""))."</company>\n"
|
|
|
|
);
|
2013-08-19 15:14:36 +04:00
|
|
|
|
2013-09-12 17:31:32 +04:00
|
|
|
}
|
2013-09-22 20:03:35 +04:00
|
|
|
|
2013-09-12 17:31:32 +04:00
|
|
|
protected function WriteCategories($categories)
|
|
|
|
{
|
|
|
|
$stringCategories = "";
|
2013-08-19 15:14:36 +04:00
|
|
|
@fwrite($this->fp, "<categories>\n");
|
|
|
|
foreach ($categories as $category) {
|
2013-09-12 17:31:32 +04:00
|
|
|
$stringCategories .= $this->BuildCategory($category);
|
2013-08-19 15:14:36 +04:00
|
|
|
}
|
2013-09-12 17:31:32 +04:00
|
|
|
@fwrite($this->fp, $stringCategories);
|
2013-08-19 15:14:36 +04:00
|
|
|
@fwrite($this->fp, "</categories>\n");
|
2013-09-12 17:31:32 +04:00
|
|
|
}
|
|
|
|
protected function PreWriteOffers()
|
|
|
|
{
|
2013-08-19 15:14:36 +04:00
|
|
|
@fwrite($this->fp, "<offers>\n");
|
2013-09-12 17:31:32 +04:00
|
|
|
}
|
2013-09-22 20:03:35 +04:00
|
|
|
|
2013-09-12 17:31:32 +04:00
|
|
|
protected function PostWriteOffers()
|
|
|
|
{
|
2013-08-19 15:14:36 +04:00
|
|
|
@fwrite($this->fp, "</offers>\n");
|
2013-09-12 17:31:32 +04:00
|
|
|
}
|
2013-09-22 20:03:35 +04:00
|
|
|
|
2013-09-12 17:31:32 +04:00
|
|
|
protected function WriteOffers($offers)
|
|
|
|
{
|
|
|
|
@fwrite($this->fp, $offers);
|
|
|
|
}
|
2013-10-10 17:46:14 +04:00
|
|
|
|
|
|
|
protected function WriteLog($text)
|
|
|
|
{
|
|
|
|
if ($this->isLogged)
|
|
|
|
@fwrite($this->fpLog, Date("Y:m:d H:i:s") . ": " . $text . "\n");
|
|
|
|
}
|
2013-09-22 20:03:35 +04:00
|
|
|
|
2013-09-12 17:31:32 +04:00
|
|
|
protected function PostWriteCatalog()
|
|
|
|
{
|
2013-09-13 16:15:54 +04:00
|
|
|
@fwrite($this->fp, "</shop>\n
|
|
|
|
</yml_catalog>\n");
|
2013-09-12 17:31:32 +04:00
|
|
|
}
|
2013-09-22 20:03:35 +04:00
|
|
|
|
2013-10-10 17:46:14 +04:00
|
|
|
protected function CloseFile($fp)
|
2013-09-12 17:31:32 +04:00
|
|
|
{
|
2013-10-10 17:46:14 +04:00
|
|
|
@fclose($fp);
|
2013-09-12 17:31:32 +04:00
|
|
|
}
|
2013-09-22 20:03:35 +04:00
|
|
|
|
|
|
|
|
2013-09-12 17:31:32 +04:00
|
|
|
protected function GetCategories()
|
|
|
|
{
|
2013-08-19 15:14:36 +04:00
|
|
|
$categories = array();
|
2013-09-22 20:03:35 +04:00
|
|
|
foreach ($this->iblocks as $id)
|
2013-08-19 15:14:36 +04:00
|
|
|
{
|
|
|
|
$filter = Array(
|
|
|
|
"IBLOCK_ID" => $id,
|
2013-10-10 17:46:14 +04:00
|
|
|
|
2013-08-19 15:14:36 +04:00
|
|
|
);
|
|
|
|
|
|
|
|
$dbRes = CIBlockSection::GetList(array("left_margin" => "asc"), $filter);
|
2013-09-12 17:31:32 +04:00
|
|
|
$hasCategories = false;
|
2013-08-19 15:14:36 +04:00
|
|
|
while ($arRes = $dbRes->Fetch())
|
|
|
|
{
|
2013-09-12 17:31:32 +04:00
|
|
|
$categories[$arRes['ID']] = $arRes;
|
|
|
|
$hasCategories = true;
|
2013-08-19 15:14:36 +04:00
|
|
|
}
|
2013-09-12 17:31:32 +04:00
|
|
|
if (!$hasCategories)
|
2013-08-20 12:53:32 +04:00
|
|
|
{
|
2013-09-12 17:31:32 +04:00
|
|
|
$iblock = CIBlock::GetByID($id)->Fetch();
|
2013-09-22 20:03:35 +04:00
|
|
|
|
2013-08-20 12:53:32 +04:00
|
|
|
$arRes = Array();
|
|
|
|
$arRes['ID'] = $this->mainSection + $id;
|
|
|
|
$arRes['IBLOCK_SECTION_ID'] = 0;
|
2013-09-22 20:03:35 +04:00
|
|
|
$arRes['NAME'] = sprintf(GetMessage('ROOT_CATEGORY_FOR_CATALOG'), $iblock['NAME']);
|
2013-09-12 17:31:32 +04:00
|
|
|
$categories[$arRes['ID']] = $arRes;
|
2013-08-20 12:53:32 +04:00
|
|
|
}
|
2013-08-19 15:14:36 +04:00
|
|
|
}
|
|
|
|
return $categories;
|
2013-08-06 19:13:49 +04:00
|
|
|
|
2013-09-12 17:31:32 +04:00
|
|
|
}
|
2013-09-22 20:03:35 +04:00
|
|
|
|
2013-09-12 17:31:32 +04:00
|
|
|
protected function BuildCategory($arCategory)
|
|
|
|
{
|
2013-08-19 15:14:36 +04:00
|
|
|
return "
|
|
|
|
<category id=\"" . $this->PrepareValue($arCategory["ID"]) . "\""
|
|
|
|
. ( intval($arCategory["IBLOCK_SECTION_ID"] ) > 0 ?
|
|
|
|
" parentId=\"" . $this->PrepareValue($arCategory["IBLOCK_SECTION_ID"]) . "\""
|
|
|
|
:"")
|
|
|
|
. ">"
|
|
|
|
. $this->PrepareValue($arCategory["NAME"])
|
2013-09-12 17:31:32 +04:00
|
|
|
. "</category>\n";
|
2013-09-22 20:03:35 +04:00
|
|
|
|
2013-09-12 17:31:32 +04:00
|
|
|
}
|
2013-09-22 20:03:35 +04:00
|
|
|
|
2013-09-12 17:31:32 +04:00
|
|
|
protected function BuildOffers(&$allCategories)
|
|
|
|
{
|
2013-09-22 20:03:35 +04:00
|
|
|
foreach ($this->iblocks as $key => $id)
|
2013-08-19 15:14:36 +04:00
|
|
|
{
|
2013-10-10 17:46:14 +04:00
|
|
|
// Get Info by infoblocks
|
2013-08-19 15:14:36 +04:00
|
|
|
$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",
|
2013-10-10 17:46:14 +04:00
|
|
|
"DETAIL_PAGE_URL",
|
|
|
|
"CATALOG_GROUP_1"
|
2013-08-19 15:14:36 +04:00
|
|
|
);
|
2013-08-20 13:42:13 +04:00
|
|
|
|
2013-10-10 17:46:14 +04:00
|
|
|
|
|
|
|
// Set selected properties
|
2013-09-13 16:15:54 +04:00
|
|
|
foreach ($this->propertiesProduct[$id] as $key => $propProduct) {
|
2013-10-10 17:46:14 +04:00
|
|
|
if ($this->propertiesProduct[$id][$key] != "") {
|
2013-09-13 16:15:54 +04:00
|
|
|
$arSelect[] = "PROPERTY_" . $propProduct;
|
2013-10-10 17:46:14 +04:00
|
|
|
$arSelect[] = "PROPERTY_" . $propProduct . ".NAME";
|
|
|
|
}
|
2013-09-13 16:15:54 +04:00
|
|
|
}
|
2013-08-19 15:14:36 +04:00
|
|
|
|
2013-10-10 17:46:14 +04:00
|
|
|
|
|
|
|
// Set filter
|
2013-08-19 15:14:36 +04:00
|
|
|
$filter = Array (
|
|
|
|
"IBLOCK_ID" => $id,
|
|
|
|
"INCLUDE_SUBSECTIONS" => "Y"
|
|
|
|
);
|
2013-10-10 17:46:14 +04:00
|
|
|
|
|
|
|
$order = Array(
|
|
|
|
"id"
|
|
|
|
);
|
|
|
|
|
|
|
|
// Counter of pagenumber
|
|
|
|
$count = 1;
|
|
|
|
$isThisTheEnd = false;
|
|
|
|
|
|
|
|
// Cycle page to page
|
|
|
|
while (!$isThisTheEnd) {
|
|
|
|
|
|
|
|
$arNavStatParams = Array(
|
|
|
|
|
|
|
|
"iNumPage" => $count,
|
|
|
|
"nPageSize" => $this->pageSize,
|
|
|
|
);
|
|
|
|
|
|
|
|
// Get products on this page
|
|
|
|
$dbResProducts = CIBlockElement::GetList($order, $filter, false, $arNavStatParams, $arSelect);
|
|
|
|
|
|
|
|
// It's last page
|
|
|
|
if ($dbResProducts->NavPageCount == $count) {
|
|
|
|
$isThisTheEnd = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
$pictures = array();
|
|
|
|
$products = array();
|
2013-10-15 15:58:25 +04:00
|
|
|
while ($product = $dbResProducts->GetNext()) {
|
2013-10-10 17:46:14 +04:00
|
|
|
|
|
|
|
// Compile products to array
|
|
|
|
$products[$product['ID']] = $product;
|
|
|
|
|
|
|
|
$detailPicture = intval($product["DETAIL_PICTURE"]);
|
|
|
|
$previewPicture = intval($product["PREVIEW_PICTURE"]);
|
|
|
|
|
|
|
|
if ($detailPicture > 0 || $previewPicture > 0)
|
|
|
|
{
|
|
|
|
$picture = $detailPicture;
|
|
|
|
if ($picture <= 0) {
|
|
|
|
$picture = $previewPicture;
|
2013-09-13 16:15:54 +04:00
|
|
|
}
|
2013-10-10 17:46:14 +04:00
|
|
|
|
|
|
|
// Link pictureID and productID
|
|
|
|
$pictures[$picture] = $product['ID'];
|
2013-09-13 16:15:54 +04:00
|
|
|
}
|
2013-10-10 17:46:14 +04:00
|
|
|
}
|
|
|
|
unset($product, $dbResProducts);
|
|
|
|
unset($detailPicture, $previewPicture, $picture);
|
|
|
|
|
|
|
|
$pictureIDs = array_keys($pictures);
|
|
|
|
|
|
|
|
// Get pathes of pictures
|
|
|
|
$dbFiles = CFile::GetList(Array(), Array("@ID" => implode(',', $pictureIDs)));
|
2013-10-15 15:58:25 +04:00
|
|
|
while($file = $dbFiles->GetNext()) {
|
2013-10-10 17:46:14 +04:00
|
|
|
|
|
|
|
// Link picture to product
|
|
|
|
$products[$pictures[$file['ID']]]['PICTURE'] = "http://" .
|
|
|
|
$iblock['IBLOCK_DB']['SERVER_NAME'] .
|
|
|
|
'/upload/' . $file['SUBDIR'] .
|
|
|
|
'/' . $file['FILE_NAME'] ;
|
|
|
|
}
|
|
|
|
unset($pictures);
|
|
|
|
|
|
|
|
|
|
|
|
if (!empty($iblockOffer['IBLOCK_ID'])) {
|
|
|
|
|
2013-09-13 16:15:54 +04:00
|
|
|
|
2013-10-10 17:46:14 +04:00
|
|
|
$productIDs = array_keys($products);
|
|
|
|
|
|
|
|
$arSelectOffer = Array (
|
|
|
|
'ID',
|
2013-10-15 15:58:25 +04:00
|
|
|
'ACTIVE',
|
2013-10-10 17:46:14 +04:00
|
|
|
"NAME",
|
|
|
|
"DETAIL_TEXT",
|
|
|
|
"DETAIL_PAGE_URL",
|
|
|
|
"DETAIL_PICTURE",
|
|
|
|
'PROPERTY_' . $iblockOffer['SKU_PROPERTY_ID'],
|
|
|
|
"CATALOG_GROUP_1"
|
|
|
|
);
|
|
|
|
$arFilterOffer = Array (
|
|
|
|
'IBLOCK_ID' => $iblockOffer['IBLOCK_ID'],
|
|
|
|
'PROPERTY_' . $iblockOffer['SKU_PROPERTY_ID'] => $productIDs
|
2013-09-12 17:31:32 +04:00
|
|
|
);
|
2013-10-10 17:46:14 +04:00
|
|
|
|
|
|
|
// Set selected properties
|
|
|
|
foreach ($this->propertiesSKU[$id] as $key => $propSKU) {
|
|
|
|
if ($this->propertiesSKU[$id][$key] != "") {
|
|
|
|
$arSelectOffer[] = "PROPERTY_" . $propSKU;
|
|
|
|
$arSelectOffer[] = "PROPERTY_" . $propSKU . ".NAME";
|
|
|
|
}
|
2013-09-12 17:31:32 +04:00
|
|
|
}
|
2013-09-22 20:03:35 +04:00
|
|
|
|
2013-10-10 17:46:14 +04:00
|
|
|
// Get all offers for products on this page
|
|
|
|
$dbResOffers = CIBlockElement::GetList(array(), $arFilterOffer, false, false, $arSelectOffer);
|
|
|
|
|
2013-10-15 15:58:25 +04:00
|
|
|
while ($offer = $dbResOffers->GetNext()) {
|
2013-10-10 17:46:14 +04:00
|
|
|
|
|
|
|
// Link offers to products
|
|
|
|
$products[$offer['PROPERTY_' . $iblockOffer['SKU_PROPERTY_ID'] . '_VALUE']]['offers'][$offer['ID']] = $offer;
|
2013-09-12 17:31:32 +04:00
|
|
|
}
|
2013-10-10 17:46:14 +04:00
|
|
|
unset($offer, $dbResOffers);
|
|
|
|
}
|
|
|
|
|
2013-08-19 15:14:36 +04:00
|
|
|
|
2013-10-10 17:46:14 +04:00
|
|
|
|
|
|
|
$stringOffers = "";
|
|
|
|
foreach ($products as $product) {
|
2013-09-22 20:03:35 +04:00
|
|
|
|
2013-10-10 17:46:14 +04:00
|
|
|
// Get properties of product
|
|
|
|
$resPropertiesProduct = Array();
|
|
|
|
foreach ($this->propertiesProduct[$id] as $key => $propProduct) {
|
|
|
|
$resPropertiesProduct[$key] = "";
|
|
|
|
|
|
|
|
if ($propProduct != "") {
|
|
|
|
|
|
|
|
if (isset ($product["PROPERTY_" . $propProduct . "_NAME"]))
|
|
|
|
$resPropertiesProduct[$key] = $product["PROPERTY_" . $propProduct . "_NAME"];
|
|
|
|
else
|
|
|
|
$resPropertiesProduct[$key] = $product["PROPERTY_" . $propProduct . "_VALUE"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get categories of product
|
|
|
|
$categories = Array();
|
|
|
|
$dbResCategories = CIBlockElement::GetElementGroups($product['ID'], true);
|
|
|
|
while ($arResCategory = $dbResCategories->Fetch()) {
|
|
|
|
$categories[$arResCategory["ID"]] = array(
|
|
|
|
'ID' => $arResCategory["ID"],
|
|
|
|
'NAME' => $arResCategory["NAME"],
|
2013-09-12 17:31:32 +04:00
|
|
|
);
|
2013-09-13 16:15:54 +04:00
|
|
|
}
|
2013-10-10 17:46:14 +04:00
|
|
|
if (count($categories) == 0) {
|
2013-09-12 17:31:32 +04:00
|
|
|
|
2013-10-10 17:46:14 +04:00
|
|
|
$catId = $this->mainSection + $id;
|
|
|
|
$categories[$catId] = $allCategories[$catId];
|
|
|
|
}
|
2013-09-12 17:31:32 +04:00
|
|
|
|
|
|
|
|
2013-10-10 17:46:14 +04:00
|
|
|
$existOffer = false;
|
|
|
|
if (!empty($iblockOffer['IBLOCK_ID'])) {
|
2013-09-13 16:15:54 +04:00
|
|
|
|
2013-10-10 17:46:14 +04:00
|
|
|
foreach ($product['offers'] as $offer) {
|
|
|
|
|
|
|
|
$offer['PRODUCT_ID'] = $product["ID"];
|
|
|
|
$offer['DETAIL_PAGE_URL'] = $product["DETAIL_PAGE_URL"];
|
|
|
|
$offer['PICTURE'] = $product["PICTURE"];
|
|
|
|
$offer['PRODUCT_NAME'] = $product["NAME"];
|
2013-10-15 15:58:25 +04:00
|
|
|
$offer['PRODUCT_ACTIVE'] = $product["ACTIVE"];
|
2013-10-10 17:46:14 +04:00
|
|
|
$offer['PRICE'] = $offer['CATALOG_PRICE_1'];
|
|
|
|
$offer['QUANTITY'] = $offer["CATALOG_QUANTITY"];
|
|
|
|
|
|
|
|
// Get properties of product
|
|
|
|
|
|
|
|
foreach ($this->propertiesSKU[$id] as $key => $propSKU) {
|
|
|
|
|
|
|
|
if ($propSKU != "") {
|
|
|
|
|
|
|
|
if (isset ($product["PROPERTY_" . $propSKU . "_NAME"]))
|
|
|
|
$offer[$key] = $product["PROPERTY_" . $propSKU . "_NAME"];
|
|
|
|
else
|
|
|
|
$offer[$key] = $product["PROPERTY_" . $propSKU . "_VALUE"];
|
2013-09-13 16:15:54 +04:00
|
|
|
}
|
|
|
|
}
|
2013-10-10 17:46:14 +04:00
|
|
|
|
|
|
|
foreach ($resPropertiesProduct as $key => $propProduct) {
|
|
|
|
if ($this->propertiesProduct[$id][$key] != "" && !isset($offer[$key]))
|
|
|
|
$offer[$key] = $propProduct;
|
|
|
|
}
|
2013-08-19 15:14:36 +04:00
|
|
|
|
2013-10-10 17:46:14 +04:00
|
|
|
$stringOffers .= $this->BuildOffer($offer, $categories, $iblock, $allCategories);
|
|
|
|
$existOffer = true;
|
|
|
|
}
|
2013-09-12 17:31:32 +04:00
|
|
|
}
|
2013-10-10 17:46:14 +04:00
|
|
|
if (!$existOffer) {
|
2013-09-22 20:03:35 +04:00
|
|
|
|
2013-10-10 17:46:14 +04:00
|
|
|
$product['PRODUCT_ID'] = $product["ID"];
|
|
|
|
$product['PRODUCT_NAME'] = $product["NAME"];
|
2013-10-15 15:58:25 +04:00
|
|
|
$product['PRODUCT_ACTIVE'] = $product["ACTIVE"];
|
2013-10-10 17:46:14 +04:00
|
|
|
$product['PRICE'] = $product['CATALOG_PRICE_1'];
|
|
|
|
$product['QUANTITY'] = $product["CATALOG_QUANTITY"];
|
2013-08-19 15:14:36 +04:00
|
|
|
|
2013-10-10 17:46:14 +04:00
|
|
|
foreach ($resPropertiesProduct as $key => $propProduct) {
|
|
|
|
if ($this->propertiesProduct[$id][$key] != "")
|
|
|
|
$product[$key] = $propProduct;
|
|
|
|
}
|
2013-09-13 16:15:54 +04:00
|
|
|
|
2013-10-10 17:46:14 +04:00
|
|
|
$stringOffers .= $this->BuildOffer($product, $categories, $iblock, $allCategories);
|
2013-09-13 16:15:54 +04:00
|
|
|
}
|
2013-08-19 15:14:36 +04:00
|
|
|
|
2013-10-10 17:46:14 +04:00
|
|
|
}
|
|
|
|
unset($products);
|
|
|
|
|
|
|
|
if ($this->isLogged)
|
|
|
|
$this->WriteLog(($this->pageSize * $count) . " product(s) has been loaded from " . $id . " IB (memory usage: " . memory_get_usage() . ")");
|
|
|
|
$count++;
|
|
|
|
if ($stringOffers != "") {
|
|
|
|
$this->WriteOffers($stringOffers);
|
|
|
|
$stringOffers = "";
|
|
|
|
}
|
2013-09-12 17:31:32 +04:00
|
|
|
}
|
2013-08-19 15:14:36 +04:00
|
|
|
}
|
2013-09-12 17:31:32 +04:00
|
|
|
}
|
2013-09-22 20:03:35 +04:00
|
|
|
|
|
|
|
|
2013-10-10 17:46:14 +04:00
|
|
|
protected function BuildOffer($arOffer, $categories, $iblock, &$allCategories)
|
2013-09-12 17:31:32 +04:00
|
|
|
{
|
2013-08-19 15:14:36 +04:00
|
|
|
$offer = "";
|
|
|
|
$offer .= "<offer id=\"" .$this->PrepareValue($arOffer["ID"]) . "\" ".
|
|
|
|
"productId=\"" . $this->PrepareValue($arOffer["PRODUCT_ID"]) . "\" ".
|
|
|
|
"quantity=\"" . $this->PrepareValue(DoubleVal($arOffer['QUANTITY'])) . "\">\n";
|
2013-10-15 15:58:25 +04:00
|
|
|
|
|
|
|
if ($arOffer['PRODUCT_ACTIVE'] == "N")
|
|
|
|
$offer .= "<productActivity>" . $this->PrepareValue($arOffer['PRODUCT_ACTIVE']) . "</productActivity>\n";
|
|
|
|
|
2013-10-10 17:46:14 +04:00
|
|
|
$keys = array_keys($categories);
|
|
|
|
if (strpos($arOffer['DETAIL_PAGE_URL'], "#SECTION_PATH#") !== false) {
|
|
|
|
if (count($categories) != 0) {
|
2013-08-06 19:13:49 +04:00
|
|
|
|
2013-10-10 17:46:14 +04:00
|
|
|
$category = $allCategories[$keys[0]];
|
|
|
|
$path = $category['CODE'];
|
2013-08-19 15:14:36 +04:00
|
|
|
|
2013-10-10 17:46:14 +04:00
|
|
|
if(intval($category["IBLOCK_SECTION_ID"] ) != 0) {
|
|
|
|
while (true) {
|
|
|
|
$category = $allCategories[$category['IBLOCK_SECTION_ID']];
|
|
|
|
$path = $category['CODE'] . '/' . $path;
|
|
|
|
if(intval($category["IBLOCK_SECTION_ID"] ) == 0)
|
|
|
|
break;
|
|
|
|
}
|
2013-08-19 15:14:36 +04:00
|
|
|
}
|
|
|
|
|
2013-10-10 17:46:14 +04:00
|
|
|
}
|
|
|
|
$arOffer['DETAIL_PAGE_URL'] = str_replace("#SECTION_PATH#", $path, $arOffer['DETAIL_PAGE_URL']);
|
2013-08-19 15:14:36 +04:00
|
|
|
}
|
|
|
|
|
2013-10-10 17:46:14 +04:00
|
|
|
$offer .= "<picture>" . $this->PrepareValue($arOffer["PICTURE"]) . "</picture>\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";
|
|
|
|
foreach ($categories as $category)
|
|
|
|
$offer .= "<categoryId>" . $category['ID'] . "</categoryId>\n";
|
|
|
|
|
2013-08-19 15:14:36 +04:00
|
|
|
$offer .= "<name>" . $this->PrepareValue($arOffer["NAME"]) . "</name>\n";
|
|
|
|
|
|
|
|
$offer .= "<xmlId>" . $this->PrepareValue($arOffer["EXTERNAL_ID"]) . "</xmlId>\n";
|
|
|
|
$offer .= "<productName>" . $this->PrepareValue($arOffer["PRODUCT_NAME"]) . "</productName>\n";
|
|
|
|
|
2013-09-13 16:15:54 +04:00
|
|
|
foreach ($this->propertiesProduct[$iblock['IBLOCK_DB']['ID']] as $key => $propProduct) {
|
|
|
|
if ($propProduct != "" && $arOffer[$key] != null)
|
|
|
|
$offer .= "<" . $key . ">" . $this->PrepareValue($arOffer[$key]) . "</" . $key . ">\n";
|
|
|
|
}
|
2013-10-10 17:46:14 +04:00
|
|
|
|
2013-08-19 15:14:36 +04:00
|
|
|
$offer.= "</offer>\n";
|
|
|
|
return $offer;
|
2013-09-12 17:31:32 +04:00
|
|
|
}
|
2013-09-22 20:03:35 +04:00
|
|
|
|
2013-08-06 19:13:49 +04:00
|
|
|
}
|