Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
productrowassembler.php
1<?php
2
4
19
20Loader::requireModule('iblock');
21
26{
27 private bool $isUseCatalogTab = false;
28 private bool $isUseSkuSelector = false;
29
30 public function setUseCatalogTab(bool $value = true): void
31 {
32 $this->isUseCatalogTab = $value;
33 }
34
35 public function setUseSkuSelector(bool $value = true): void
36 {
37 $this->isUseSkuSelector = $value;
38 }
39
40 protected function prepareFieldAssemblers(): array
41 {
42 $result = parent::prepareFieldAssemblers();
43
44 if ($this->isUseSkuSelector)
45 {
46 $result[] = new ProductSelectorFieldAssembler(
47 'PRODUCT', $this->settings
48 );
49 }
50 else
51 {
52 $result[] = new ProductNameFieldAssembler(
53 ['PRODUCT'],
54 $this->settings->getUrlBuilder()
55 );
56 }
57
58 $result[] = new SectionNameFieldAssembler(
59 ['PRODUCT'],
60 $this->settings->getUrlBuilder()
61 );
62
63 $result[] = new MeasureFieldAssembler(['MEASURE']);
64
65 $result[] = new ProductTypeFieldAssembler(['TYPE']);
66
67 $result[] = new VatFieldAssembler(['VAT_ID']);
68
69 $result[] = new LockedFieldAssembler($this->settings);
70
71 $result[] = (new PriceFieldAssemblerFactory)->createForCatalogPrices();
72
73 $result[] = new PurchasingPriceFieldAssembler();
74
75 $result[] = new MorePhotoAssembler(
76 ['MORE_PHOTO'],
77 $this->settings
78 );
79
80 return $result;
81 }
82
83 private function getClearedProductFields(): array
84 {
85 $result = array_fill_keys(ProductTable::getProductTypes(false), []);
86
87 $baseClearSkuFields = [
88 'QUANTITY',
89 'QUANTITY_RESERVED',
90 'QUANTITY_TRACE',
91 'CAN_BUY_ZERO',
92 'PURCHASING_PRICE',
93 'PURCHASING_CURRENCY',
94 'MEASURE',
95 'VAT_INCLUDED',
96 'VAT_ID',
97 'WEIGHT',
98 'WIDTH',
99 'LENGTH',
100 'HEIGHT',
101 ];
102
103 if (!$this->isUseSkuSelector && !$this->isUseCatalogTab)
104 {
105 $result[ProductTable::TYPE_SKU] = $baseClearSkuFields;
106 }
107
108 if (!$this->isUseCatalogTab)
109 {
110 $result[ProductTable::TYPE_EMPTY_SKU] = $baseClearSkuFields;
111 }
112
113 $result[ProductTable::TYPE_SET] = [
114 'QUANTITY_RESERVED',
115 ];
116
117 $result[ProductTable::TYPE_SERVICE] = [
118 'QUANTITY',
119 'QUANTITY_RESERVED',
120 'QUANTITY_TRACE',
121 'CAN_BUY_ZERO',
122 'WEIGHT',
123 'WIDTH',
124 'LENGTH',
125 'HEIGHT',
126 ];
127
128 return $result;
129 }
130
131 private function clearProductFields(array $rowsList): array
132 {
133 $clearedFields = $this->getClearedProductFields();
134
135 foreach ($rowsList as $index => $rowItem)
136 {
137 $productType = (int)($rowList[$index]['data']['TYPE'] ?? 0);
138 if (isset($clearedFields[$productType]))
139 {
140 foreach ($clearedFields[$productType] as $fieldName)
141 {
142 if (isset($rowList[$index]['data'][$fieldName]))
143 {
144 $rowList[$index]['data'][$fieldName] = '';
145 }
146 }
147 }
148 }
149
150 return $rowsList;
151 }
152
153 public function prepareRows(array $rowsList): array
154 {
155 $rowsList = $this->clearProductFields($rowsList);
156
157 return parent::prepareRows($rowsList);
158 }
159}
static getProductTypes($descr=false)
Definition product.php:824