Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
productinfo.php
1
<?php
2
3
namespace
Bitrix\Catalog\Integration\Report\StoreStock\Entity
;
4
5
use
Bitrix\Catalog\ProductTable
;
6
use
Bitrix\Currency\CurrencyManager
;
7
use
Bitrix\Currency\CurrencyTable
;
8
use
Bitrix\Main\ORM\Fields\Relations\Reference
;
9
use
Bitrix\Main\ORM\Query\Join
;
10
11
final
class
ProductInfo
12
{
13
private
static
array $productNameList = [];
14
15
private
int
$productId;
16
private
float
$quantity;
17
private
static
array $productPrice;
18
19
public
function
__construct
(
int
$productId,
float
$quantity)
20
{
21
$this->productId = $productId;
22
$this->quantity = $quantity;
23
}
24
25
public
function
getProductId
(): int
26
{
27
return
$this->productId;
28
}
29
30
public
function
getQuantity
(): float
31
{
32
return
$this->quantity;
33
}
34
41
public
function
getPrice
(): float
42
{
43
if
(!isset(self::$productPrice[$this->productId]))
44
{
45
self::initBasePrice
($this->productId);
46
}
47
48
if
(!isset(self::$productPrice[$this->productId]))
49
{
50
self::$productPrice[$this->productId] = 0.0;
51
}
52
53
return
self::$productPrice[$this->productId];
54
}
55
64
public
static
function
initBasePrice
(
int
...$productId): void
65
{
66
$defaultCurrency = CurrencyManager::getBaseCurrency();
67
$productsData =
ProductTable::getList
([
68
'select'
=> [
69
'ID'
,
70
'PURCHASING_PRICE'
,
71
'PURCHASING_CURRENCY'
,
72
'PURCHASING_CURRENCY_AMOUNT'
=>
'CURRENCY_TABLE.CURRENT_BASE_RATE'
,
73
],
74
'filter'
=> [
75
'=ID'
=> $productId,
76
],
77
'runtime'
=> [
78
(
new
Reference
(
79
'CURRENCY_TABLE'
,
80
CurrencyTable::class,
81
Join::on(
'this.PURCHASING_CURRENCY'
,
'ref.CURRENCY'
)
82
))->configureJoinType(Join::TYPE_LEFT),
83
],
84
])->fetchAll();
85
86
foreach
($productsData as $product)
87
{
88
$productPrice = (float)$product[
'PURCHASING_PRICE'
];
89
if
($product[
'PURCHASING_CURRENCY'
] !== $defaultCurrency)
90
{
91
$defaultCurrencyAmount = (float)\CCurrency::getCurrency($defaultCurrency)[
'CURRENT_BASE_RATE'
];
92
$currentCurrencyAmount = (float)$product[
'PURCHASING_CURRENCY_AMOUNT'
];
93
94
$productPrice *= $currentCurrencyAmount;
95
$productPrice /= $defaultCurrencyAmount;
96
}
97
98
self::setPrice
($product[
'ID'
], $productPrice);
99
}
100
}
101
109
public
static
function
setPrice
(
int
$productId,
float
$productPrice): void
110
{
111
self::$productPrice[$productId] = $productPrice;
112
}
113
}
Bitrix\Catalog\Integration\Report\StoreStock\Entity\ProductInfo
Definition
productinfo.php:12
Bitrix\Catalog\Integration\Report\StoreStock\Entity\ProductInfo\getPrice
getPrice()
Definition
productinfo.php:41
Bitrix\Catalog\Integration\Report\StoreStock\Entity\ProductInfo\getProductId
getProductId()
Definition
productinfo.php:25
Bitrix\Catalog\Integration\Report\StoreStock\Entity\ProductInfo\setPrice
static setPrice(int $productId, float $productPrice)
Definition
productinfo.php:109
Bitrix\Catalog\Integration\Report\StoreStock\Entity\ProductInfo\initBasePrice
static initBasePrice(int ... $productId)
Definition
productinfo.php:64
Bitrix\Catalog\Integration\Report\StoreStock\Entity\ProductInfo\getQuantity
getQuantity()
Definition
productinfo.php:30
Bitrix\Catalog\Integration\Report\StoreStock\Entity\ProductInfo\__construct
__construct(int $productId, float $quantity)
Definition
productinfo.php:19
Bitrix\Catalog\ProductTable
Definition
product.php:63
Bitrix\Currency\CurrencyManager
Definition
currencymanager.php:15
Bitrix\Currency\CurrencyTable
Definition
currency.php:47
Bitrix\Main\ORM\Data\DataManager\getList
static getList(array $parameters=array())
Definition
datamanager.php:441
Bitrix\Main\ORM\Fields\Relations\Reference
Definition
reference.php:26
Bitrix\Main\ORM\Query\Join
Definition
join.php:19
Bitrix\Catalog\Integration\Report\StoreStock\Entity
Definition
productinfo.php:3
modules
catalog
lib
integration
report
storestock
entity
productinfo.php
Создано системой
1.10.0