Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
productandstoreinfo.php
1<?php
2
4
10
14trait ProductAndStoreInfo
15{
19 private $productRow;
20
24 private $storeProductRow;
25
31 public function getStoreId(): ?int
32 {
33 return $this->storeId ?? null;
34 }
35
41 public function getProductId(): ?int
42 {
43 return $this->productId ?? null;
44 }
45
51 protected function getStoreName(): ?string
52 {
53 static $cache = [];
54
55 $storeId = $this->getStoreId();
56 if (!$storeId)
57 {
58 return '';
59 }
60
61 if (!array_key_exists($storeId, $cache))
62 {
63 $cache[$storeId] = null;
64
65 $row = StoreTable::getRow([
66 'select' => [
67 'TITLE',
68 'ADDRESS',
69 ],
70 'filter' => [
71 '=ID' => $storeId,
72 ],
73 ]);
74 if ($row)
75 {
76 $cache[$storeId] = (string)($row['TITLE'] ?: $row['ADDRESS']);
77 }
78 }
79
80 return $cache[$storeId];
81 }
82
88 protected function getStoreProductRow(): array
89 {
90 if (!isset($this->storeProductRow))
91 {
92 if ($this->getProductId() && $this->getStoreId())
93 {
94 $this->storeProductRow = StoreProductTable::getRow([
95 'select' => [
96 'AMOUNT',
97 'QUANTITY_RESERVED',
98 ],
99 'filter' => [
100 '=PRODUCT_ID' => $this->getProductId(),
101 '=STORE_ID' => $this->getStoreId(),
102 ],
103 ]) ?: [];
104 }
105 else
106 {
107 $this->storeProductRow = [];
108 }
109 }
110
111 return $this->storeProductRow;
112 }
113
119 protected function getStoreProductAmount(): float
120 {
121 return (float)($this->getStoreProductRow()['AMOUNT'] ?? 0.0);
122 }
123
129 protected function getStoreReservedQuantity(): float
130 {
131 return (float)($this->getStoreProductRow()['QUANTITY_RESERVED'] ?? 0.0);
132 }
133
139 protected function getProductName(): ?string
140 {
141 static $cache = [];
142
143 $productId = $this->getProductId();
144 if (!$productId)
145 {
146 return null;
147 }
148
149 if (!array_key_exists($productId, $cache))
150 {
151 Loader::includeModule('iblock');
152
153 $row = ElementTable::getRow([
154 'select' => [
155 'NAME',
156 ],
157 'filter' => [
158 '=ID' => $productId,
159 ],
160 ]);
161 $cache[$productId] = $row ? (string)$row['NAME'] : null;
162 }
163
164 return $cache[$productId];
165 }
166
172 protected function getProductRow(): ?array
173 {
174 if (!$this->productRow)
175 {
176 if ($this->getProductId())
177 {
178 $this->productRow = ProductTable::getRow([
179 'select' => [
180 'QUANTITY',
181 'QUANTITY_RESERVED',
182 ],
183 'filter' => [
184 '=ID' => $this->getProductId(),
185 ],
186 ]) ?: null;
187 }
188 else
189 {
190 $this->productRow = null;
191 }
192 }
193 return $this->productRow;
194 }
195
201 protected function getProductTotalQuantity(): float
202 {
203 return (float)($this->getProductRow()['QUANTITY'] ?? 0.0);
204 }
205
211 protected function getProductTotalReservedQuantity(): float
212 {
213 return (float)($this->getProductRow()['QUANTITY_RESERVED'] ?? 0.0);
214 }
215}
static getRow(array $parameters)