/** * {@inheritdoc} */ public function visitCart(CartInterface $cart) { $paymentMethod = $cart->getPaymentMethod(); if (null !== $cart->getShippingMethodCost()) { $shippingMethod = $cart->getShippingMethodCost()->getShippingMethod(); $collection = $shippingMethod->getPaymentMethods(); if (null === $paymentMethod || !$collection->contains($paymentMethod)) { $defaultPaymentMethod = $shippingMethod->getPaymentMethods()->first(); $cart->setPaymentMethod($defaultPaymentMethod); } } }
/** * {@inheritdoc} */ public function collect(CartInterface $cart) { $totals = $cart->getTotals(); $totalGrossPrice = $totals->getGrossPrice(); $shippingCost = $this->collectShippingCost($cart->getShippingMethodCost()); return round($totalGrossPrice + $shippingCost, 2); }
/** * {@inheritdoc} */ public function visitCart(CartInterface $cart) { $cartShippingMethodCost = $cart->getShippingMethodCost(); if (null === $cartShippingMethodCost) { $shippingMethodCostCollection = $this->getShippingMethodCostCollection($cart); if ($shippingMethodCostCollection->count()) { $cart->setShippingMethodCost($shippingMethodCostCollection->first()); } } }
/** * {@inheritdoc} */ public function createOrderFromCart(CartInterface $cart) { $order = $this->create(); $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->prepareShippingTotals($order, $cart->getShippingMethodCost()); $this->prepareProductTotals($order, $cart); return $order; }
/** * Adds payment method options to select * * @param RadioGroup $radioGroup * @param CartInterface $cart */ protected function addPaymentOptions(RadioGroup $radioGroup, CartInterface $cart) { $shippingMethodCost = $cart->getShippingMethodCost(); if (null !== $shippingMethodCost) { $shippingMethod = $shippingMethodCost->getShippingMethod(); $collection = $shippingMethod->getPaymentMethods(); $collection->map(function (PaymentMethodInterface $paymentMethod) use($radioGroup) { $radioGroup->addOptionToSelect($paymentMethod->getId(), $paymentMethod->translate()->getName()); }); } }
protected function prepareOrderShippingDetails(CartInterface $cart, OrderInterface $order) { $cost = $cart->getShippingMethodCost()->getCost(); $grossAmount = $this->getCurrencyHelper()->convert($cost->getGrossAmount(), $cost->getCurrency(), $order->getCurrency()); $taxRate = $cost->getTaxRate(); $orderTotal = $this->orderTotalFactory->createFromSpecifiedValues($grossAmount, $taxRate, $order->getCurrency()); $order->setShippingTotal($orderTotal); }