36 throw new \OutOfRangeException($id);
45 return reset($entities) ?:
null;
55 foreach ($this->
getList((array)$params) as $item)
69 if ($parent && !$parent->isNew())
71 $id = $parent->getId();
85 foreach ($entities as $entity)
87 if (!$entity->getProductId())
93 $entity->setProductId($productId);
97 $result->addError(
new Error(
'Wrong product id'));
102 if ($entityId = $entity->getId())
104 $res = $this->
updateInternal($entityId, $entity->getChangedFields());
106 if (!$res->isSuccess())
108 $result->addErrors($res->getErrors());
115 if ($res->isSuccess())
117 $entity->setId($res->getData()[
'ID']);
121 $result->addErrors($res->getErrors());
132 public function delete(BaseEntity ...$entities): Result
134 $result =
new Result();
137 foreach ($entities as $entity)
139 if ($entityId = $entity->getId())
143 if (!$res->isSuccess())
145 $result->addErrors($res->getErrors());
169 '=PRODUCT_ID' => $skuId,
175 protected function getList(array $params): array
177 $rows = Catalog\StoreBarcodeTable::getList($params)->fetchAll();
179 return array_column($rows,
null,
'ID');
184 $entity = $this->factory->createEntity();
193 $collection = $this->factory->createCollection();
195 foreach ($entityFields as $fields)
198 $collection->add($barcode);
208 $res = Catalog\StoreBarcodeTable::add($fields);
209 if ($res->isSuccess())
211 $result->setData([
'ID' => $res->getId()]);
215 $result->addErrors($res->getErrors());
225 $res = Catalog\StoreBarcodeTable::update($id, $fields);
227 if (!$res->isSuccess())
229 $result->addErrors($res->getErrors());
239 $res = Catalog\StoreBarcodeTable::delete($id);
241 if (!$res->isSuccess())
243 $result->addErrors($res->getErrors());