Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
productprovider.php
1<?php
2
4
13use CCatalogMeasure;
14
16{
17 public function prepareColumns(): array
18 {
19 $useSkuSelector = $this->isSkuSelectorEnabled();
20
21 $result = [];
22
23 $result['TYPE'] = [
24 'type' => Grid\Column\Type::DROPDOWN,
25 'name' => Loc::getMessage('PRODUCT_COLUMN_PROVIDER_FIELD_TYPE'),
26 'title' => Loc::getMessage('PRODUCT_COLUMN_PROVIDER_FIELD_TITLE_TYPE'),
27 'necessary' => true,
28 'editable' => false,
29 'multiple' => false,
30 'select' => [
31 'TYPE',
32 'BUNDLE',
33 ],
34 'sort' => 'TYPE',
35 'align' => 'right',
36 ];
37
38 $result['AVAILABLE'] = [
39 'type' => Grid\Column\Type::CHECKBOX,
40 'name' => Loc::getMessage('PRODUCT_COLUMN_PROVIDER_FIELD_AVAILABLE'),
41 'title' => Loc::getMessage('PRODUCT_COLUMN_PROVIDER_FIELD_TITLE_AVAILABLE'),
42 'necessary' => true,
43 'editable' => false,
44 'multiple' => false,
45 'sort' => 'AVAILABLE',
46 'align' => 'center',
47 ];
48
49 if ($useSkuSelector)
50 {
51 $result['PRODUCT'] = [
52 'type' => Grid\Column\Type::CUSTOM,
53 'name' => Loc::getMessage('PRODUCT_COLUMN_PROVIDER_FIELD_PRODUCT'),
54 'title' => Loc::getMessage('PRODUCT_COLUMN_PROVIDER_FIELD_TITLE_PRODUCT'),
55 'necessary' => true,
56 'editable' => false,
57 'multiple' => false,
58 'select' => [],
59 'sort' => 'NAME',
60 'align' => 'left',
61 'width' => 420, // TODO: enable support
62 ];
63 }
64 else
65 {
66 $result['PRODUCT'] = [
67 'type' => Grid\Column\Type::TEXT,
68 'name' => Loc::getMessage('PRODUCT_COLUMN_PROVIDER_FIELD_PRODUCT'),
69 'title' => Loc::getMessage('PRODUCT_COLUMN_PROVIDER_FIELD_TITLE_PRODUCT'),
70 'editable' => new Grid\Column\Editable\Config('NAME'),
71 'sort' => 'NAME',
72 ];
73 }
74
75 $result = array_merge(
76 $result,
81 );
82
83 return $this->createColumns($result);
84 }
85
86 public static function allowedShowQuantityColumns(): bool
87 {
88 if (!Loader::includeModule('crm'))
89 {
90 return true;
91 }
92
93 if (!Catalog\Config\State::isUsedInventoryManagement())
94 {
95 return true;
96 }
97 $allowedStores = Catalog\Access\AccessController::getCurrent()->getPermissionValue(
99 );
100 if (!empty($allowedStores))
101 {
102 return true;
103 }
104
105 return false;
106 }
107
113 public static function needSummaryStoreAmountByPermissions(): bool
114 {
115 if (!Loader::includeModule('crm'))
116 {
117 return false;
118 }
119
120 if (!Catalog\Config\State::isUsedInventoryManagement())
121 {
122 return false;
123 }
124
125 $allowedStores = Access\AccessController::getCurrent()->getPermissionValue(
127 );
128 if (
129 is_array($allowedStores)
130 && in_array(Access\Permission\PermissionDictionary::VALUE_VARIATION_ALL, $allowedStores, true)
131 )
132 {
133 return false;
134 }
135
136 return true;
137 }
138
139 protected function getQuantityColumnsDescription(): array
140 {
141 $useSkuSelector = $this->isSkuSelectorEnabled();
142 $allowProductEdit = $this->allowProductEdit();
143 $useInventoryManagment = Catalog\Config\State::isUsedInventoryManagement();
144
145 $result = [];
146
147 if (static::allowedShowQuantityColumns())
148 {
149 $result['QUANTITY'] = [
150 'type' => Grid\Column\Type::FLOAT,
151 'name' => Loc::getMessage('PRODUCT_COLUMN_PROVIDER_FIELD_PRODUCT_QUANTITY'),
152 'necessary' => false,
153 'editable' => $allowProductEdit && !$useInventoryManagment,
154 'multiple' => false,
155 'sort' => $useSkuSelector || static::needSummaryStoreAmountByPermissions() ? null : 'QUANTITY',
156 'align' => 'right',
157 ];
158
159 $result['QUANTITY_RESERVED'] = [
160 'type' => Grid\Column\Type::FLOAT,
161 'name' => Loc::getMessage('PRODUCT_COLUMN_PROVIDER_FIELD_PRODUCT_QUANTITY_RESERVED'),
162 'necessary' => false,
163 'editable' => $allowProductEdit && !$useInventoryManagment,
164 'multiple' => false,
165 'sort' => null,
166 'align' => 'right',
167 ];
168 }
169
170 $result['MEASURE'] = [
171 'type' => Grid\Column\Type::DROPDOWN,
172 'name' => Loc::getMessage('PRODUCT_COLUMN_PROVIDER_FIELD_MEASURE'),
173 'title' => Loc::getMessage('PRODUCT_COLUMN_PROVIDER_FIELD_TITLE_MEASURE'),
174 'necessary' => false,
175 'editable' => $allowProductEdit ? $this->getMeasureEditable() : false,
176 'multiple' => false,
177 'sort' => $useSkuSelector ? null : 'MEASURE',
178 'align' => 'right',
179 ];
180
181 $result['QUANTITY_TRACE'] = [
182 'type' => Grid\Column\Type::CHECKBOX,
183 'name' => Loc::getMessage('PRODUCT_COLUMN_PROVIDER_FIELD_QUANTITY_TRACE'),
184 'title' => Loc::getMessage('PRODUCT_COLUMN_PROVIDER_FIELD_TITLE_QUANTITY_TRACE'),
185 'necessary' => false,
186 'editable' => $allowProductEdit,
187 'multiple' => false,
188 'sort' => null,
189 'align' => 'right',
190 ];
191
192 $result['CAN_BUY_ZERO'] = [
193 'type' => Grid\Column\Type::CHECKBOX,
194 'name' => Loc::getMessage('PRODUCT_COLUMN_PROVIDER_FIELD_CAN_BUY_ZERO'),
195 'title' => Loc::getMessage('PRODUCT_COLUMN_PROVIDER_FIELD_TITLE_CAN_BUY_ZERO'),
196 'necessary' => false,
197 'editable' => $allowProductEdit,
198 'multiple' => false,
199 'sort' => null,
200 'align' => 'right',
201 ];
202
203 return $result;
204 }
205
206 protected function getPhysicalColumsDescription(): array
207 {
208 $useSkuSelector = $this->isSkuSelectorEnabled();
209 $allowProductEdit = $this->allowProductEdit();
210
211 $result = [];
212
213 $result['WEIGHT'] = [
214 'type' => Grid\Column\Type::FLOAT,
215 'name' => Loc::getMessage('PRODUCT_COLUMN_PROVIDER_FIELD_WEIGHT'),
216 'necessary' => false,
217 'editable' => $allowProductEdit,
218 'multiple' => false,
219 'sort' => $useSkuSelector ? null : 'WEIGHT',
220 'align' => 'right',
221 ];
222
223 $result['WIDTH'] = [
224 'type' => Grid\Column\Type::FLOAT,
225 'name' => Loc::getMessage('PRODUCT_COLUMN_PROVIDER_FIELD_WIDTH'),
226 'necessary' => false,
227 'editable' => $allowProductEdit,
228 'multiple' => false,
229 'sort' => $useSkuSelector ? null : 'WIDTH',
230 'align' => 'right',
231 ];
232
233 $result['LENGTH'] = [
234 'type' => Grid\Column\Type::FLOAT,
235 'name' => Loc::getMessage('PRODUCT_COLUMN_PROVIDER_FIELD_LENGTH'),
236 'necessary' => false,
237 'editable' => $allowProductEdit,
238 'multiple' => false,
239 'sort' => $useSkuSelector ? null : 'LENGTH',
240 'align' => 'right',
241 ];
242
243 $result['HEIGHT'] = [
244 'type' => Grid\Column\Type::FLOAT,
245 'name' => Loc::getMessage('PRODUCT_COLUMN_PROVIDER_FIELD_HEIGHT'),
246 'necessary' => false,
247 'editable' => $allowProductEdit,
248 'multiple' => false,
249 'sort' => $useSkuSelector ? null : 'HEIGHT',
250 'align' => 'right',
251 ];
252
253 return $result;
254 }
255
256 protected function getVatColumnsDescription(): array
257 {
258 $allowProductEdit = $this->allowProductEdit();
259
260 $result = [];
261
262 $result['VAT_INCLUDED'] = [
263 'type' => Grid\Column\Type::CHECKBOX,
264 'name' => Loc::getMessage('PRODUCT_COLUMN_PROVIDER_FIELD_VAT_INCLUDED'),
265 'necessary' => false,
266 'editable' => $allowProductEdit,
267 'multiple' => false,
268 'sort' => null,
269 'align' => 'right',
270 ];
271
272 $result['VAT_ID'] = [
273 'type' => Grid\Column\Type::DROPDOWN,
274 'name' => Loc::getMessage('PRODUCT_COLUMN_PROVIDER_FIELD_VAT_ID'),
275 'necessary' => false,
276 'editable' => $allowProductEdit ? $this->getVatEditable() : false,
277 'multiple' => false,
278 'align' => 'right',
279 'partial' => true,
280 ];
281
282 return $result;
283 }
284
285 protected function getPurchasingPriceColumnDescription(): array
286 {
287 if (!$this->accessController->check(Access\ActionDictionary::ACTION_PRODUCT_PURCHASE_INFO_VIEW))
288 {
289 return [];
290 }
291
292 $result = [];
293
294 $result['PURCHASING_PRICE'] = [
295 'type' => Grid\Column\Type::MONEY,
296 'name' => Loc::getMessage('PRODUCT_COLUMN_PROVIDER_FIELD_PURCHASING_PRICE'),
297 'necessary' => false,
298 'editable' => Catalog\Config\State::isUsedInventoryManagement() ? false : new MoneyConfig('PURCHASING_PRICE'),
299 'multiple' => false,
300 'select' => [
301 'PURCHASING_PRICE',
302 'PURCHASING_CURRENCY',
303 ],
304 'sort' => 'PURCHASING_PRICE',
305 'align' => 'right',
306 ];
307
308 return $result;
309 }
310
311 private function getMeasureEditable(): Grid\Column\Editable\ListConfig
312 {
313 $items = [];
314
315 $rows = CCatalogMeasure::getList();
316 while ($row = $rows->Fetch())
317 {
318 $items[$row['ID']] = $row['MEASURE_TITLE'];
319 }
320
321 return new ListConfig('MEASURE', $items);
322 }
323
324 private function getVatEditable(): Grid\Column\Editable\ListConfig
325 {
326 $items = [];
327
328 $rows = VatTable::getList([
329 'select' => [
330 'ID',
331 'NAME',
332 ],
333 'filter' => [
334 '=ACTIVE' => 'Y',
335 ],
336 'order' => [
337 'SORT' => 'ASC',
338 'ID' => 'ASC',
339 ],
340 ]);
341
342 if ($rows->getSelectedRowsCount() > 0)
343 {
344 $items['0'] = Loc::getMessage('PRODUCT_COLUMN_PROVIDER_FIELD_VAT_EDITABLE_ITEMS_NOT_SELECTED');
345 }
346
347 foreach ($rows as $row)
348 {
349 $id = $row['ID'];
350 $items[$id] = $row['NAME'];
351 }
352
353 return new ListConfig('VAT_ID', $items);
354 }
355}
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static getList(array $parameters=array())