optimize catalog export + added limitation on offers fetching
This commit is contained in:
parent
45662c78ed
commit
0f885e2e54
@ -18,6 +18,7 @@ class ICMLLoader {
|
|||||||
protected $fp;
|
protected $fp;
|
||||||
protected $mainSection = 1000000;
|
protected $mainSection = 1000000;
|
||||||
protected $pageSize = 500;
|
protected $pageSize = 500;
|
||||||
|
protected $offerPageSize = 50;
|
||||||
|
|
||||||
protected $isLogged = false;
|
protected $isLogged = false;
|
||||||
protected $logFile = '/bitrix/catalog_export/i_crm_load_log.txt';
|
protected $logFile = '/bitrix/catalog_export/i_crm_load_log.txt';
|
||||||
@ -179,20 +180,15 @@ class ICMLLoader {
|
|||||||
$categories = array();
|
$categories = array();
|
||||||
foreach ($this->iblocks as $id)
|
foreach ($this->iblocks as $id)
|
||||||
{
|
{
|
||||||
$filter = Array(
|
$filter = array("IBLOCK_ID" => $id);
|
||||||
"IBLOCK_ID" => $id,
|
|
||||||
|
|
||||||
);
|
|
||||||
|
|
||||||
$dbRes = CIBlockSection::GetList(array("left_margin" => "asc"), $filter);
|
$dbRes = CIBlockSection::GetList(array("left_margin" => "asc"), $filter);
|
||||||
$hasCategories = false;
|
$hasCategories = false;
|
||||||
while ($arRes = $dbRes->Fetch())
|
while ($arRes = $dbRes->Fetch()) {
|
||||||
{
|
|
||||||
$categories[$arRes['ID']] = $arRes;
|
$categories[$arRes['ID']] = $arRes;
|
||||||
$hasCategories = true;
|
$hasCategories = true;
|
||||||
}
|
}
|
||||||
if (!$hasCategories)
|
if (!$hasCategories) {
|
||||||
{
|
|
||||||
$iblock = CIBlock::GetByID($id)->Fetch();
|
$iblock = CIBlock::GetByID($id)->Fetch();
|
||||||
|
|
||||||
$arRes = Array();
|
$arRes = Array();
|
||||||
@ -243,8 +239,6 @@ class ICMLLoader {
|
|||||||
"DETAIL_PAGE_URL",
|
"DETAIL_PAGE_URL",
|
||||||
"CATALOG_GROUP_1"
|
"CATALOG_GROUP_1"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
// Set selected properties
|
// Set selected properties
|
||||||
foreach ($this->propertiesProduct[$id] as $key => $propProduct) {
|
foreach ($this->propertiesProduct[$id] as $key => $propProduct) {
|
||||||
if ($this->propertiesProduct[$id][$key] != "") {
|
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
|
// Set filter
|
||||||
$filter = Array (
|
$filter = array(
|
||||||
"IBLOCK_ID" => $id,
|
"IBLOCK_ID" => $id,
|
||||||
"INCLUDE_SUBSECTIONS" => "Y"
|
"INCLUDE_SUBSECTIONS" => "Y",
|
||||||
);
|
);
|
||||||
|
$order = array("id");
|
||||||
$order = Array(
|
|
||||||
"id"
|
|
||||||
);
|
|
||||||
|
|
||||||
// Counter of pagenumber
|
|
||||||
$count = 1;
|
|
||||||
$isThisTheEnd = false;
|
|
||||||
|
|
||||||
// Cycle page to page
|
|
||||||
while (!$isThisTheEnd) {
|
|
||||||
|
|
||||||
$arNavStatParams = Array(
|
$arNavStatParams = Array(
|
||||||
|
"iNumPage" => 1,
|
||||||
"iNumPage" => $count,
|
|
||||||
"nPageSize" => $this->pageSize,
|
"nPageSize" => $this->pageSize,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Cycle page to page
|
||||||
|
do {
|
||||||
// Get products on this page
|
// Get products on this page
|
||||||
$dbResProducts = CIBlockElement::GetList($order, $filter, false, $arNavStatParams, $arSelect);
|
$dbResProducts = CIBlockElement::GetList($order, $filter, false, $arNavStatParams, $arSelect);
|
||||||
|
|
||||||
// It's last page
|
|
||||||
if ($dbResProducts->NavPageCount == $count) {
|
|
||||||
$isThisTheEnd = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
$pictures = array();
|
$pictures = array();
|
||||||
$products = array();
|
$products = array();
|
||||||
while ($product = $dbResProducts->GetNext()) {
|
while ($product = $dbResProducts->GetNext()) {
|
||||||
@ -307,7 +303,7 @@ class ICMLLoader {
|
|||||||
$pictures[$picture] = $product['ID'];
|
$pictures[$picture] = $product['ID'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
unset($product, $dbResProducts);
|
unset($product);
|
||||||
unset($detailPicture, $previewPicture, $picture);
|
unset($detailPicture, $previewPicture, $picture);
|
||||||
|
|
||||||
$pictureIDs = array_keys($pictures);
|
$pictureIDs = array_keys($pictures);
|
||||||
@ -324,48 +320,28 @@ class ICMLLoader {
|
|||||||
}
|
}
|
||||||
unset($pictures);
|
unset($pictures);
|
||||||
|
|
||||||
|
|
||||||
if (!empty($iblockOffer['IBLOCK_ID'])) {
|
if (!empty($iblockOffer['IBLOCK_ID'])) {
|
||||||
|
$arFilterOffer = array(
|
||||||
|
|
||||||
$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'],
|
'IBLOCK_ID' => $iblockOffer['IBLOCK_ID'],
|
||||||
'PROPERTY_' . $iblockOffer['SKU_PROPERTY_ID'] => $productIDs
|
'PROPERTY_' . $iblockOffer['SKU_PROPERTY_ID'] => array_keys($products),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Set selected properties
|
|
||||||
foreach ($this->propertiesSKU[$id] as $key => $propSKU) {
|
|
||||||
if ($this->propertiesSKU[$id][$key] != "") {
|
|
||||||
$arSelectOffer[] = "PROPERTY_" . $propSKU;
|
|
||||||
$arSelectOffer[] = "PROPERTY_" . $propSKU . ".NAME";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get all offers for products on this page
|
// 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()) {
|
while ($offer = $dbResOffers->GetNext()) {
|
||||||
|
|
||||||
// Link offers to products
|
// Link offers to products
|
||||||
$products[$offer['PROPERTY_' . $iblockOffer['SKU_PROPERTY_ID'] . '_VALUE']]['offers'][$offer['ID']] = $offer;
|
$products[$offer['PROPERTY_' . $iblockOffer['SKU_PROPERTY_ID'] . '_VALUE']]['offers'][$offer['ID']] = $offer;
|
||||||
}
|
}
|
||||||
unset($offer, $dbResOffers);
|
unset($offer, $dbResOffers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$stringOffers = "";
|
$stringOffers = "";
|
||||||
foreach ($products as $product) {
|
foreach ($products as $product) {
|
||||||
|
|
||||||
@ -471,13 +447,15 @@ class ICMLLoader {
|
|||||||
unset($products);
|
unset($products);
|
||||||
|
|
||||||
if ($this->isLogged)
|
if ($this->isLogged)
|
||||||
$this->WriteLog(($this->pageSize * $count) . " product(s) has been loaded from " . $id . " IB (memory usage: " . memory_get_usage() . ")");
|
$this->WriteLog(($this->pageSize * $arNavStatParams['iNumPage']) . " product(s) has been loaded from " . $id . " IB (memory usage: " . memory_get_usage() . ")");
|
||||||
$count++;
|
|
||||||
if ($stringOffers != "") {
|
if ($stringOffers != "") {
|
||||||
$this->WriteOffers($stringOffers);
|
$this->WriteOffers($stringOffers);
|
||||||
$stringOffers = "";
|
$stringOffers = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$arNavStatParams['iNumPage'] = $dbResProducts->NavPageNomer + 1;
|
||||||
}
|
}
|
||||||
|
while ($dbResProducts->NavPageNomer < $dbResProducts->NavPageCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -529,7 +507,7 @@ class ICMLLoader {
|
|||||||
if ($key === "manufacturer")
|
if ($key === "manufacturer")
|
||||||
$offer .= "<vendor>" . $this->PrepareValue($arOffer[$key]) . "</vendor>\n";
|
$offer .= "<vendor>" . $this->PrepareValue($arOffer[$key]) . "</vendor>\n";
|
||||||
else
|
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) {
|
foreach ($this->propertiesSKU[$iblock['IBLOCK_DB']['ID']] as $key => $propProduct) {
|
||||||
@ -537,12 +515,11 @@ class ICMLLoader {
|
|||||||
if ($key === "manufacturer")
|
if ($key === "manufacturer")
|
||||||
$offer .= "<vendor>" . $this->PrepareValue($arOffer[$key]) . "</vendor>\n";
|
$offer .= "<vendor>" . $this->PrepareValue($arOffer[$key]) . "</vendor>\n";
|
||||||
else
|
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";
|
$offer.= "</offer>\n";
|
||||||
return $offer;
|
return $offer;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user