/** * {@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 getCurrentCartIdentifier() { if ($this->hasCurrentCart()) { return $this->currentCart->getId(); } return null; }
/** * {@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 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 visitCart(CartInterface $cart) { $totals = $cart->getTotals(); $totalGrossAmount = $this->cartTotalsCollector->collectTotalGrossAmount($cart); $totalNetAmount = $this->cartTotalsCollector->collectTotalNetAmount($cart); $totalTaxAmount = $this->cartTotalsCollector->collectTotalTaxAmount($cart); $totalQuantity = $this->cartTotalsCollector->collectTotalQuantity($cart); $totalQWeight = $this->cartTotalsCollector->collectTotalWeight($cart); $totals->setQuantity($totalQuantity); $totals->setWeight($totalQWeight); $totals->setGrossPrice($totalGrossAmount); $totals->setNetPrice($totalNetAmount); $totals->setTaxAmount($totalTaxAmount); }
/** * 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); } }
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); }
/** * Copies the client's contact details to cart * * @param ClientInterface $client * @param CartInterface $cart */ protected function copyContactDetails(ClientInterface $client, CartInterface $cart) { $cart->setContactDetails($client->getContactDetails()); }
/** * 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()); }); } }
/** * {@inheritdoc} */ public function collectTotalTaxAmount(CartInterface $cart, $targetCurrency = null) { $amount = 0; $cart->getProducts()->map(function (CartProductInterface $cartProduct) use(&$amount, &$targetCurrency) { $sellPrice = $cartProduct->getSellPrice(); $baseCurrency = $sellPrice->getCurrency(); $taxAmount = $sellPrice->getFinalTaxAmount(); $amount += $this->helper->convert($taxAmount, $baseCurrency, $targetCurrency, $cartProduct->getQuantity()); }); return $amount; }