Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
feature.php
1<?php
3
4use Bitrix\Bitrix24;
8
15final class Feature
16{
17 private const PRODUCT_SETS = 'catalog_product_sets';
18 private const MULTI_PRICE_TYPES = 'catalog_multi_price_types';
19 private const CUMULATIVE_DISCOUNTS = 'catalog_cumulative_discounts';
20 private const MULTI_WARENHOUSES = 'catalog_multi_warenhouses';
21 private const EXTENDED_PRICES = 'catalog_price_quantity_ranges';
22 private const INVENTORY_MANAGEMENT = 'catalog_inventory_management';
23 private const COMMON_PRODUCT_PROCESSING = 'catalog_common_product_processing';
24 private const PRODUCT_LIMIT = 'catalog_product_limit';
25 private const CATALOG_PERMISSIONS = 'catalog_permissions';
26 private const CATALOG_SERVICES = 'catalog_services';
27
28 private const LANDING_PRODUCT_LIMIT_VARIABLE = 'landing_product_limit';
29
31 private static ?bool $bitrix24Included = null;
32
34 private static array $tranferList = [
35 self::PRODUCT_SETS => 'CatCompleteSet',
36 self::MULTI_PRICE_TYPES => 'CatMultiPrice',
37 self::CUMULATIVE_DISCOUNTS => 'CatDiscountSave',
38 self::MULTI_WARENHOUSES => 'CatMultiStore'
39 ];
40
42 private static array $retailExist = [
43 self::PRODUCT_SETS => true,
44 self::MULTI_PRICE_TYPES => true,
45 self::CUMULATIVE_DISCOUNTS => true,
46 self::MULTI_WARENHOUSES => true
47 ];
48
50 private static array $bitrix24exist = [
51 self::PRODUCT_SETS => true,
52 self::EXTENDED_PRICES => true,
53 self::MULTI_PRICE_TYPES => true,
54 self::MULTI_WARENHOUSES => true,
55 self::INVENTORY_MANAGEMENT => true,
56 self::COMMON_PRODUCT_PROCESSING => true,
57 self::CATALOG_PERMISSIONS => true,
58 self::CATALOG_SERVICES => true,
59 ];
60
62 private static array $bitrix24helpCodes = [
63 self::PRODUCT_SETS => 'limit_shop_bundles',
64 self::MULTI_PRICE_TYPES => 'limit_shop_variable_prices',
65 self::EXTENDED_PRICES => 'limit_shop_variable_prices',
66 self::MULTI_WARENHOUSES => 'limit_shop_stocks',
67 self::INVENTORY_MANAGEMENT => 'limit_store_inventory_management',
68 self::PRODUCT_LIMIT => 'limit_shop_products',
69 self::CATALOG_PERMISSIONS => 'limit_crm_catalog_access_permissions',
70 self::CATALOG_SERVICES => 'limit_crm_catalog_services',
71 ];
72
73 private static int $helpCodesCounter = 0;
74 private static bool $initUi = false;
75
79 public static function getLandingProductLimit(): int
80 {
81 $result = 0;
82 if (self::isBitrix24())
83 {
84 $result = (int)Bitrix24\Feature::getVariable(self::LANDING_PRODUCT_LIMIT_VARIABLE);
85 }
86
87 return $result;
88 }
89
95 public static function isProductSetsEnabled(): bool
96 {
97 return self::isFeatureEnabled(self::PRODUCT_SETS);
98 }
99
105 public static function isPriceQuantityRangesEnabled(): bool
106 {
107 return self::isFeatureEnabled(self::EXTENDED_PRICES);
108 }
109
115 public static function isMultiPriceTypesEnabled(): bool
116 {
117 return self::isFeatureEnabled(self::MULTI_PRICE_TYPES);
118 }
119
125 public static function isCumulativeDiscountsEnabled(): bool
126 {
127 return self::isFeatureEnabled(self::CUMULATIVE_DISCOUNTS);
128 }
129
135 public static function isMultiStoresEnabled(): bool
136 {
137 return self::isFeatureEnabled(self::MULTI_WARENHOUSES);
138 }
139
145 public static function isInventoryManagementEnabled(): bool
146 {
147 return self::isFeatureEnabled(self::INVENTORY_MANAGEMENT);
148 }
149
155 public static function isCommonProductProcessingEnabled(): bool
156 {
157 if (!self::isBitrix24())
158 {
159 return Option::get('catalog', 'catalog_common_product_processing') === 'Y';
160 }
161
162 return self::isFeatureEnabled(self::COMMON_PRODUCT_PROCESSING);
163 }
164
170 public static function isAccessControllerCheckingEnabled(): bool
171 {
172 return self::isFeatureEnabled(self::CATALOG_PERMISSIONS);
173 }
174
180 public static function isCanUseYandexExport(): bool
181 {
182 $lang = LANGUAGE_ID;
183
184 if (self::isBitrix24())
185 {
186 $lang = \CBitrix24::getLicensePrefix();
187 }
188 elseif (Loader::includeModule('intranet'))
189 {
190 $lang = \CIntranetUtils::getPortalZone();
191 }
192 elseif (Option::get('main', 'vendor') === '1c_bitrix')
193 {
194 $lang = 'ru';
195 }
196
197 return in_array($lang, ['ru', 'by', 'kz'], true);
198 }
199
205 public static function isCatalogServicesEnabled(): bool
206 {
207 return self::isFeatureEnabled(self::CATALOG_SERVICES);
208 }
209
215 public static function isStoreBatchEnabled(): bool
216 {
218 }
219
220 public static function getLandingLimitVariable(): string
221 {
222 return self::LANDING_PRODUCT_LIMIT_VARIABLE;
223 }
224
230 public static function getProductSetsHelpLink(): ?array
231 {
232 return self::getHelpLink(self::PRODUCT_SETS);
233 }
234
240 public static function getPriceQuantityRangesHelpLink(): ?array
241 {
242 return self::getHelpLink(self::EXTENDED_PRICES);
243 }
244
250 public static function getMultiPriceTypesHelpLink(): ?array
251 {
252 return self::getHelpLink(self::MULTI_PRICE_TYPES);
253 }
254
260 public static function getMultiStoresHelpLink(): ?array
261 {
262 return self::getHelpLink(self::MULTI_WARENHOUSES);
263 }
264
270 public static function getInventoryManagementHelpLink(): ?array
271 {
272 return self::getHelpLink(self::INVENTORY_MANAGEMENT);
273 }
274
280 public static function getProductLimitHelpLink(): ?array
281 {
282 return self::getHelpLink(self::PRODUCT_LIMIT);
283 }
284
290 public static function getAccessControllerHelpLink(): ?array
291 {
292 return self::getHelpLink(self::CATALOG_PERMISSIONS);
293 }
294
300 public static function getCatalogServicesHelpLink(): ?array
301 {
302 return self::getHelpLink(self::CATALOG_SERVICES);
303 }
304
310 public static function initUiHelpScope(): void
311 {
312 if (!self::isBitrix24())
313 {
314 return;
315 }
316 if (self::$helpCodesCounter <= 0 || self::$initUi)
317 {
318 return;
319 }
320 if (Loader::includeModule('ui'))
321 {
322 self::$initUi = true;
323 Main\UI\Extension::load('ui.info-helper');
324 }
325 }
326
333 private static function isFeatureEnabled(string $featureId): bool
334 {
335 if ($featureId === '')
336 {
337 return false;
338 }
339
340 $result = true;
341 if (self::isBitrix24())
342 {
343 if (isset(self::$bitrix24exist[$featureId]))
344 {
345 $result = Bitrix24\Feature::isFeatureEnabled($featureId);
346 }
347 }
348 else
349 {
350 if (isset(self::$retailExist[$featureId]))
351 {
352 $result = \CBXFeatures::IsFeatureEnabled(self::$tranferList[$featureId]);
353 }
354 }
355
356 return $result;
357 }
358
365 private static function getHelpLink(string $featureId): ?array
366 {
367 if (!self::isBitrix24())
368 {
369 return null;
370 }
371 if (!isset(self::$bitrix24helpCodes[$featureId]))
372 {
373 return null;
374 }
375 self::$helpCodesCounter++;
376 return [
377 'TYPE' => 'ONCLICK',
378 'LINK' => 'top.BX.UI.InfoHelper.show(\''.self::$bitrix24helpCodes[$featureId].'\');',
379 'FEATURE_CODE' => self::$bitrix24helpCodes[$featureId],
380 ];
381 }
382
389 private static function isBitrix24(): bool
390 {
391 if (self::$bitrix24Included === null)
392 self::$bitrix24Included = Loader::includeModule('bitrix24');
393 return self::$bitrix24Included;
394 }
395}
static isAccessControllerCheckingEnabled()
Definition feature.php:170
static getPriceQuantityRangesHelpLink()
Definition feature.php:240
static getInventoryManagementHelpLink()
Definition feature.php:270
static isCommonProductProcessingEnabled()
Definition feature.php:155