24 $this->basketItem = $item;
50 return new $className;
59 public function create()
64 $reservedItemClassName = $registry->getReservedItemClassName();
66 $reservedItem = $reservedItemClassName::create($this);
67 $this->addItem($reservedItem);
79 public static function load(BasketItemBase
$basketItem) : self
94 $reservedItemClassName = $registry->getReservedItemClassName();
96 $reservedQuantityList = $reservedItemClassName::loadForBasketItem(
$basketItem->getId());
97 foreach ($reservedQuantityList as $item)
115 public function save()
117 $result =
new Result();
126 if ($basketItem->getId() > 0)
128 $itemsFromDbList = static::getList([
131 while ($item = $itemsFromDbList->fetch())
135 static::deleteInternal($item[
'ID']);
141 foreach ($this->collection as $entity)
143 $r = $entity->save();
144 if (!$r->isSuccess())
146 $result->addErrors($r->getErrors());
168 $dbRes = static::getList([
170 'filter' => [
'=BASKET_ID' => $basketId],
173 while ($entity = $dbRes->fetch())
175 $r = static::deleteInternal($entity[
'ID']);
176 if (!$r->isSuccess())
178 $result->addErrors($r->getErrors());
185 public function getQuantity() : float
190 foreach ($this->collection as $reservation)
192 $quantity += $reservation->getQuantity();
198 public function getQuantityByStoreId(
int $storeId) : float
203 foreach ($this->collection as $reservation)
205 if ($reservation->getStoreId() === $storeId)
207 $quantity += $reservation->getQuantity();
219 protected static function deleteInternal($primary)
222 $service = ServiceLocator::getInstance()->get(
'sale.basketReservation');
223 return $service->delete($primary);
233 public static function getList(array $parameters = [])
235 return Reservation\Internals\BasketReservationTable::getList($parameters);