/** * {@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()); } } }
protected function prepareOrderShippingDetails(CartInterface $cart, OrderInterface $order) { $cost = $cart->getShippingMethodCost()->getCost(); $grossAmount = $this->currencyHelper->convert($cost->getGrossAmount(), $cost->getCurrency(), $order->getCurrency()); $taxRate = $cost->getTaxRate(); $orderTotal = $this->orderTotalFactory->createFromSpecifiedValues($grossAmount, $taxRate, $order->getCurrency()); $order->setShippingTotal($orderTotal); }
/** * 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()); }); } }