25 public function findBasePrice(): ?
BasePrice
30 if ($price->isPriceBase())
39 public function findByGroupId(
int $groupId): ?BasePrice
44 if ($price->getGroupId() === $groupId)
55 $price = $this->factory->createEntity();
68 $preparedValues = $this->prepareValues($values);
70 foreach ($preparedValues as $id => $fields)
72 $price = $this->findByGroupId($id);
77 $price = $this->
create()->setGroupId($id);
82 $price->setPrice($fields[
'PRICE'] ??
null);
84 if (isset($fields[
'CURRENCY']))
86 $price->setCurrency($fields[
'CURRENCY']);
94 public function getValues(): array
101 if ($item->hasField(
'PRICE') && $item->hasField(
'CURRENCY'))
103 $values[$item->getGroupId()] = [
104 'PRICE' => $item->getPrice(),
105 'CURRENCY' => $item->getCurrency(),
115 $basePrice = $this->findBasePrice();
117 return $basePrice && $basePrice->hasPrice();
122 return !empty($this->getValues());
125 private function prepareValues(array $values): array
130 foreach ($values as $id => $fields)
132 if (!is_array($fields))
134 if (is_numeric($fields) && is_finite($fields))
136 $fields = [
'PRICE' => $fields];
144 $fields = array_intersect_key($fields, [
'PRICE' =>
true,
'CURRENCY' =>
true]);
147 if (isset($fields[
'PRICE']))
149 if (is_numeric($fields[
'PRICE']) && is_finite($fields[
'PRICE']))
151 $fields[
'PRICE'] = (float)$fields[
'PRICE'];
155 $fields[
'PRICE'] =
null;
159 if (isset($fields[
'CURRENCY']) && !is_string($fields[
'CURRENCY']))
161 unset($fields[
'CURRENCY']);
170 $prepared[$id] = $fields;
172 elseif ($id ===
'BASE')
174 $basePrice = \CCatalogGroup::GetBaseGroup();
176 if (!empty($basePrice[
'ID']))
178 $id = (int)$basePrice[
'ID'];
179 $prepared[$id] = $fields;