33 throw new \OutOfRangeException($id);
42 return reset($entities) ?:
null;
49 foreach ($this->
getList((array)$params) as $item)
63 if ($parent && !$parent->isNew())
65 $id = $parent->getId();
76 foreach ($entities as $entity)
78 if (!$entity->getProductId())
84 $entity->setProductId($productId);
88 $result->addError(
new Error(
'Wrong product id'));
93 if ($entityId = $entity->getId())
95 $res = $this->
updateInternal($entityId, $entity->getChangedFields());
97 if (!$res->isSuccess())
99 $result->addErrors($res->getErrors());
106 if ($res->isSuccess())
108 $entity->setId($res->getData()[
'ID']);
112 $result->addErrors($res->getErrors());
120 public function delete(BaseEntity ...$entities): Result
122 $result =
new Result();
125 foreach ($entities as $entity)
127 if ($entityId = $entity->getId())
131 if (!$res->isSuccess())
133 $result->addErrors($res->getErrors());
157 '=PRODUCT_ID' => $skuId,
162 protected function getList(array $params): array
164 return MeasureRatioTable::getList($params)
171 $entity = $this->factory->createEntity();
180 $collection = $this->factory->createCollection();
182 foreach ($entityFields as $fields)
185 $collection->add($measureRatio);
195 $res = MeasureRatioTable::add($fields);
197 if ($res->isSuccess())
199 $result->setData([
'ID' => $res->getId()]);
203 $result->addErrors($res->getErrors());
213 $res = MeasureRatioTable::update($id, $fields);
215 if (!$res->isSuccess())
217 $result->addErrors($res->getErrors());
227 $res = MeasureRatioTable::delete($id);
229 if (!$res->isSuccess())
231 $result->addErrors($res->getErrors());