Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
VariationProvider.php
1<?php
2
4
10
12{
13 protected const ENTITY_ID = 'variation';
14
15 public function __construct(array $options = [])
16 {
17 parent::__construct();
18 if (Loader::includeModule('crm'))
19 {
20 $defaultIblockId = \Bitrix\Crm\Product\Catalog::getDefaultOfferId();
21 }
22 else
23 {
24 $defaultIblockId = 0;
25 }
26
27 if (isset($options['iblockId']) && (int)$options['iblockId'] > 0)
28 {
29 $iblockId = (int)$options['iblockId'];
30 }
31 else
32 {
33 $iblockId = $defaultIblockId;
34 }
35 $this->options['iblockId'] = $iblockId;
36 }
37
38 public function fillDialog(Dialog $dialog): void
39 {
40 $dialog->loadPreselectedItems();
41
42 if ($dialog->getItemCollection()->count() > 0)
43 {
44 foreach ($dialog->getItemCollection() as $item)
45 {
46 $dialog->addRecentItem($item);
47 }
48 }
49
50 $recentItems = $dialog->getRecentItems()->getEntityItems(self::ENTITY_ID);
54 $ids = [];
55 foreach ($recentItems as $recentItem)
56 {
57 $ids[] = $recentItem->getId();
58 }
59 $filter = [
60 'ID' => $ids,
61 ];
62
63 $offers = $this->getProducts([
64 'filter' => $filter,
65 ]);
66
67 foreach ($offers as $offer)
68 {
69 $dialog->addRecentItem($this->makeItem($offer));
70 }
71 }
72
73 protected function getProductsBySearchString(string $searchString = ''): array
74 {
75 if (trim($searchString) === '')
76 {
77 return [];
78 }
79
80 $filter = [
81 '*SEARCHABLE_CONTENT' => $searchString,
82 ];
83
84 return $this->getProducts([
85 'filter' => $filter,
86 'searchString' => $searchString,
87 ]);
88 }
89
90 public function getItems(array $ids): array
91 {
92 if (empty($ids))
93 {
94 return [];
95 }
96
97 $filter = [
98 'ID' => $ids,
99 ];
100
101 $offers = $this->getProducts([
102 'filter' => $filter,
103 ]);
104
105 $items = [];
106 foreach ($offers as $offer)
107 {
108 $items[] = $this->makeItem($offer);
109 }
110
111 return $items;
112 }
113
114 public function getSelectedItems(array $ids): array
115 {
116 return $this->getItems($ids);
117 }
118
119 protected function getProducts(array $parameters = []): array
120 {
121 $iblockInfo = $this->getIblockInfo();
122 if (!$iblockInfo)
123 {
124 return [];
125 }
126
127 $filter = $this->getDefaultFilter();
128 $filter['IBLOCK_ID'] = $iblockInfo->getSkuIblockId();
129
130 $additionalFilter = $parameters['filter'];
131
132 $filter = array_merge($filter, $additionalFilter);
133
134 $offers = $this->loadElements([
135 'filter' => $filter,
136 'limit' => self::PRODUCT_LIMIT,
137 ]);
138 $offers = $this->loadProperties($offers, $iblockInfo->getSkuIblockId(), $iblockInfo);
139
140 $offers = $this->loadPrices($offers);
141
142 if (isset($parameters['searchString']))
143 {
144 $offers = $this->loadBarcodes($offers, $parameters['searchString']);
145 }
146
147 return $offers;
148 }
149
150 protected function getIblockInfo(): ?IblockInfo
151 {
152 return ServiceContainer::getIblockInfo($this->getIblockId());
153 }
154
155 private function getDefaultFilter(): array
156 {
157 return [
158 'CHECK_PERMISSIONS' => 'Y',
159 'MIN_PERMISSION' => 'R',
160 'ACTIVE' => 'Y',
161 'ACTIVE_DATE' => 'Y',
162 ];
163 }
164}
loadProperties(array $elements, int $iblockId, IblockInfo $iblockInfo)
loadPreselectedItems($preselectedMode=true)
Definition dialog.php:389