Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
productgrid.php
1<?php
2
3namespace Bitrix\Catalog\Grid;
4
22
23Loader::requireModule('iblock');
24
29class ProductGrid extends Grid
30{
31 private bool $useFilter = false;
32 private ProductRightsChecker $rights;
33
34 public function __construct(ProductSettings $settings)
35 {
36 parent::__construct($settings);
37 }
38
39 public function setUseFilter(bool $value = true): self
40 {
41 $this->useFilter = $value;
42
43 return $this;
44 }
45
46 private function getProductRightsChecker(): ProductRightsChecker
47 {
48 $this->rights ??= new ProductRightsChecker($this->getIblockId());
49
50 return $this->rights;
51 }
52
53 private function getIblockId(): int
54 {
55 return $this->getSettings()->getIblockId();
56 }
57
58 public function getOrmFilter(): ?array
59 {
60 $result = parent::getOrmFilter();
61
62 if (isset($result))
63 {
64 $result['IBLOCK_ID'] = $this->getSettings()->getIblockId();
65 }
66
67 return $result;
68 }
69
70 public function prepareColumns(): array
71 {
72 $columns = parent::prepareColumns();
73
74 return $this->prepareSortingColumns($columns);
75 }
76
77 private function getBasePriceColumnId(): string
78 {
79 return PriceProvider::getPriceTypeColumnId(
81 );
82 }
83
84 private function prepareDefaultColumns(Columns $columns): void
85 {
86 $defaultColumns = array_fill_keys([
87 'PRODUCT',
88 'MORE_PHOTO',
89 'SECTIONS',
90 'QUANTITY',
91 'MEASURE',
92 $this->getBasePriceColumnId(),
93 ], true);
94
95 foreach ($columns as $column)
96 {
97 $id = $column->getId();
98 $column->setDefault(
99 isset($defaultColumns[$id])
100 );
101 }
102 }
103
109 private function prepareSortingColumns(array $columns): array
110 {
111 $map = [];
112 foreach ($columns as $column)
113 {
114 $map[$column->getId()] = $column;
115 }
116
117 $primaryColumns = [
118 'ID',
119 'ACTIVE',
120 'PRODUCT',
121 'MORE_PHOTO',
122 'QUANTITY',
123 'MEASURE',
124 $this->getBasePriceColumnId(),
125 'SHOW_COUNTER',
126 ];
127
128 $result = [];
129 foreach ($primaryColumns as $columnId)
130 {
131 if (isset($map[$columnId]))
132 {
133 $result[] = $map[$columnId];
134 unset($map[$columnId]);
135 }
136 }
137
138 array_push($result, ... array_values($map));
139
140 return $result;
141 }
142
143 #region creation methods
144
145 protected function createColumns(): Columns
146 {
147 $columns = (new ProductColumnsFactory)->create($this->getSettings());
148
149 $this->prepareDefaultColumns($columns);
150
151 return $columns;
152 }
153
154 protected function createRows(): Rows
155 {
156 $assembler = new ProductRowAssembler(
157 $this->getVisibleColumnsIds(),
158 $this->getSettings(),
159 $this->getColumns()
160 );
161
162 $assembler->setUseCatalogTab(
163 Option::get('catalog', 'show_catalog_tab_with_offers') === 'Y'
164 );
165 $assembler->setUseSkuSelector(
166 $this->getSettings()->isSkuSelectorEnabled()
167 );
168
169 return new Rows(
170 $assembler,
172 $this->getSettings(),
173 $this->getProductRightsChecker()
174 )
175 );
176 }
177
178 protected function createPanel(): ProductPanel
179 {
180 return new ProductPanel(
182 $this->getSettings(),
183 $this->getColumns(),
184 $this->getProductRightsChecker()
185 ),
186 );
187 }
188
189 protected function createFilter(): ?Filter
190 {
191 if (!$this->useFilter)
192 {
193 return null;
194 }
195
196 $settings = new \Bitrix\Catalog\Filter\DataProvider\Settings\ProductSettings([
197 'ID' => $this->getId(),
198 'IBLOCK_ID' => $this->getSettings()->getIblockId(),
199 'VARIATION_IBLOCK_ID' => $this->getSettings()->getOffersIblockId(),
200 'LINK_PROPERTY_ID' => $this->getSettings()->getSkuPropertyId(),
201 //'SHOW_SECTIONS' => true,
202 //'SHOW_XML_ID' => true,
203 ]);
204
205 return (new ProductFilterFactory)->createBySettings($settings);
206 }
207
208 #endregion creation methods
209}
__construct(ProductSettings $settings)
static getBasePriceTypeId()
Definition group.php:248