/** * @param CartInterface $cart * * @return \WellCommerce\Bundle\OrderBundle\Entity\OrderInterface */ public function prepareOrderFromCart(CartInterface $cart) { $order = $this->initResource(); $order->setCurrency($cart->getCurrency()); $order->setPaymentMethod($cart->getPaymentMethod()); $order->setShippingMethod($cart->getShippingMethodCost()->getShippingMethod()); $order->setBillingAddress($cart->getBillingAddress()); $order->setShippingAddress($cart->getShippingAddress()); $order->setContactDetails($cart->getContactDetails()); $order->setShop($cart->getShop()); $order->setSessionId($cart->getSessionId()); $order->setClient($cart->getClient()); $order->setCurrentStatus($cart->getPaymentMethod()->getDefaultOrderStatus()); $order->setCoupon($cart->getCoupon()); $this->prepareOrderProducts($cart, $order); $this->prepareOrderShippingDetails($cart, $order); $this->eventDispatcher->dispatchOnPostOrderPrepared($order); return $order; }
/** * Prepares order product totals * * @param OrderInterface $order * @param ShippingMethodCostInterface $shippingMethodCost */ protected function prepareProductTotals(OrderInterface $order, CartInterface $cart) { $cartTotals = $cart->getTotals(); $baseCurrency = $cart->getCurrency(); $productTotal = new OrderTotal(); $productTotal->setGrossAmount($this->currencyHelper->convert($cartTotals->getGrossPrice(), $baseCurrency, $order->getCurrency())); $productTotal->setNetAmount($this->currencyHelper->convert($cartTotals->getNetPrice(), $baseCurrency, $order->getCurrency())); $productTotal->setTaxAmount($this->currencyHelper->convert($cartTotals->getTaxAmount(), $baseCurrency, $order->getCurrency())); $productTotal->setCurrency($order->getCurrency()); $order->setProductTotal($productTotal); }
/** * Updates client and/or currency if changed * * @param CartInterface $cart * @param ClientInterface|null $client * @param string $currency */ protected function updateCart(CartInterface $cart, ClientInterface $client = null, $currency) { $needsUpdate = false; if ($client !== $cart->getClient()) { $cart->setClient($client); $needsUpdate = true; } if ($currency !== $cart->getCurrency()) { $cart->setCurrency($currency); $needsUpdate = true; } if ($needsUpdate) { $this->updateResource($cart); } }