3namespace Bitrix\Catalog\Config;
7use Bitrix\Main\ModuleManager;
8use Bitrix\Main\Localization\Loc;
22 private const EXTERNAL_CATALOG_OPTION =
'is_external_catalog';
25 private static $landingSections;
27 private static $iblockSections;
29 private static $fullIblockSections;
31 private static $elementCount;
33 private static $iblockList = [];
35 private static $crmIncluded;
59 return (
Main\
Config\Option::get(
'catalog',
'default_use_store_control') ===
'Y');
79 if (!self::isUsedInventoryManagement())
84 Main\
Config\Option::get(
'catalog',
'enable_reservation') ===
'Y'
85 &&
Main\
Config\Option::get(
'catalog',
'show_store_reserve') ===
'Y'
90 if (self::isCrmIncluded())
92 return (
Main\
Config\Option::get(
'crm',
'enable_order_deal_create') ===
'Y');
140 return Catalog\StoreTable::getCount([], [
'ttl' => 86400]) > 1;
155 return Catalog\StoreTable::getCount([], [
'ttl' => 86400]) === 0;
172 if (!ModuleManager::isModuleInstalled(
'bitrix24'))
177 if (
$iblockId !== self::getCrmCatalogId())
183 if (
$result !==
null && $sectionId !==
null)
186 if (!isset(self::$fullIblockSections[$sectionId]))
206 $crmCatalogId = self::getCrmCatalogId();
207 if ($crmCatalogId > 0)
222 if (!ModuleManager::isModuleInstalled(
'bitrix24'))
227 if (
$iblockId !== self::getCrmCatalogId())
235 'LIMIT_NAME' => $variable,
237 'CURRENT_VALUE' => self::getElementCount(
$iblockId),
240 $crmLimit = self::getCrmCatalogLimitState(
$iblockId);
241 if ($crmLimit !==
null)
243 $result[$crmLimit[
'LIMIT_NAME']] = $crmLimit;
257 if (!self::checkIblockId(
$fields))
262 $limit = self::checkIblockLimit((
int)
$fields[
'IBLOCK_ID']);
268 if (!isset(
$fields[
'IBLOCK_SECTION']) || !is_array(
$fields[
'IBLOCK_SECTION']))
272 $sections =
$fields[
'IBLOCK_SECTION'];
274 if (empty($sections))
278 self::loadIblockSections((
int)
$fields[
'IBLOCK_ID']);
279 $sections = array_intersect($sections, self::$fullIblockSections);
280 if (empty($sections))
286 self::setProductLimitError($limit[
'MESSAGE']);
300 if (
$fields[
'RESULT'] ===
false)
303 if (!self::checkIblockId(
$fields))
306 $sections =
$fields[
'IBLOCK_SECTION'] ??
null;
308 if (empty($sections))
310 self::loadIblockSections((
int)
$fields[
'IBLOCK_ID']);
311 $sections = array_intersect($sections, self::$fullIblockSections);
312 if (empty($sections))
315 self::$elementCount =
null;
326 if (!self::checkIblockId(
$fields))
331 $limit = self::checkIblockLimit((
int)
$fields[
'IBLOCK_ID']);
337 if (!isset(
$fields[
'IBLOCK_SECTION']) || !is_array(
$fields[
'IBLOCK_SECTION']))
341 $sections =
$fields[
'IBLOCK_SECTION'];
343 if (empty($sections))
347 self::loadIblockSections((
int)
$fields[
'IBLOCK_ID']);
348 $sections = array_intersect($sections, self::$fullIblockSections);
349 if (empty($sections))
356 $iterator = Iblock\SectionElementTable::getList([
357 'select' => [
'IBLOCK_SECTION_ID'],
359 '=IBLOCK_ELEMENT_ID' =>
$fields[
'ID'],
360 '=ADDITIONAL_PROPERTY_ID' =>
null,
365 $row[
'ID'] = (int)$row[
'ID'];
366 if (isset(self::$fullIblockSections[$row[
'ID']]))
378 self::setProductLimitError($limit[
'MESSAGE']);
392 if (
$fields[
'RESULT'] ===
false)
396 if (!self::checkIblockId(
$fields))
400 if (!array_key_exists(
'IBLOCK_SECTION',
$fields))
405 self::$elementCount =
null;
416 if (!self::checkIblockId(
$fields))
419 self::$elementCount =
null;
430 if (
$fields[
'RESULT'] ===
false)
432 if (!self::checkIblockId(
$fields))
435 self::$iblockSections =
null;
436 self::$fullIblockSections =
null;
447 if (!self::checkIblockId(
$fields))
452 $limit = self::getIblockLimit((
int)
$fields[
'IBLOCK_ID']);
453 if ($limit[
'LIMIT'] === 0)
457 if (!array_key_exists(
'IBLOCK_SECTION_ID',
$fields))
461 $parentId = (int)
$fields[
'IBLOCK_SECTION_ID'];
462 self::loadIblockSections((
int)
$fields[
'IBLOCK_ID']);
463 if (!isset(self::$fullIblockSections[$parentId]))
468 'select' => [
'IBLOCK_SECTION_ID'],
471 '=IBLOCK_ID' =>
$fields[
'IBLOCK_ID'],
480 $oldParentId = (int)$row[
'IBLOCK_SECTION_ID'];
481 if (isset(self::$fullIblockSections[$oldParentId]))
486 $count = (int)\CIBlockElement::GetList(
489 'IBLOCK_ID' =>
$fields[
'IBLOCK_ID'],
491 'INCLUDE_SUBSECTIONS' =>
'Y',
492 'CHECK_PERMISSIONS' =>
'N',
502 $limit[
'COUNT'] +=
$count;
503 if ($limit[
'COUNT'] <= $limit[
'LIMIT'])
508 $limit[
'MESSAGE_ID'] =
'CATALOG_STATE_ERR_PRODUCT_IN_SECTION_LIMIT';
510 self::setProductLimitError(self::getProductLimitError($limit));
524 if (
$fields[
'RESULT'] ===
false)
528 if (!self::checkIblockId(
$fields))
532 if (!array_key_exists(
'IBLOCK_SECTION_ID',
$fields))
537 self::$iblockSections =
null;
538 self::$fullIblockSections =
null;
539 self::$elementCount =
null;
550 if (!self::checkIblockId(
$fields))
553 self::$iblockSections =
null;
554 self::$fullIblockSections =
null;
555 self::$elementCount =
null;
562 private static function getElementCount(
int $iblockId): int
564 if (self::$elementCount ===
null)
566 self::$elementCount = 0;
568 $iblockSectionIds = self::getIblockSections(
$iblockId);
569 if (!empty($iblockSectionIds))
573 'SECTION_ID' => $iblockSectionIds,
574 'INCLUDE_SUBSECTIONS' =>
'Y',
575 'CHECK_PERMISSIONS' =>
'N',
577 $filter = Catalog\Product\SystemField\ProductMapping::getExtendedFilterByArea(
581 self::$elementCount = (int)\CIBlockElement::GetList(
589 unset($iblockSectionIds);
591 return self::$elementCount;
600 if (self::$iblockSections ===
null)
604 return self::$iblockSections;
611 private static function loadIblockSections(
int $iblockId): void
613 if (self::$iblockSections ===
null)
615 self::$iblockSections = [];
616 self::$fullIblockSections = [];
617 $sections = self::getLandingSections();
618 if (!empty($sections))
620 $iterator = Iblock\SectionTable::getList([
633 $row[
'ID'] = (int)$row[
'ID'];
634 self::$iblockSections[] = $row[
'ID'];
635 self::$fullIblockSections[$row[
'ID']] = $row[
'ID'];
636 $sublist = Iblock\SectionTable::getList([
640 '>LEFT_MARGIN' => $row[
'LEFT_MARGIN'],
641 '<RIGHT_MARGIN' => $row[
'RIGHT_MARGIN'],
644 while ($sub = $sublist->fetch())
646 $sub[
'ID'] = (int)$sub[
'ID'];
647 self::$fullIblockSections[$sub[
'ID']] = $sub[
'ID'];
661 private static function getLandingSections():
array
663 if (self::$landingSections ===
null)
665 self::$landingSections = [];
667 if (!Loader::includeModule(
'landing'))
669 return self::$landingSections;
672 $iterator = Landing\Internals\HookDataTable::getList([
674 new Main\ORM\Fields\Relations\Reference(
676 'Bitrix\Landing\Internals\SiteTable',
677 [
'=this.ENTITY_ID' =>
'ref.ID']
680 'select' => [
'VALUE'],
682 '=ENTITY_TYPE' => Landing\Hook::ENTITY_TYPE_SITE,
683 '=HOOK' =>
'SETTINGS',
684 '=CODE' =>
'SECTION_ID',
685 '=TMP_LANDING_SITE.DELETED' =>
'N',
687 'cache' => [
'ttl' => 86400],
691 $id = (int)$row[
'VALUE'];
696 self::$landingSections[$id] = $id;
700 if (!empty(self::$landingSections))
702 self::$landingSections = array_values(self::$landingSections);
706 return self::$landingSections;
714 private static function getCrmCatalogId(): ?int
717 if (self::isCrmIncluded())
719 $result = Crm\Product\Catalog::getDefaultId();
731 if (!self::isCrmIncluded())
736 return Crm\Config\State::getExceedingProductLimit(
$iblockId);
739 private static function getCrmCatalogLimitState(
int $iblockId): ?
array
741 if (!self::isCrmIncluded())
746 if (!method_exists(
'\Bitrix\Crm\Config\State',
'getProductLimitState'))
751 return Crm\Config\State::getProductLimitState(
$iblockId);
759 private static function isCrmIncluded(): bool
761 if (self::$crmIncluded ===
null)
763 self::$crmIncluded = Loader::includeModule(
'crm');
766 return self::$crmIncluded;
775 private static function checkIblockId(
array $fields): bool
777 if (!isset(
$fields[
'IBLOCK_ID']))
786 if (!isset(self::$iblockList[
$iblockId]))
789 if (!ModuleManager::isModuleInstalled(
'bitrix24'))
793 if (
$iblockId !== self::getCrmCatalogId())
850 'MESSAGE_ID' =>
'CATALOG_STATE_ERR_PRODUCT_LIMIT_1'
867 private static function getProductLimitError(
array $limit): ?string
869 if (!isset($limit[
'COUNT']) || !isset($limit[
'LIMIT']) || !isset($limit[
'MESSAGE_ID']))
874 return Loc::getMessage(
875 $limit[
'MESSAGE_ID'],
877 '#COUNT#' => $limit[
'COUNT'],
878 '#LIMIT#' => $limit[
'LIMIT']
889 private static function setProductLimitError(
string $errorMessage): void
893 $error = new \CAdminException([
928 return \Bitrix\Catalog\Product\Store\CostPriceCalculator::getMethod() !==
'';
static getProductLimitHelpLink()
static getLandingProductLimit()
static isMultiStoresEnabled()
static checkInventoryManagementFeatureByCurrentMode()
static getLandingLimitVariable()
static isStoreBatchEnabled()
static isMultiPriceTypesEnabled()
static isCommonProductProcessingEnabled()
static isExceededStoreLimit()
static handlerBeforeIblockSectionUpdate(array &$fields)
static getProductLimitState(int $iblockId)
static isExternalCatalog()
static handlerAfterIblockElementUpdate(array &$fields)
static handlerAfterIblockSectionDelete(array $fields)
static isProductCardSliderEnabled()
static isUsedInventoryManagement()
static getCrmExceedingProductLimit()
static handlerAfterIblockSectionUpdate(array &$fields)
static isShowedStoreReserve()
static handlerAfterIblockElementAdd(array &$fields)
static handlerAfterIblockElementDelete(array $fields)
static getExceedingProductLimit(int $iblockId, ?int $sectionId=null)
static handlerBeforeIblockElementAdd(array &$fields)
static isProductBatchMethodSelected()
static isExceededPriceTypeLimit()
static isEnabledInventoryManagement()
static handlerBeforeIblockElementUpdate(array &$fields)
static isAllowedNewPriceType()
static setIsExternalCatalog(bool $isEnabled)
static handlerAfterIblockSectionAdd(array &$fields)
static isAllowedNewStore()
static get($moduleId, $name, $default="", $siteId=false)
static set($moduleId, $name, $value="", $siteId="")
static getList(array $parameters=array())
static getCount($filter=array(), array $cache=array())
static normalizeArrayValuesByInt(&$map, $sorted=true)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
while($arParentIBlockProperty=$dbParentIBlockProperty->Fetch()) $errorMessage