Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
pricefieldassembler.php
1<?php
2
4
8use CCurrencyLang;
9
11{
12 private bool $isCurrencyIncluded;
13
14 public function __construct(array $columnIds)
15 {
16 parent::__construct($columnIds);
17
18 $this->isCurrencyIncluded = Loader::includeModule('currency');
19 }
20
33 protected function getCurrencyColumnId(string $priceColumnId): ?string
34 {
35 $priceTypeId = PriceProvider::parsePriceTypeId($priceColumnId);
36 if (isset($priceTypeId))
37 {
38 return PriceProvider::getCurrencyPriceTypeId($priceTypeId);
39 }
40
41 return null;
42 }
43
44 final protected function prepareRow(array $row): array
45 {
46 if (empty($this->getColumnIds()))
47 {
48 return $row;
49 }
50
51 foreach ($this->getColumnIds() as $priceColumnId)
52 {
53 $currencyColumnId = $this->getCurrencyColumnId($priceColumnId);
54 if (isset($currencyColumnId))
55 {
56 $priceValue = $row['data'][$priceColumnId] ?? null;
57 $currencyValue = $row['data'][$currencyColumnId] ?? null;
58
59 if ($this->isCurrencyIncluded)
60 {
61 $row['columns'][$priceColumnId] = CCurrencyLang::CurrencyFormat(
62 $priceValue,
63 $currencyValue
64 );
65 }
66 else
67 {
68 $row['columns'][$priceColumnId] = $priceValue;
69 }
70
71 $row['data'][$priceColumnId] = [
72 'PRICE' => [
73 'NAME' => 'PRICE',
74 'VALUE' => $priceValue,
75 ],
76 'CURRENCY' => [
77 'NAME' => 'CURRENCY',
78 'VALUE' => $currencyValue,
79 ],
80 ];
81 }
82 }
83
84 return $row;
85 }
86}