21 [$elementFields, $productFields, $priceFields] = $this->splitProductFields($fields);
23 if (!empty($elementFields))
25 $result = parent::saveElement($id, $elementFields);
28 if ($result->isSuccess())
33 $product = ServiceContainer::getProductRepository($this->
getIblockId())->getEntityById($id);
36 $product->setFields($productFields);
38 $sku = $product->getSkuCollection()->getFirst();
41 $sku->getPriceCollection()->setValues($priceFields);
44 $result = $product->save();
51 $sku = ServiceContainer::getSkuRepository($this->
getIblockId())->getEntityById($id);
54 $sku->setFields($productFields);
55 $sku->getPriceCollection()->setValues($priceFields);
57 $result = $sku->save();
70 private function splitProductFields(array $fields): array
76 $priceColumns = $this->getPriceColumns();
77 $productColumns = $this->getProductColumns();
79 foreach ($fields as $name => $value)
81 if (isset($productColumns[$name]))
83 if ($name ===
'PURCHASING_PRICE')
87 if (isset($value[
'PRICE'][
'VALUE']))
89 $productFields[
'PURCHASING_PRICE'] =
90 $value[
'PRICE'][
'VALUE'] ===
''
92 : $value[
'PRICE'][
'VALUE']
94 $productFields[
'PURCHASING_CURRENCY'] = $value[
'CURRENCY'][
'VALUE'] ??
null;
97 elseif ($value !==
'')
99 $productFields[$name] = (float)$value;
104 $productFields[$name] = $value;
107 elseif (isset($priceColumns[$name]))
109 $priceTypeId = PriceProvider::parsePriceTypeId($name);
110 if (isset($priceTypeId))
112 $priceFields[$priceTypeId] = [
113 'PRICE' => $value[
'PRICE'][
'VALUE'] ??
null,
114 'CURRENCY' => $value[
'CURRENCY'][
'VALUE'] ??
null,
120 $elementFields[$name] = $value;
124 return [$elementFields, $productFields, $priceFields];
130 private function getPriceColumns(): array
134 $availableColumnsIds = [];
137 $id = PriceProvider::getPriceTypeColumnId($type[
'ID']);
138 $availableColumnsIds[$id] =
true;
143 $id = $column->getId();
144 if (isset($availableColumnsIds[$id]))
156 private function getProductColumns(): array
160 $availableColumnsIds = array_fill_keys([
166 'PURCHASING_CURRENCY',
180 $id = $column->getId();
181 if (isset($availableColumnsIds[$id]))