1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
PriceCollection.php
См. документацию.
1
<?php
2
3
namespace
Bitrix\Catalog\v2\Price;
4
5
use Bitrix\Catalog\v2\BaseCollection;
6
15
class
PriceCollection
extends
BaseCollection
16
{
18
protected
$factory
;
19
20
public
function
__construct
(
PriceFactory
$factory
)
21
{
22
$this->factory =
$factory
;
23
}
24
25
public
function
findBasePrice(): ?
BasePrice
26
{
28
foreach
($this->
getIterator
() as $price)
29
{
30
if
($price->isPriceBase())
31
{
32
return
$price;
33
}
34
}
35
36
return
null
;
37
}
38
39
public
function
findByGroupId(
int
$groupId): ?BasePrice
40
{
42
foreach
($this->
getIterator
() as $price)
43
{
44
if
($price->getGroupId() === $groupId)
45
{
46
return
$price;
47
}
48
}
49
50
return
null
;
51
}
52
53
public
function
create
():
BasePrice
54
{
55
$price = $this->factory->createEntity();
56
57
$this->
add
($price);
58
59
return
$price;
60
}
61
66
public
function
setValues
(
array
$values): self
67
{
68
$preparedValues = $this->prepareValues($values);
69
70
foreach
($preparedValues as $id =>
$fields
)
71
{
72
$price = $this->findByGroupId($id);
73
74
if
($price ===
null
)
75
{
76
// ToDo make all collections with factory methods?
77
$price = $this->
create
()->setGroupId($id);
78
}
79
80
if
($price)
81
{
82
$price->setPrice(
$fields
[
'PRICE'
] ??
null
);
83
84
if
(isset(
$fields
[
'CURRENCY'
]))
85
{
86
$price->setCurrency(
$fields
[
'CURRENCY'
]);
87
}
88
}
89
}
90
91
return
$this;
92
}
93
94
public
function
getValues():
array
95
{
96
$values = [];
97
99
foreach
($this->
getIterator
() as $item)
100
{
101
if
($item->hasField(
'PRICE'
) && $item->hasField(
'CURRENCY'
))
102
{
103
$values[$item->getGroupId()] = [
104
'PRICE'
=> $item->getPrice(),
105
'CURRENCY'
=> $item->getCurrency(),
106
];
107
}
108
}
109
110
return
$values;
111
}
112
113
public
function
hasBasePrice
(): bool
114
{
115
$basePrice = $this->findBasePrice();
116
117
return
$basePrice && $basePrice->hasPrice();
118
}
119
120
public
function
hasAnyPrice
(): bool
121
{
122
return
!empty($this->getValues());
123
}
124
125
private
function
prepareValues(
array
$values):
array
126
{
127
// ToDo check required properties + QUANTITY_FROM etc
128
$prepared = [];
129
130
foreach
($values as $id =>
$fields
)
131
{
132
if
(!is_array(
$fields
))
133
{
134
if
(is_numeric(
$fields
) && is_finite(
$fields
))
135
{
136
$fields
= [
'PRICE'
=>
$fields
];
137
}
138
else
139
{
140
continue
;
141
}
142
}
143
144
$fields
= array_intersect_key(
$fields
, [
'PRICE'
=>
true
,
'CURRENCY'
=>
true
]);
145
if
(!empty(
$fields
))
146
{
147
if
(isset(
$fields
[
'PRICE'
]))
148
{
149
if
(is_numeric(
$fields
[
'PRICE'
]) && is_finite(
$fields
[
'PRICE'
]))
150
{
151
$fields
[
'PRICE'
] = (float)
$fields
[
'PRICE'
];
152
}
153
else
154
{
155
$fields
[
'PRICE'
] =
null
;
156
}
157
}
158
159
if
(isset(
$fields
[
'CURRENCY'
]) && !is_string(
$fields
[
'CURRENCY'
]))
160
{
161
unset(
$fields
[
'CURRENCY'
]);
162
}
163
}
164
165
if
(!empty(
$fields
))
166
{
167
if
(is_numeric($id))
168
{
169
$id = (int)$id;
170
$prepared[$id] =
$fields
;
171
}
172
elseif
($id ===
'BASE'
)
173
{
174
$basePrice = \CCatalogGroup::GetBaseGroup();
175
176
if
(!empty($basePrice[
'ID'
]))
177
{
178
$id = (int)$basePrice[
'ID'
];
179
$prepared[$id] =
$fields
;
180
}
181
}
182
}
183
}
184
185
return
$prepared;
186
}
187
}
Bitrix\Catalog\v2\BaseCollection
Определения
BaseCollection.php:17
Bitrix\Catalog\v2\BaseCollection\getIterator
getIterator()
Определения
BaseCollection.php:252
Bitrix\Catalog\v2\BaseCollection\add
add(BaseEntity ... $items)
Определения
BaseCollection.php:50
Bitrix\Catalog\v2\Price\BasePrice
Определения
BasePrice.php:18
Bitrix\Catalog\v2\Price\PriceCollection
Определения
PriceCollection.php:16
Bitrix\Catalog\v2\Price\PriceCollection\$factory
$factory
Определения
PriceCollection.php:18
Bitrix\Catalog\v2\Price\PriceCollection\create
create()
Определения
PriceCollection.php:53
Bitrix\Catalog\v2\Price\PriceCollection\hasBasePrice
hasBasePrice()
Определения
PriceCollection.php:113
Bitrix\Catalog\v2\Price\PriceCollection\__construct
__construct(PriceFactory $factory)
Определения
PriceCollection.php:20
Bitrix\Catalog\v2\Price\PriceCollection\hasAnyPrice
hasAnyPrice()
Определения
PriceCollection.php:120
Bitrix\Catalog\v2\Price\PriceCollection\setValues
setValues(array $values)
Определения
PriceCollection.php:66
Bitrix\Catalog\v2\Price\PriceFactory
Определения
PriceFactory.php:16
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
elseif
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения
prolog_main_admin.php:393
$fields
$fields
Определения
yandex_run.php:501
bitrix
modules
catalog
lib
v2
Price
PriceCollection.php
Создано системой
1.14.0