303 private $offersMap =
array();
304 private $offersIds =
array();
305 private $prices =
array();
306 private $calculatePrices =
array();
307 private $existPriceIds =
array();
308 private $existIdsByType =
array();
309 private $measureRatios =
array();
310 private $currencyReference =
array();
311 private $measureIds = [
327 $sessID = self::SESSION_PREFIX.time();
329 $this->preloadTooLong =
false;
337 return $this->config[
'CHECK_SETS'];
342 return $this->config[
'SEPARATE_SKU_MODE'];
347 if (!isset($this->params[
'IBLOCK_ID']))
349 $this->params[
'IBLOCK_ID'] = (int)$this->params[
'IBLOCK_ID'];
350 if ($this->params[
'IBLOCK_ID'] <= 0)
352 $this->iblockData = CCatalogSku::GetInfoByIBlock($this->params[
'IBLOCK_ID']);
353 if (empty($this->iblockData))
356 $this->currentList =
array();
357 $this->currentIdsList =
array();
359 while ($product = $productIterator->fetch())
361 $product[
'PRODUCT_ID'] = (int)$product[
'PRODUCT_ID'];
362 $product[
'PRODUCT_EXISTS'] = $product[
'PRODUCT_ID'] > 0;
363 $this->currentList[$product[
'ID']] = $product;
364 $this->currentIdsList[] = $product[
'ID'];
366 unset($product, $productIterator);
368 if (!empty($this->currentList))
370 switch ($this->iblockData[
'CATALOG_TYPE'])
372 case CCatalogSku::TYPE_CATALOG:
373 $this->loadProductPrices();
375 case CCatalogSku::TYPE_OFFERS:
376 $this->loadOffersData();
377 $this->loadProductPrices();
379 case CCatalogSku::TYPE_FULL:
380 case CCatalogSku::TYPE_PRODUCT:
381 $this->loadSkuData();
382 $this->loadProductPrices();
383 $this->loadSkuPrices();
386 $this->loadProductSets();
387 $this->loadMeasureRatios();
389 $this->updateProductData();
393 $this->currentList =
array();
394 $this->currentIdsList =
array();
399 if (empty($this->iblockData))
400 return parent::getMessage();
404 switch ($this->iblockData[
'CATALOG_TYPE'])
406 case CCatalogSku::TYPE_CATALOG:
408 'BX_STEP_OPERATION_CATALOG_TITLE',
410 '#ID#' => $this->iblockData[
'IBLOCK_ID'],
411 '#NAME#' =>
htmlspecialcharsbx(CIBlock::GetArrayByID($this->iblockData[
'IBLOCK_ID'],
'NAME'))
415 case CCatalogSku::TYPE_OFFERS:
417 'BX_STEP_OPERATION_OFFERS_TITLE',
419 '#ID#' => $this->iblockData[
'PRODUCT_IBLOCK_ID'],
420 '#NAME#' =>
htmlspecialcharsbx(CIBlock::GetArrayByID($this->iblockData[
'PRODUCT_IBLOCK_ID'],
'NAME'))
424 case CCatalogSku::TYPE_PRODUCT:
425 case CCatalogSku::TYPE_FULL:
427 'BX_STEP_OPERATION_CATALOG_TITLE',
429 '#ID#' => $this->iblockData[
'PRODUCT_IBLOCK_ID'],
430 '#NAME#' =>
htmlspecialcharsbx(CIBlock::GetArrayByID($this->iblockData[
'PRODUCT_IBLOCK_ID'],
'NAME'))
436 $messageParams =
array(
438 'PROGRESS_TOTAL' => $this->allCounter,
439 'PROGRESS_VALUE' => $this->allOperationCounter,
440 'TYPE' =>
'PROGRESS',
441 'DETAILS' => str_replace(
array(
'#ALL#',
'#COUNT#'),
array($this->allCounter, $this->allOperationCounter), $this->progressTemplate),
461 case CCatalogSku::TYPE_CATALOG:
462 $iblockName = CIBlock::GetArrayByID(
$iblockData[
'IBLOCK_ID'],
'NAME');
465 'NAME' => $iblockName,
467 'BX_STEP_OPERATION_CATALOG_TITLE',
470 '#NAME#' => $iblockName
473 'COUNT' => static::getIblockCounter(
$iblockData[
'IBLOCK_ID'])
477 case CCatalogSku::TYPE_OFFERS:
480 'NAME' => CIBlock::GetArrayByID(
$iblockData[
'IBLOCK_ID'],
'NAME'),
482 'BX_STEP_OPERATION_OFFERS_TITLE',
485 '#NAME#' => CIBlock::GetArrayByID(
$iblockData[
'PRODUCT_IBLOCK_ID'],
'NAME')
488 'COUNT' => static::getIblockCounter(
$iblockData[
'IBLOCK_ID'])
491 case CCatalogSku::TYPE_PRODUCT:
492 case CCatalogSku::TYPE_FULL:
493 $iblockName = CIBlock::GetArrayByID(
$iblockData[
'PRODUCT_IBLOCK_ID'],
'NAME');
496 'NAME' => CIBlock::GetArrayByID(
$iblockData[
'IBLOCK_ID'],
'NAME'),
498 'BX_STEP_OPERATION_OFFERS_TITLE',
501 '#NAME#' => $iblockName
504 'COUNT' => static::getIblockCounter(
$iblockData[
'IBLOCK_ID'])
508 'NAME' => $iblockName,
510 'BX_STEP_OPERATION_CATALOG_TITLE',
513 '#NAME#' => $iblockName
516 'COUNT' => static::getIblockCounter(
$iblockData[
'PRODUCT_IBLOCK_ID'])
528 $this->preloadTooLong = ($this->maxExecutionTime > 0 && (time() - $this->startOperationTime > ($this->maxExecutionTime/2)));
534 if (!$this->finishOperation)
536 if ($this->preloadTooLong)
538 $this->maxOperationCounter = (int)(($this->maxOperationCounter*2)/3);
542 if ($this->maxExecutionTime > 2*$period)
543 $this->maxOperationCounter = $this->maxOperationCounter*2;
544 elseif ($period >= $this->maxExecutionTime)
545 $this->maxOperationCounter = (int)(($this->maxOperationCounter*2)/3);
547 if ($this->maxOperationCounter < 10)
548 $this->maxOperationCounter = 10;
549 elseif($this->maxOperationCounter > 500)
550 $this->maxOperationCounter = 500;
556 $this->config =
array(
557 'SEPARATE_SKU_MODE' => (
string)
Main\
Config\
Option::get(
'catalog',
'show_catalog_tab_with_offers') ==
'Y',
558 'CHECK_AVAILABLE' =>
true,
559 'CHECK_SKU_PRICES' =>
true,
560 'CHECK_PRICES' =>
false,
561 'CHECK_SETS' =>
Catalog\
Config\Feature::isProductSetsEnabled(),
562 'CHECK_MEASURE_RATIO' =>
false,
563 'CHECK_MEASURE' =>
false,
564 'UPDATE_ONLY' =>
false
570 $this->useSets = $this->config[
'CHECK_SETS'];
571 $this->separateSkuMode = $this->config[
'SEPARATE_SKU_MODE'];
572 $this->extendedMode =
false;
577 $this->initCurrencyReference();
578 $this->initMeasures();
581 private function initCurrencyReference()
583 $this->currencyReference = [];
584 if (!$this->config[
'CHECK_PRICES'])
586 $iterator = Currency\CurrencyTable::getList([
587 'select' => [
'CURRENCY',
'CURRENT_BASE_RATE']
590 $this->currencyReference[$row[
'CURRENCY']] = (float)$row[
'CURRENT_BASE_RATE'];
594 private function initMeasures()
597 if (!empty($measure))
599 if ($measure[
'ID'] > 0)
600 $this->measureIds[
'DEFAULT'] = $measure[
'ID'];
604 array(
'=CODE' => CCatalogMeasure::DEFAULT_MEASURE_CODE),
611 if (!empty($measure))
613 $this->measureIds[
'BASE'] = $measure[
'ID'];
644 $select[
'PRODUCT_ID'] =
'PRODUCT.ID';
645 $select[
'QUANTITY'] =
'PRODUCT.QUANTITY';
646 $select[
'QUANTITY_TRACE'] =
'PRODUCT.QUANTITY_TRACE';
647 $select[
'CAN_BUY_ZERO'] =
'PRODUCT.CAN_BUY_ZERO';
648 $select[
'TYPE'] =
'PRODUCT.TYPE';
649 $select[
'MEASURE'] =
'PRODUCT.MEASURE';
651 if ($this->lastID > 0)
653 $filter[
'=IBLOCK_ID'] = $this->params[
'IBLOCK_ID'];
654 $filter[
'=WF_PARENT_ELEMENT_ID'] =
null;
655 if ($this->config[
'UPDATE_ONLY'])
656 $filter[
'!==PRODUCT.ID'] =
null;
661 'order' =>
array(
'ID' =>
'ASC'),
665 'Bitrix\Catalog\Product',
666 array(
'=this.ID' =>
'ref.ID'),
667 array(
'join_type' =>
'LEFT')
671 if ($this->maxOperationCounter > 0)
684 '=WF_PARENT_ELEMENT_ID' =>
null
688 private function loadSkuData()
690 if (empty($this->currentList))
692 $offers = \CCatalogSku::getOffersList(
693 $this->currentIdsList,
694 $this->params[
'IBLOCK_ID'],
696 array(
'ID',
'ACTIVE',
'AVAILABLE')
698 foreach ($this->currentIdsList as $id)
701 $this->currentList[$id][
'SET_EXISTS'] =
false;
702 $this->currentList[$id][
'BUNDLE_EXISTS'] =
false;
703 if (empty($offers[$id]))
707 $allOffers =
array();
708 $availableOffers =
array();
709 foreach ($offers[$id] as $offerId => $row)
711 $allOffers[] = $offerId;
712 if ($row[
'ACTIVE'] !=
'Y' || $row[
'AVAILABLE'] !=
'Y')
715 $availableOffers[] = $offerId;
718 $this->calculatePrices[$id] = [];
719 if ($this->config[
'CHECK_SKU_PRICES'] && !$this->config[
'SEPARATE_SKU_MODE'])
721 if ($this->currentList[$id][
'SKU_STATE'] == Catalog\Product\Sku::OFFERS_AVAILABLE)
723 foreach ($availableOffers as $offerId)
725 $this->offersMap[$offerId] = $id;
726 $this->offersIds[] = $offerId;
731 foreach ($allOffers as $offerId)
733 $this->offersMap[$offerId] = $id;
734 $this->offersIds[] = $offerId;
739 unset($offerId, $availableOffers, $allOffers, $id);
742 private function loadProductPrices()
744 if (empty($this->currentList))
748 $this->existPriceIds = [];
749 $this->existIdsByType = [];
751 if (!$this->config[
'CHECK_PRICES'] && !$this->config[
'CHECK_SKU_PRICES'])
754 foreach (array_chunk($this->currentIdsList, 500) as $pageIds)
756 $iterator = Catalog\PriceTable::getList([
757 'select' => [
'ID',
'PRODUCT_ID',
'CATALOG_GROUP_ID',
'PRICE',
'CURRENCY',
'PRICE_SCALE'],
758 'filter' => [
'@PRODUCT_ID' => $pageIds],
759 'order' => [
'PRODUCT_ID' =>
'ASC',
'CATALOG_GROUP_ID' =>
'ASC']
763 $id = (int)$row[
'ID'];
764 $row[
'PRICE'] = (float)$row[
'PRICE'];
765 $row[
'PRICE_SCALE'] = (float)$row[
'PRICE_SCALE'];
767 $priceTypeId = (int)$row[
'CATALOG_GROUP_ID'];
769 if (!isset($this->prices[$productId]))
773 if (!isset($this->existPriceIds[$productId]))
777 if (!isset($this->existIdsByType[$productId]))
779 if (!isset($this->existIdsByType[$productId][$priceTypeId]))
780 $this->existIdsByType[
$productId][$priceTypeId] = [];
781 $this->existIdsByType[
$productId][$priceTypeId][] = $id;
783 unset($priceTypeId, $productId, $id, $row,
$iterator);
788 private function loadSkuPrices()
790 if (empty($this->currentList))
796 if (!$this->config[
'CHECK_SKU_PRICES'] || $this->config[
'SEPARATE_SKU_MODE'])
824 if (empty($this->offersIds))
827 sort($this->offersIds);
828 foreach (array_chunk($this->offersIds, 500) as $pageOfferIds)
830 $filter = Main\Entity\Query::filter();
831 $filter->whereIn(
'PRODUCT_ID', $pageOfferIds);
832 $filter->where(Main\Entity\Query::filter()->logic(
'or')->where(
'QUANTITY_FROM',
'<=', 1)->whereNull(
'QUANTITY_FROM'));
833 $filter->where(Main\Entity\Query::filter()->logic(
'or')->where(
'QUANTITY_TO',
'>=', 1)->whereNull(
'QUANTITY_TO'));
837 'PRODUCT_ID',
'CATALOG_GROUP_ID',
'PRICE',
'CURRENCY',
838 'PRICE_SCALE',
'TMP_ID'
841 'order' =>
array(
'PRODUCT_ID' =>
'ASC',
'CATALOG_GROUP_ID' =>
'ASC')
845 $typeId = (int)$row[
'CATALOG_GROUP_ID'];
846 $offerId = (int)$row[
'PRODUCT_ID'];
848 unset($row[
'PRODUCT_ID']);
850 if (!isset($this->calculatePrices[$productId][$typeId]))
851 $this->calculatePrices[
$productId][$typeId] = $row;
852 elseif ($this->calculatePrices[$productId][$typeId][
'PRICE_SCALE'] > $row[
'PRICE_SCALE'])
853 $this->calculatePrices[
$productId][$typeId] = $row;
860 private function loadOffersData()
862 if (empty($this->currentList))
866 $this->currentIdsList,
867 $this->params[
'IBLOCK_ID']
872 foreach ($this->currentIdsList as $id)
873 $this->currentList[$id][
'PARENT_EXISTS'] = isset(
$productList[$id]);
877 private function loadProductSets()
879 if (!$this->config[
'CHECK_SETS'])
881 if (empty($this->currentIdsList))
884 foreach ($this->currentIdsList as $id)
886 $this->currentList[$id][
'SET_EXISTS'] =
false;
887 $this->currentList[$id][
'BUNDLE_EXISTS'] =
false;
892 $conn = Main\Application::getConnection();
893 $helper = $conn->getSqlHelper();
894 $tableName = $helper->quote(
'b_catalog_product_sets');
896 'select '.$helper->quote(
'OWNER_ID').
', '.$helper->quote(
'TYPE').
' from '.$tableName.
897 ' where '.$helper->quote(
'OWNER_ID').
' in ('.implode(
',', $this->currentIdsList).
') and '.
898 $helper->quote(
'OWNER_ID').
' = '.$helper->quote(
'ITEM_ID')
902 $id = (int)$row[
'OWNER_ID'];
904 $this->currentList[$id][
'SET_EXISTS'] =
true;
906 $this->currentList[$id][
'BUNDLE_EXISTS'] =
true;
909 unset($tableName, $helper, $conn);
912 private function loadMeasureRatios()
914 $this->measureRatios =
array();
915 if (!$this->config[
'CHECK_MEASURE_RATIO'])
917 if (empty($this->currentIdsList))
920 $this->measureRatios = array_fill_keys(
921 $this->currentIdsList,
924 'DEFAULT_EXISTS' =>
false,
925 'DEFAULT_RATIO_ID' =>
null,
929 foreach (array_chunk($this->currentIdsList, 500) as $pageIds)
932 'select' =>
array(
'*'),
933 'filter' =>
array(
'@PRODUCT_ID' => $pageIds),
934 'order' =>
array(
'PRODUCT_ID' =>
'ASC',
'RATIO' =>
'ASC')
939 $this->measureRatios[
$productId][
'RATIOS'][$row[
'ID']] = $row;
940 if ($row[
'IS_DEFAULT'] ==
'Y')
942 if ($this->measureRatios[$productId][
'DEFAULT_EXISTS'])
944 $this->measureRatios[
$productId][
'DOUBLES'][] = $row[
'ID'];
948 $this->measureRatios[
$productId][
'DEFAULT_EXISTS'] =
true;
949 $this->measureRatios[
$productId][
'DEFAULT_RATIO_ID'] = $row[
'ID'];
954 unset($productId, $row,
$iterator, $pageIds);
957 private function updateProductData()
959 if (empty($this->currentIdsList))
963 $this->config[
'CHECK_MEASURE']
965 && (isset($this->iblockData[
'SUBSCRIPTION']) && $this->iblockData[
'SUBSCRIPTION'] !=
'Y')
968 foreach ($this->currentIdsList as $id)
970 $product = $this->currentList[$id];
971 $product[
'SUCCESS'] =
true;
972 if ($this->config[
'CHECK_AVAILABLE'])
974 switch ($this->iblockData[
'CATALOG_TYPE'])
977 $fields = $this->getCatalogItem($product);
980 $fields = $this->getOfferIblockItem($product);
983 $fields = $this->getFullCatalogItem($product);
986 $fields = $this->getProductIblockItem($product);
993 if ($this->config[
'CHECK_SETS'])
995 $fields[
'BUNDLE'] = ($product[
'BUNDLE_EXISTS']
996 ? Catalog\ProductTable::STATUS_YES
997 : Catalog\ProductTable::STATUS_NO
1002 if (
$fields[
'TYPE'] == Catalog\ProductTable::TYPE_SET)
1004 if ($this->measureIds[
'BASE'] !==
null)
1006 $fields[
'MEASURE'] = $this->measureIds[
'BASE'];
1011 if ((
int)$product[
'MEASURE'] <= 0 && $this->measureIds[
'DEFAULT'] !==
null)
1013 $fields[
'MEASURE'] = $this->measureIds[
'DEFAULT'];
1018 if ($product[
'PRODUCT_EXISTS'])
1020 $productResult = Catalog\ProductTable::update($product[
'ID'],
$fields);
1024 $fields[
'ID'] = $product[
'ID'];
1025 $productResult = Catalog\ProductTable::add(
$fields);
1030 if ($productResult->isSuccess())
1032 $product = array_merge($product,
$fields);
1036 $product[
'SUCCESS'] =
false;
1037 $errorId =
'BX_CATALOG_REINDEX_ERR_PRODUCT_UPDATE_FAIL_EXT';
1039 $product[
'TYPE'] == Catalog\ProductTable::TYPE_OFFER
1040 || $product[
'TYPE'] == Catalog\ProductTable::TYPE_FREE_OFFER
1042 $errorId =
'BX_CATALOG_REINDEX_ERR_OFFER_UPDATE_FAIL_EXT';
1047 '#NAME#' => $product[
'NAME'],
1048 '#ERROR#' => implode(
'; ', $productResult->getErrorMessages())
1053 unset($productResult,
$fields);
1056 if ($product[
'SUCCESS'])
1058 if ($this->config[
'CHECK_PRICES'])
1059 $this->updateProductPrices($id, $product);
1060 if ($this->config[
'CHECK_SKU_PRICES'])
1062 $this->updateSkuPrices($id, $product);
1063 if ($product[
'TYPE'] == Catalog\ProductTable::TYPE_SKU)
1064 Iblock\PropertyIndex\Manager::updateElementIndex($this->params[
'IBLOCK_ID'], $id);
1066 if ($this->config[
'CHECK_MEASURE_RATIO'])
1067 $this->updateMeasureRatios($id, $product);
1078 private function updateProductPrices($id,
array $product)
1080 if (!$this->config[
'CHECK_PRICES'])
1083 if ($product[
'TYPE'] == Catalog\ProductTable::TYPE_SKU && !$this->config[
'SEPARATE_SKU_MODE'])
1086 if (empty($this->prices[$id]))
1089 if ($product[
'TYPE'] == Catalog\ProductTable::TYPE_EMPTY_SKU)
1091 unset($this->prices[$id]);
1092 unset($this->existIdsByType[$id]);
1093 unset($this->existPriceIds[$id]);
1095 $conn = Main\Application::getConnection();
1096 $helper = $conn->getSqlHelper();
1097 $conn->queryExecute(
1098 'delete from '.$helper->quote(Catalog\PriceTable::getTableName()).
1099 ' where '.$helper->quote(
'PRODUCT_ID').
' = '.$id
1101 unset($helper, $conn);
1107 foreach (array_keys($this->prices[$id]) as $rowId)
1109 $row = $this->prices[$id][$rowId];
1111 !isset($this->currencyReference[$row[
'CURRENCY']])
1112 || $this->currencyReference[$row[
'CURRENCY']] == 0
1115 $baseRate = $this->currencyReference[$row[
'CURRENCY']];
1116 $newScale = $row[
'PRICE'] * $baseRate;
1117 if ($newScale == $row[
'PRICE_SCALE'])
1119 $rowResult = Catalog\PriceTable::update($rowId, [
'PRICE_SCALE' => $newScale]);
1120 if (!$rowResult->isSuccess())
1127 unset($rowResult, $newScale, $baseRate, $row, $rowId);
1129 unset($this->prices[$id]);
1133 $errorId =
'BX_CATALOG_REINDEX_ERR_PRODUCT_PRICE_UPDATE_FAIL_EXT';
1135 $product[
'TYPE'] == Catalog\ProductTable::TYPE_OFFER
1136 || $product[
'TYPE'] == Catalog\ProductTable::TYPE_FREE_OFFER
1138 $errorId =
'BX_CATALOG_REINDEX_ERR_OFFER_PRICE_UPDATE_FAIL_EXT';
1143 '#NAME#' => $product[
'NAME'],
1152 private function updateSkuPrices($id,
array $product)
1154 if ($product[
'TYPE'] != Catalog\ProductTable::TYPE_SKU)
1156 if (!$this->config[
'CHECK_SKU_PRICES'] || $this->config[
'SEPARATE_SKU_MODE'])
1161 if (!empty($this->calculatePrices[$id]))
1163 foreach (array_keys($this->calculatePrices[$id]) as $resultPriceType)
1166 $row = $this->calculatePrices[$id][$resultPriceType];
1167 if (!empty($this->existIdsByType[$id][$resultPriceType]))
1169 $rowId = array_shift($this->existIdsByType[$id][$resultPriceType]);
1170 unset($this->existPriceIds[$id][$rowId]);
1171 unset($this->prices[$id][$rowId]);
1173 if ($rowId ===
null)
1175 $row[
'PRODUCT_ID'] = $id;
1176 $row[
'CATALOG_GROUP_ID'] = $resultPriceType;
1177 $rowResult = Catalog\PriceTable::add($row);
1181 $rowResult = Catalog\PriceTable::update($rowId, $row);
1183 if (!$rowResult->isSuccess())
1191 unset($this->calculatePrices[$id]);
1193 if (
$success && !empty($this->existPriceIds[$id]))
1195 $conn = Main\Application::getConnection();
1196 $helper = $conn->getSqlHelper();
1197 $conn->queryExecute(
1198 'delete from '.$helper->quote(Catalog\PriceTable::getTableName()).
1199 ' where '.$helper->quote(
'ID').
' in ('.implode(
',', $this->existPriceIds[$id]).
')'
1201 unset($helper, $conn);
1204 if (isset($this->existPriceIds[$id]))
1205 unset($this->existPriceIds[$id]);
1210 'BX_CATALOG_REINDEX_ERR_PRODUCT_UPDATE_FAIL_EXT',
1213 '#NAME#' => $product[
'NAME'],
1221 private function updateMeasureRatios($id,
array $product)
1223 if (!$this->config[
'CHECK_MEASURE_RATIO'])
1226 if (!isset($this->measureRatios[$id]))
1230 if (isset($this->iblockData[
'SUBSCRIPTION']) && $this->iblockData[
'SUBSCRIPTION'] ==
'Y')
1232 if (!empty($this->measureRatios[$id][
'RATIOS']))
1238 $product[
'TYPE'] == Catalog\ProductTable::TYPE_PRODUCT
1239 || $product[
'TYPE'] == Catalog\ProductTable::TYPE_OFFER
1240 || $product[
'TYPE'] == Catalog\ProductTable::TYPE_FREE_OFFER
1243 if (!empty($this->measureRatios[$id][
'RATIOS']))
1248 elseif ($product[
'TYPE'] == Catalog\ProductTable::TYPE_SET)
1250 if (!empty($this->measureRatios[$id][
'RATIOS']))
1255 elseif ($product[
'TYPE'] == Catalog\ProductTable::TYPE_EMPTY_SKU)
1257 if (!empty($this->measureRatios[$id][
'RATIOS']))
1260 elseif ($product[
'TYPE'] == Catalog\ProductTable::TYPE_SKU)
1262 if ($this->config[
'SEPARATE_SKU_MODE'])
1264 if (!empty($this->measureRatios[$id][
'RATIOS']))
1271 if (!empty($this->measureRatios[$id][
'RATIOS']))
1279 $ratioResult = Catalog\MeasureRatioTable::add(
array(
1280 'PRODUCT_ID' => $id,
1284 unset($ratioResult);
1287 if (!$this->measureRatios[$id][
'DEFAULT_EXISTS'])
1289 $firstRatio = reset($this->measureRatios[$id][
'RATIOS']);
1290 $ratioResult = Catalog\MeasureRatioTable::update($firstRatio[
'ID'],
array(
'IS_DEFAULT' =>
'Y'));
1291 unset($ratioResult, $firstRatio);
1293 if (!empty($this->measureRatios[$id][
'DOUBLES']))
1295 foreach ($this->measureRatios[$id][
'DOUBLES'] as $ratioId)
1297 $ratioResult = Catalog\MeasureRatioTable::update($ratioId,
array(
'IS_DEFAULT' =>
'N'));
1299 unset($ratioResult, $ratioId);
1304 foreach ($this->measureRatios[$id][
'RATIOS'] as $row)
1306 if ($row[
'RATIO'] == 1)
1308 $ratioId = $row[
'ID'];
1313 if ($ratioId ===
null && $this->measureRatios[$id][
'DEFAULT_RATIO_ID'] !==
null)
1314 $ratioId = $this->measureRatios[$id][
'DEFAULT_RATIO_ID'];
1315 if ($ratioId ===
null)
1317 $firstRatio = reset($this->measureRatios[$id][
'RATIOS']);
1318 $ratioId = $firstRatio[
'ID'];
1321 foreach ($this->measureRatios[$id][
'RATIOS'] as $row)
1323 if ($row[
'ID'] == $ratioId)
1325 $ratioResult = Catalog\MeasureRatioTable::update(
1327 array(
'RATIO' => 1,
'IS_DEFAULT' =>
'Y')
1332 $ratioResult = Catalog\MeasureRatioTable::delete($row[
'ID']);
1335 unset($ratioResult, $row, $ratioId);
1339 Catalog\MeasureRatioTable::deleteByProduct($id);
1346 unset($this->measureRatios[$id]);
1349 private function getFullCatalogItem(
array $product):
array
1352 switch ($product[
'SKU_STATE'])
1354 case Catalog\Product\Sku::OFFERS_AVAILABLE:
1355 case Catalog\Product\Sku::OFFERS_NOT_AVAILABLE:
1356 if ($this->config[
'SEPARATE_SKU_MODE'])
1359 'AVAILABLE' => Catalog\ProductTable::calculateAvailable($product),
1360 'TYPE' => Catalog\ProductTable::TYPE_SKU,
1365 $fields = Catalog\Product\Sku::getDefaultParentSettings($product[
'SKU_STATE']);
1368 case Catalog\Product\Sku::OFFERS_NOT_EXIST:
1369 switch ($product[
'TYPE'])
1371 case Catalog\ProductTable::TYPE_SKU:
1372 case Catalog\ProductTable::TYPE_EMPTY_SKU:
1373 $fields = Catalog\Product\Sku::getDefaultParentSettings($product[
'SKU_STATE']);
1375 case Catalog\ProductTable::TYPE_PRODUCT:
1376 case Catalog\ProductTable::TYPE_SET:
1377 $fields[
'AVAILABLE'] = Catalog\ProductTable::calculateAvailable($product);
1378 $fields[
'TYPE'] = (int)$product[
'TYPE'];
1380 case Catalog\ProductTable::TYPE_SERVICE:
1381 $fields[
'TYPE'] = (int)$product[
'TYPE'];
1384 $fields = Catalog\ProductTable::getDefaultAvailableSettings();
1385 $fields[
'TYPE'] = Catalog\ProductTable::TYPE_PRODUCT;
1391 return $this->prepareSetState(
$fields, $product);
1394 private function getProductIblockItem(
array $product):
array
1396 return Catalog\Product\Sku::getParentProductFieldsByState(
1397 $product[
'SKU_STATE']
1401 private function getCatalogItem(
array $product):
array
1403 if ($product[
'PRODUCT_EXISTS'])
1405 switch ($product[
'TYPE'])
1407 case Catalog\ProductTable::TYPE_PRODUCT:
1408 case Catalog\ProductTable::TYPE_SET:
1409 $fields[
'AVAILABLE'] = Catalog\ProductTable::calculateAvailable($product);
1410 $fields[
'TYPE'] = (int)$product[
'TYPE'];
1412 case Catalog\ProductTable::TYPE_SERVICE:
1413 $fields[
'TYPE'] = (int)$product[
'TYPE'];
1417 'AVAILABLE' => Catalog\ProductTable::calculateAvailable($product),
1418 'TYPE' => Catalog\ProductTable::TYPE_PRODUCT,
1425 $fields = Catalog\ProductTable::getDefaultAvailableSettings();
1426 $fields[
'TYPE'] = Catalog\ProductTable::TYPE_PRODUCT;
1429 return $this->prepareSetState(
$fields, $product);
1432 private function getOfferIblockItem(
array $product):
array
1435 'AVAILABLE' => Catalog\ProductTable::calculateAvailable($product),
1436 'TYPE' => ($product[
'PARENT_EXISTS'] ? Catalog\ProductTable::TYPE_OFFER : Catalog\ProductTable::TYPE_FREE_OFFER)
1442 if (!$this->config[
'CHECK_SETS'])
1447 if (
$fields[
'TYPE'] == Catalog\ProductTable::TYPE_SET && !$product[
'SET_EXISTS'])
1449 $fields[
'TYPE'] = Catalog\ProductTable::TYPE_PRODUCT;
1451 elseif (
$fields[
'TYPE'] == Catalog\ProductTable::TYPE_PRODUCT && $product[
'SET_EXISTS'])
1453 $fields[
'TYPE'] = Catalog\ProductTable::TYPE_SET;