Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
productandstoreinfo.php
1
<?php
2
3
namespace
Bitrix\Catalog\Document\Action
;
4
5
use
Bitrix\Catalog\ProductTable
;
6
use
Bitrix\Catalog\StoreProductTable
;
7
use
Bitrix\Catalog\StoreTable
;
8
use
Bitrix\Iblock\ElementTable
;
9
use
Bitrix\Main\Loader
;
10
14
trait 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
}
Bitrix\Catalog\ProductTable
Definition
product.php:63
Bitrix\Catalog\StoreProductTable
Definition
storeproduct.php:39
Bitrix\Catalog\StoreTable
Definition
store.php:55
Bitrix\Iblock\ElementTable
Definition
elementtable.php:79
Bitrix\Main\Loader
Definition
loader.php:12
Bitrix\Main\ORM\Data\DataManager\getRow
static getRow(array $parameters)
Definition
datamanager.php:410
Bitrix\Catalog\Document\Action
Bitrix\Catalog\Document\Action\getStoreId
getStoreId()
Definition
productandstoreinfo.php:31
Bitrix\Catalog\Document\Action\getProductTotalQuantity
getProductTotalQuantity()
Definition
productandstoreinfo.php:201
Bitrix\Catalog\Document\Action\getProductId
getProductId()
Definition
productandstoreinfo.php:41
Bitrix\Catalog\Document\Action\getProductRow
getProductRow()
Definition
productandstoreinfo.php:172
Bitrix\Catalog\Document\Action\getStoreReservedQuantity
getStoreReservedQuantity()
Definition
productandstoreinfo.php:129
Bitrix\Catalog\Document\Action\getStoreProductAmount
getStoreProductAmount()
Definition
productandstoreinfo.php:119
Bitrix\Catalog\Document\Action\getProductName
getProductName()
Definition
productandstoreinfo.php:139
Bitrix\Catalog\Document\Action\getStoreName
getStoreName()
Definition
productandstoreinfo.php:51
Bitrix\Catalog\Document\Action\getStoreProductRow
getStoreProductRow()
Definition
productandstoreinfo.php:88
Bitrix\Catalog\Document\Action\getProductTotalReservedQuantity
getProductTotalReservedQuantity()
Definition
productandstoreinfo.php:211
modules
catalog
lib
document
action
productandstoreinfo.php
Создано системой
1.10.0