23 private static $landingSections;
25 private static $iblockSections;
27 private static $fullIblockSections;
29 private static $elementCount;
31 private static $iblockList = [];
33 private static $crmIncluded;
57 return (Main\
Config\Option::get(
'catalog',
'default_use_store_control') ===
'Y');
67 if (!self::isUsedInventoryManagement())
72 Main\
Config\Option::get(
'catalog',
'enable_reservation') ===
'Y'
73 && Main\
Config\Option::get(
'catalog',
'show_store_reserve') ===
'Y'
78 if (self::isCrmIncluded())
80 return (Main\
Config\Option::get(
'crm',
'enable_order_deal_create') ===
'Y');
98 return Catalog\GroupTable::getCount([], [
'ttl' => 86400]) > 1;
113 return Catalog\GroupTable::getCount([], [
'ttl' => 86400]) === 0;
128 return Catalog\StoreTable::getCount([], [
'ttl' => 86400]) > 1;
143 return Catalog\StoreTable::getCount([], [
'ttl' => 86400]) === 0;
160 if (!ModuleManager::isModuleInstalled(
'bitrix24'))
165 if ($iblockId !== self::getCrmCatalogId())
170 $result = self::checkIblockLimit($iblockId);
171 if ($result !==
null && $sectionId !==
null)
173 self::loadIblockSections($iblockId);
174 if (!isset(self::$fullIblockSections[$sectionId]))
179 if ($result ===
null)
181 $result = self::getCrmCatalogLimit($iblockId);
194 $crmCatalogId = self::getCrmCatalogId();
195 if ($crmCatalogId > 0)
210 if (!ModuleManager::isModuleInstalled(
'bitrix24'))
215 if ($iblockId !== self::getCrmCatalogId())
222 $result[$variable] = [
223 'LIMIT_NAME' => $variable,
225 'CURRENT_VALUE' => self::getElementCount($iblockId),
228 $crmLimit = self::getCrmCatalogLimitState($iblockId);
229 if ($crmLimit !==
null)
231 $result[$crmLimit[
'LIMIT_NAME']] = $crmLimit;
245 if (!self::checkIblockId($fields))
250 $limit = self::checkIblockLimit((
int)$fields[
'IBLOCK_ID']);
256 if (!isset($fields[
'IBLOCK_SECTION']) || !is_array($fields[
'IBLOCK_SECTION']))
260 $sections = $fields[
'IBLOCK_SECTION'];
261 Main\Type\Collection::normalizeArrayValuesByInt($sections,
true);
262 if (empty($sections))
266 self::loadIblockSections((
int)$fields[
'IBLOCK_ID']);
267 $sections = array_intersect($sections, self::$fullIblockSections);
268 if (empty($sections))
274 self::setProductLimitError($limit[
'MESSAGE']);
288 if ($fields[
'RESULT'] ===
false)
291 if (!self::checkIblockId($fields))
294 $sections = $fields[
'IBLOCK_SECTION'] ??
null;
295 Main\Type\Collection::normalizeArrayValuesByInt($sections,
true);
296 if (empty($sections))
298 self::loadIblockSections((
int)$fields[
'IBLOCK_ID']);
299 $sections = array_intersect($sections, self::$fullIblockSections);
300 if (empty($sections))
303 self::$elementCount =
null;
314 if (!self::checkIblockId($fields))
319 $limit = self::checkIblockLimit((
int)$fields[
'IBLOCK_ID']);
325 if (!isset($fields[
'IBLOCK_SECTION']) || !is_array($fields[
'IBLOCK_SECTION']))
329 $sections = $fields[
'IBLOCK_SECTION'];
330 Main\Type\Collection::normalizeArrayValuesByInt($sections,
true);
331 if (empty($sections))
335 self::loadIblockSections((
int)$fields[
'IBLOCK_ID']);
336 $sections = array_intersect($sections, self::$fullIblockSections);
337 if (empty($sections))
344 $iterator = Iblock\SectionElementTable::getList([
345 'select' => [
'IBLOCK_SECTION_ID'],
347 '=IBLOCK_ELEMENT_ID' => $fields[
'ID'],
348 '=ADDITIONAL_PROPERTY_ID' =>
null,
351 while ($row = $iterator->fetch())
353 $row[
'ID'] = (int)$row[
'ID'];
354 if (isset(self::$fullIblockSections[$row[
'ID']]))
360 unset($row, $iterator);
366 self::setProductLimitError($limit[
'MESSAGE']);
380 if ($fields[
'RESULT'] ===
false)
384 if (!self::checkIblockId($fields))
388 if (!array_key_exists(
'IBLOCK_SECTION', $fields))
393 self::$elementCount =
null;
404 if (!self::checkIblockId($fields))
407 self::$elementCount =
null;
418 if ($fields[
'RESULT'] ===
false)
420 if (!self::checkIblockId($fields))
423 self::$iblockSections =
null;
424 self::$fullIblockSections =
null;
435 if (!self::checkIblockId($fields))
440 $limit = self::getIblockLimit((
int)$fields[
'IBLOCK_ID']);
441 if ($limit[
'LIMIT'] === 0)
445 if (!array_key_exists(
'IBLOCK_SECTION_ID', $fields))
449 $parentId = (int)$fields[
'IBLOCK_SECTION_ID'];
450 self::loadIblockSections((
int)$fields[
'IBLOCK_ID']);
451 if (!isset(self::$fullIblockSections[$parentId]))
455 $iterator = Iblock\SectionTable::getList([
456 'select' => [
'IBLOCK_SECTION_ID'],
458 '=ID' => $fields[
'ID'],
459 '=IBLOCK_ID' => $fields[
'IBLOCK_ID'],
462 $row = $iterator->fetch();
468 $oldParentId = (int)$row[
'IBLOCK_SECTION_ID'];
469 if (isset(self::$fullIblockSections[$oldParentId]))
474 $count = (int)\CIBlockElement::GetList(
477 'IBLOCK_ID' => $fields[
'IBLOCK_ID'],
478 'SECTION_ID' => $fields[
'ID'],
479 'INCLUDE_SUBSECTIONS' =>
'Y',
480 'CHECK_PERMISSIONS' =>
'N',
490 $limit[
'COUNT'] += $count;
491 if ($limit[
'COUNT'] <= $limit[
'LIMIT'])
496 $limit[
'MESSAGE_ID'] =
'CATALOG_STATE_ERR_PRODUCT_IN_SECTION_LIMIT';
498 self::setProductLimitError(self::getProductLimitError($limit));
512 if ($fields[
'RESULT'] ===
false)
516 if (!self::checkIblockId($fields))
520 if (!array_key_exists(
'IBLOCK_SECTION_ID', $fields))
525 self::$iblockSections =
null;
526 self::$fullIblockSections =
null;
527 self::$elementCount =
null;
538 if (!self::checkIblockId($fields))
541 self::$iblockSections =
null;
542 self::$fullIblockSections =
null;
543 self::$elementCount =
null;
550 private static function getElementCount(
int $iblockId): int
552 if (self::$elementCount ===
null)
554 self::$elementCount = 0;
556 $iblockSectionIds = self::getIblockSections($iblockId);
557 if (!empty($iblockSectionIds))
560 'IBLOCK_ID' => $iblockId,
561 'SECTION_ID' => $iblockSectionIds,
562 'INCLUDE_SUBSECTIONS' =>
'Y',
563 'CHECK_PERMISSIONS' =>
'N',
565 $filter = Catalog\Product\SystemField\ProductMapping::getExtendedFilterByArea(
569 self::$elementCount = (int)\CIBlockElement::GetList(
577 unset($iblockSectionIds);
579 return self::$elementCount;
586 private static function getIblockSections(
int $iblockId): array
588 if (self::$iblockSections ===
null)
590 self::loadIblockSections($iblockId);
592 return self::$iblockSections;
599 private static function loadIblockSections(
int $iblockId): void
601 if (self::$iblockSections ===
null)
603 self::$iblockSections = [];
604 self::$fullIblockSections = [];
605 $sections = self::getLandingSections();
606 if (!empty($sections))
608 $iterator = Iblock\SectionTable::getList([
615 '=IBLOCK_ID' => $iblockId,
619 while ($row = $iterator->fetch())
621 $row[
'ID'] = (int)$row[
'ID'];
622 self::$iblockSections[] = $row[
'ID'];
623 self::$fullIblockSections[$row[
'ID']] = $row[
'ID'];
624 $sublist = Iblock\SectionTable::getList([
627 '=IBLOCK_ID' => $iblockId,
628 '>LEFT_MARGIN' => $row[
'LEFT_MARGIN'],
629 '<RIGHT_MARGIN' => $row[
'RIGHT_MARGIN'],
632 while ($sub = $sublist->fetch())
634 $sub[
'ID'] = (int)$sub[
'ID'];
635 self::$fullIblockSections[$sub[
'ID']] = $sub[
'ID'];
638 unset($sub, $sublist, $row, $iterator);
649 private static function getLandingSections(): array
651 if (self::$landingSections ===
null)
653 self::$landingSections = [];
655 if (!Loader::includeModule(
'landing'))
657 return self::$landingSections;
660 $iterator = Landing\Internals\HookDataTable::getList([
662 new Main\ORM\Fields\Relations\Reference(
664 'Bitrix\Landing\Internals\SiteTable',
665 [
'=this.ENTITY_ID' =>
'ref.ID']
668 'select' => [
'VALUE'],
671 '=HOOK' =>
'SETTINGS',
672 '=CODE' =>
'SECTION_ID',
673 '=TMP_LANDING_SITE.DELETED' =>
'N',
675 'cache' => [
'ttl' => 86400],
677 while ($row = $iterator->fetch())
679 $id = (int)$row[
'VALUE'];
684 self::$landingSections[$id] = $id;
686 unset($id, $row, $iterator);
688 if (!empty(self::$landingSections))
690 self::$landingSections = array_values(self::$landingSections);
694 return self::$landingSections;
702 private static function getCrmCatalogId(): ?int
705 if (self::isCrmIncluded())
707 $result = Crm\Product\Catalog::getDefaultId();
717 private static function getCrmCatalogLimit(
int $iblockId): ?array
719 if (!self::isCrmIncluded())
724 return Crm\Config\State::getExceedingProductLimit($iblockId);
727 private static function getCrmCatalogLimitState(
int $iblockId): ?array
729 if (!self::isCrmIncluded())
734 if (!method_exists(
'\Bitrix\Crm\Config\State',
'getProductLimitState'))
739 return Crm\Config\State::getProductLimitState($iblockId);
747 private static function isCrmIncluded(): bool
749 if (self::$crmIncluded ===
null)
751 self::$crmIncluded = Loader::includeModule(
'crm');
754 return self::$crmIncluded;
763 private static function checkIblockId(array $fields): bool
765 if (!isset($fields[
'IBLOCK_ID']))
769 $iblockId = (int)$fields[
'IBLOCK_ID'];
774 if (!isset(self::$iblockList[$iblockId]))
777 if (!ModuleManager::isModuleInstalled(
'bitrix24'))
781 if ($iblockId !== self::getCrmCatalogId())
785 self::$iblockList[$iblockId] = $result;
788 return self::$iblockList[$iblockId];
804 private static function checkIblockLimit(
int $iblockId): ?array
806 $result = self::getIblockLimit($iblockId);
808 $result[
'LIMIT'] === 0
809 || $result[
'COUNT'] < $result[
'LIMIT']
814 $result[
'MESSAGE'] = self::getProductLimitError($result);
815 unset($result[
'MESSAGE_ID']);
833 private static function getIblockLimit(
int $iblockId): array
838 'MESSAGE_ID' =>
'CATALOG_STATE_ERR_PRODUCT_LIMIT_1'
840 if ($result[
'LIMIT'] === 0)
844 $result[
'COUNT'] = self::getElementCount($iblockId);
855 private static function getProductLimitError(array $limit): ?string
857 if (!isset($limit[
'COUNT']) || !isset($limit[
'LIMIT']) || !isset($limit[
'MESSAGE_ID']))
863 $limit[
'MESSAGE_ID'],
865 '#COUNT#' => $limit[
'COUNT'],
866 '#LIMIT#' => $limit[
'LIMIT']
877 private static function setProductLimitError(
string $errorMessage): void
881 $error = new \CAdminException([
883 'text' => $errorMessage,
886 $APPLICATION->ThrowException($error);
901 return Main\Config\Option::get(
'catalog',
'product_card_slider_enabled') ===
'Y';
916 return \Bitrix\Catalog\Product\Store\CostPriceCalculator::getMethod() !==
'';
static getMessage($code, $replace=null, $language=null)