/** * @param Quote $quote * @param AccountUser|null $user * @param array|null $selectedOffers * @return Order */ public function convert(Quote $quote, AccountUser $user = null, array $selectedOffers = null) { $accountUser = $user ?: $quote->getAccountUser(); $account = $user ? $user->getAccount() : $quote->getAccount(); $order = new Order(); $order->setAccount($account)->setAccountUser($accountUser)->setOwner($quote->getOwner())->setOrganization($quote->getOrganization()); if (!$selectedOffers) { foreach ($quote->getQuoteProducts() as $quoteProduct) { /** @var QuoteProductOffer $productOffer */ $productOffer = $quoteProduct->getQuoteProductOffers()->first(); $order->addLineItem($this->createOrderLineItem($productOffer)); } } else { foreach ($selectedOffers as $selectedOffer) { /** @var QuoteProductOffer $offer */ $offer = $selectedOffer[self::FIELD_OFFER]; $order->addLineItem($this->createOrderLineItem($offer, (double) $selectedOffer[self::FIELD_QUANTITY])); } } $this->orderCurrencyHandler->setOrderCurrency($order); $this->fillSubtotals($order); return $order; }