Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
basefilter.php
1<?php
2
4
12
13abstract class BaseFilter extends Filter
14{
15 abstract protected static function getStoreFilterContext(): string;
16
17 abstract protected static function getProductFilterContext(): string;
18
19 public function getFilterParameters()
20 {
21 return [
22 'FILTER_ID' => $this->filterId,
23 'COMMON_PRESETS_ID' => $this->filterId . '_presets',
24 'FILTER' => static::getFieldsList(),
25 'DISABLE_SEARCH' => true,
26 'FILTER_PRESETS' => static::getPresetsList(),
27 'ENABLE_LABEL' => true,
28 'ENABLE_LIVE_SEARCH' => false,
29 'RESET_TO_DEFAULT_MODE' => false,
30 'VALUE_REQUIRED_MODE' => false,
31 ];
32 }
33
34 public static function getFieldsList()
35 {
36 $productsEntities = [];
37 if (Loader::includeModule('crm'))
38 {
39 $productsEntities[] = [
40 'id' => 'product_variation',
41 'options' => [
42 'iblockId' => \Bitrix\Crm\Product\Catalog::getDefaultId(),
43 'basePriceId' => Catalog\GroupTable::getBasePriceTypeId(),
44 'showPriceInCaption' => false,
45 ],
46 ];
47 }
48
49 return [
50 'STORES' => [
51 'id' => 'STORES',
52 'name' => Loc::getMessage('BASE_FILTER_STORES_TITLE'),
53 'type' => 'entity_selector',
54 'default' => true,
55 'partial' => true,
56 'params' => [
57 'multiple' => 'Y',
58 'dialogOptions' => [
59 'hideOnSelect' => false,
60 'context' => static::getStoreFilterContext(),
61 'entities' => [
62 [
63 'id' => 'store',
64 'dynamicLoad' => true,
65 'dynamicSearch' => true,
66 ]
67 ],
68 'dropdownMode' => true
69 ],
70 ],
71 ],
72 'PRODUCTS' => [
73 'id' => 'PRODUCTS',
74 'name' => Loc::getMessage('BASE_FILTER_PRODUCTS_TITLE'),
75 'type' => 'entity_selector',
76 'default' => true,
77 'partial' => true,
78 'params' => [
79 'multiple' => true,
80 'showDialogOnEmptyInput' => false,
81 'dialogOptions' => [
82 'hideOnSelect' => false,
83 'context' => static::getProductFilterContext(),
84 'entities' => $productsEntities,
85 'dropdownMode' => true,
86 'recentTabOptions' => [
87 'stub' => true,
88 'stubOptions' => [
89 'title' => Loc::getMessage('BASE_FILTER_DEFAULT_STORE_PRESET_TITLE'),
90 ],
91 ],
92 'events' => [
93 'onBeforeSearch' => 'onBeforeDialogSearch',
94 ]
95 ],
96 ],
97 ],
98 ];
99 }
100
101 public static function getPresetsList()
102 {
103 return [];
104 }
105
106 public static function prepareProductFilter(array $productIds): array
107 {
108 $preparedFilter = [];
109 $repositoryFacade = ServiceContainer::getRepositoryFacade();
110 if (!$repositoryFacade)
111 {
112 return $preparedFilter;
113 }
114
115 \Bitrix\Main\Type\Collection::normalizeArrayValuesByInt($productIds);
116
117 foreach ($productIds as $productId)
118 {
119 $product = $repositoryFacade->loadProduct($productId);
120 if (!$product)
121 {
122 $preparedFilter[] = $productId;
123 }
124 else
125 {
126 array_push($preparedFilter, ...self::getProductVariations($product));
127 }
128 }
129
130 return $preparedFilter;
131 }
132
133 private static function getProductVariations(BaseProduct $product): array
134 {
135 $variationIds = [];
136
137 foreach ($product->getSkuCollection() as $variation)
138 {
139 $variationIds[] = $variation->getId();
140 }
141
142 return $variationIds;
143 }
144}
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29