1
0
mirror of synced 2024-11-25 23:06:08 +03:00

optimize catalog export + added limitation on offers fetching

This commit is contained in:
Ilyas Salikhov 2014-02-19 15:18:35 +04:00
parent 45662c78ed
commit 0f885e2e54

View File

@ -18,6 +18,7 @@ class ICMLLoader {
protected $fp;
protected $mainSection = 1000000;
protected $pageSize = 500;
protected $offerPageSize = 50;
protected $isLogged = false;
protected $logFile = '/bitrix/catalog_export/i_crm_load_log.txt';
@ -179,20 +180,15 @@ class ICMLLoader {
$categories = array();
foreach ($this->iblocks as $id)
{
$filter = Array(
"IBLOCK_ID" => $id,
);
$filter = array("IBLOCK_ID" => $id);
$dbRes = CIBlockSection::GetList(array("left_margin" => "asc"), $filter);
$hasCategories = false;
while ($arRes = $dbRes->Fetch())
{
$categories[$arRes['ID']] = $arRes;
$hasCategories = true;
while ($arRes = $dbRes->Fetch()) {
$categories[$arRes['ID']] = $arRes;
$hasCategories = true;
}
if (!$hasCategories)
{
if (!$hasCategories) {
$iblock = CIBlock::GetByID($id)->Fetch();
$arRes = Array();
@ -228,23 +224,21 @@ class ICMLLoader {
$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",
"CATALOG_GROUP_1"
);
"ID",
"LID",
"IBLOCK_ID",
"IBLOCK_SECTION_ID",
"ACTIVE",
"ACTIVE_FROM",
"ACTIVE_TO",
"NAME",
"DETAIL_PICTURE",
"DETAIL_TEXT",
"DETAIL_PICTURE",
"LANG_DIR",
"DETAIL_PAGE_URL",
"CATALOG_GROUP_1"
);
// Set selected properties
foreach ($this->propertiesProduct[$id] as $key => $propProduct) {
if ($this->propertiesProduct[$id][$key] != "") {
@ -253,38 +247,40 @@ class ICMLLoader {
}
}
$arSelectOffer = Array (
'ID',
'ACTIVE',
"NAME",
"DETAIL_TEXT",
"DETAIL_PAGE_URL",
"DETAIL_PICTURE",
'PROPERTY_' . $iblockOffer['SKU_PROPERTY_ID'],
"CATALOG_GROUP_1"
);
// Set selected properties
foreach ($this->propertiesSKU[$id] as $key => $propSKU) {
if ($this->propertiesSKU[$id][$key] != "") {
$arSelectOffer[] = "PROPERTY_" . $propSKU;
$arSelectOffer[] = "PROPERTY_" . $propSKU . ".NAME";
}
}
// Set filter
$filter = Array (
"IBLOCK_ID" => $id,
"INCLUDE_SUBSECTIONS" => "Y"
);
$order = Array(
"id"
$filter = array(
"IBLOCK_ID" => $id,
"INCLUDE_SUBSECTIONS" => "Y",
);
$order = array("id");
$arNavStatParams = Array(
"iNumPage" => 1,
"nPageSize" => $this->pageSize,
);
// Counter of pagenumber
$count = 1;
$isThisTheEnd = false;
// Cycle page to page
while (!$isThisTheEnd) {
$arNavStatParams = Array(
"iNumPage" => $count,
"nPageSize" => $this->pageSize,
);
do {
// 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();
while ($product = $dbResProducts->GetNext()) {
@ -307,7 +303,7 @@ class ICMLLoader {
$pictures[$picture] = $product['ID'];
}
}
unset($product, $dbResProducts);
unset($product);
unset($detailPicture, $previewPicture, $picture);
$pictureIDs = array_keys($pictures);
@ -324,48 +320,28 @@ class ICMLLoader {
}
unset($pictures);
if (!empty($iblockOffer['IBLOCK_ID'])) {
$productIDs = array_keys($products);
$arSelectOffer = Array (
'ID',
'ACTIVE',
"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
);
// Set selected properties
foreach ($this->propertiesSKU[$id] as $key => $propSKU) {
if ($this->propertiesSKU[$id][$key] != "") {
$arSelectOffer[] = "PROPERTY_" . $propSKU;
$arSelectOffer[] = "PROPERTY_" . $propSKU . ".NAME";
}
}
$arFilterOffer = array(
'IBLOCK_ID' => $iblockOffer['IBLOCK_ID'],
'PROPERTY_' . $iblockOffer['SKU_PROPERTY_ID'] => array_keys($products),
);
// Get all offers for products on this page
$dbResOffers = CIBlockElement::GetList(array(), $arFilterOffer, false, false, $arSelectOffer);
$dbResOffers = CIBlockElement::GetList(
array(),
$arFilterOffer,
false,
array('nTopCount' => $this->pageSize * $this->offerPageSize),
$arSelectOffer
);
while ($offer = $dbResOffers->GetNext()) {
// Link offers to products
$products[$offer['PROPERTY_' . $iblockOffer['SKU_PROPERTY_ID'] . '_VALUE']]['offers'][$offer['ID']] = $offer;
}
unset($offer, $dbResOffers);
}
$stringOffers = "";
foreach ($products as $product) {
@ -471,13 +447,15 @@ class ICMLLoader {
unset($products);
if ($this->isLogged)
$this->WriteLog(($this->pageSize * $count) . " product(s) has been loaded from " . $id . " IB (memory usage: " . memory_get_usage() . ")");
$count++;
$this->WriteLog(($this->pageSize * $arNavStatParams['iNumPage']) . " product(s) has been loaded from " . $id . " IB (memory usage: " . memory_get_usage() . ")");
if ($stringOffers != "") {
$this->WriteOffers($stringOffers);
$stringOffers = "";
}
$arNavStatParams['iNumPage'] = $dbResProducts->NavPageNomer + 1;
}
while ($dbResProducts->NavPageNomer < $dbResProducts->NavPageCount);
}
}
@ -529,7 +507,7 @@ class ICMLLoader {
if ($key === "manufacturer")
$offer .= "<vendor>" . $this->PrepareValue($arOffer[$key]) . "</vendor>\n";
else
$offer .= "<param name=\"" . $key . "\" " . (isset($arOffer[$key . "_UNIT"]) ? 'unit="' . $arOffer[$key . "_UNIT"] . '"' : "") . ">" . $this->PrepareValue($arOffer[$key]) . "</param>\n";
$offer .= '<param name="' . $key . '"' . (isset($arOffer[$key . "_UNIT"]) ? ' unit="' . $arOffer[$key . "_UNIT"] . '"' : "") . ">" . $this->PrepareValue($arOffer[$key]) . "</param>\n";
}
}
foreach ($this->propertiesSKU[$iblock['IBLOCK_DB']['ID']] as $key => $propProduct) {
@ -537,12 +515,11 @@ class ICMLLoader {
if ($key === "manufacturer")
$offer .= "<vendor>" . $this->PrepareValue($arOffer[$key]) . "</vendor>\n";
else
$offer .= "<param name=\"" . $key . "\" " . ( isset($arOffer[$key . "_UNIT"]) ? 'unit="' . $arOffer[$key . "_UNIT"] . '"' : "") . ">" . $this->PrepareValue($arOffer[$key]) . "</param>\n";
$offer .= '<param name="' . $key . '"' . (isset($arOffer[$key . "_UNIT"]) ? ' unit="' . $arOffer[$key . "_UNIT"] . '"' : "") . ">" . $this->PrepareValue($arOffer[$key]) . "</param>\n";
}
}
$offer.= "</offer>\n";
return $offer;
}
}