/** * @param BasketItem $basketItem * @param Order $order * * @throws \RuntimeException */ private function basketItemToOrderItem(BasketItem $basketItem, Order $order) { $orderItem = new OrderItem(); $orderItem->price = $basketItem->priceAsFloat(); $orderItem->basketItem()->associate($basketItem); $productOption = $basketItem->productOption; if ($productOption instanceof ProductOptionPresenter) { $productOption = $productOption->getWrappedObject(); } $stockItem = $this->inventory->allocate($productOption); if (!$stockItem->isAvailable()) { throw new StockAllocationException(sprintf('Failed to allocate stock for product option `%s`.', $basketItem->productOption->id)); } $order->orderItems()->save($orderItem); $orderItem->stockItem()->save($stockItem); }