예제 #1
0
 /**
  * {@inheritdoc}
  */
 public function getCurrentCartIdentifier()
 {
     if ($this->hasCurrentCart()) {
         return $this->currentCart->getId();
     }
     return null;
 }
 /**
  * {@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 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);
         }
     }
 }
예제 #5
0
 /**
  * {@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);
 }
 /**
  * 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());
 }
예제 #7
0
 /**
  * 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());
         });
     }
 }
예제 #8
0
 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);
 }
예제 #9
0
 /**
  * Adds all products to order
  *
  * @param CartInterface  $cart
  * @param OrderInterface $order
  */
 protected function prepareOrderProducts(CartInterface $cart, OrderInterface $order)
 {
     $cart->getProducts()->map(function (CartProductInterface $cartProduct) use($order) {
         $orderProduct = $this->orderProductFactory->createFromCartProduct($cartProduct);
         $orderProduct->setOrder($order);
         $order->addProduct($orderProduct);
     });
 }
예제 #10
0
 /**
  * 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);
     }
 }
예제 #11
0
 /**
  * {@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;
 }