3namespace Bitrix\Sale\Services\Base;
5use Bitrix\Sale\BasketItem;
6use Bitrix\Sale\Delivery\Restrictions\Base;
7use \Bitrix\Main\Localization\Loc;
8use Bitrix\Sale\Internals\Entity;
10Loc::getMessage(__FILE__);
35 if (!\
Bitrix\
Main\Loader::includeModule(
'catalog'))
40 $basketItems = static::getBasketItems(
$entity);
45 foreach ($basketItems as $basketItem)
47 if ($basketItem->getField(
'MODULE') !=
'catalog')
52 $productId = (int)$basketItem->getField(
'PRODUCT_ID');
53 $productInfo = \CCatalogSKU::getProductInfo($productId);
55 $candidate = $productInfo[
'ID'] ?? $productId;
57 if (!in_array($candidate, $productIds))
59 $productIds[] = $candidate;
72 return Loc::getMessage(
'SALE_BASE_RESTRICTION_BY_CATEGORY');
77 return Loc::getMessage(
'SALE_BASE_RESTRICTION_BY_CATEGORY_ON_APPLY_ERROR_MSG');
88 public static function check($categoriesList,
array $restrictionParams, $deliveryId = 0) : bool
91 empty($categoriesList)
92 || !is_array($categoriesList)
93 || empty($restrictionParams[
"CATEGORIES"])
94 || !is_array($restrictionParams[
"CATEGORIES"])
100 foreach ($categoriesList as $productId => $productCategories)
102 if (!is_array($productCategories) || empty($productCategories))
107 $isProductFromCategory =
false;
109 foreach ($productCategories as $categoryId)
113 if (array_intersect($categoryPath, $restrictionParams[
"CATEGORIES"]))
115 $isProductFromCategory =
true;
120 if (!$isProductFromCategory)
136 if (!\
Bitrix\
Main\Loader::includeModule(
'iblock'))
143 $res = \CIBlockElement::GetElementGroups($productIds,
true, [
'ID',
'IBLOCK_ELEMENT_ID']);
145 while ($group =
$res->Fetch())
147 if (!is_array($groupsIds[$group[
'IBLOCK_ELEMENT_ID']]))
149 $groupsIds[$group[
'IBLOCK_ELEMENT_ID']] = [];
152 if (!in_array($group[
'ID'], $groupsIds[$group[
'IBLOCK_ELEMENT_ID']]))
154 $groupsIds[$group[
'IBLOCK_ELEMENT_ID']][] = $group[
'ID'];
168 if (!\
Bitrix\
Main\Loader::includeModule(
'iblock'))
175 $nav = \CIBlockSection::GetNavChain(
false, $categoryId, [
'ID'],
true);
176 foreach ($nav as $arSectionPath)
178 $result[] = $arSectionPath[
'ID'];
193 "TYPE" =>
"PRODUCT_CATEGORIES",
194 "ID" =>
'sale-admin-category-restriction',
195 "JS_HANDLER" => static::getJsHandler(),
196 "LABEL" => Loc::getMessage(
'SALE_BASE_RESTRICTION_BY_CATEGORY_LST_LABEL'),
static getCategoriesPath($categoryId)
static getBasketItems(Entity $entity)
static check($categoriesList, array $restrictionParams, $deliveryId=0)
static getCategoriesItems(array $productIds)
static getOnApplyErrorMessage()
static getParamsStructure($entityId=0)
static extractParams(Entity $entity)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)