35 throw new \OutOfRangeException($id);
44 return reset($entities) ?:
null;
51 foreach ($this->
getList((array)$params) as $item)
65 if ($parent && !$parent->isNew())
67 $id = $parent->getId();
78 foreach ($entities as $entity)
80 if (!$entity->hasPrice())
82 if (!$entity->isNew())
86 if ($res->isSuccess())
88 $entity->setField(
'ID',
null);
92 $result->addErrors($res->getErrors());
99 if (!$entity->getProductId())
105 $entity->setProductId($productId);
109 $result->addError(
new Error(
'Wrong product id'));
114 if ($entityId = $entity->getId())
116 $res = $this->
updateInternal($entityId, $entity->getChangedFields());
118 if (!$res->isSuccess())
120 $result->addErrors($res->getErrors());
127 if ($res->isSuccess())
129 $entity->setId($res->getData()[
'ID']);
133 $result->addErrors($res->getErrors());
141 public function delete(BaseEntity ...$entities): Result
143 $result =
new Result();
146 foreach ($entities as $entity)
148 if ($entityId = $entity->getId())
152 if (!$res->isSuccess())
154 $result->addErrors($res->getErrors());
178 '=PRODUCT_ID' => $skuId,
183 protected function getList(array $params): array
187 return array_column($prices,
null,
'CATALOG_GROUP_ID');
192 $entity = $this->factory->createEntity();
201 $collection = $this->factory->createCollection();
203 foreach ($this->getPriceSettings() as $settings)
205 $fields = $entityFields[$settings[
'ID']]
207 'CATALOG_GROUP_ID' => $settings[
'ID'],
210 $price->setSettings($settings);
211 $collection->add($price);
232 if ($res->isSuccess())
234 $result->setData([
'ID' => $res->getId()]);
238 $result->addErrors($res->getErrors());
259 if (!$res->isSuccess())
261 $result->addErrors($res->getErrors());
273 if (!$res->isSuccess())
275 $result->addErrors($res->getErrors());
281 private function getPriceSettings(): array
283 static $priceSettings =
null;
285 if ($priceSettings ===
null)
290 return $priceSettings;
static getList(array $parameters=array())
static update($primary, array $data)