Пример #1
0
 /**
  * Calculates order's total values
  *
  * @param OrderInterface $order
  *
  * @return OrderTotal
  */
 protected function calculateOrderTotal(OrderInterface $order)
 {
     $totals = $order->getTotals();
     $targetCurrency = $order->getCurrency();
     $orderTotal = new OrderTotal();
     $grossTotal = 0;
     $netTotal = 0;
     $taxTotal = 0;
     $totals->map(function (OrderTotalDetailInterface $orderTotalDetail) use(&$grossTotal, &$netTotal, &$taxTotal, $targetCurrency) {
         $total = $orderTotalDetail->getOrderTotal();
         $baseCurrency = $total->getCurrency();
         $grossAmount = $this->currencyHelper->convert($total->getGrossAmount(), $baseCurrency, $targetCurrency);
         $netAmount = $this->currencyHelper->convert($total->getNetAmount(), $baseCurrency, $targetCurrency);
         $taxAmount = $this->currencyHelper->convert($total->getTaxAmount(), $baseCurrency, $targetCurrency);
         if ($orderTotalDetail->isSubtraction()) {
             $grossTotal -= $grossAmount;
             $netTotal -= $netAmount;
             $taxTotal -= $taxAmount;
         } else {
             $grossTotal += $grossAmount;
             $netTotal += $netAmount;
             $taxTotal += $taxAmount;
         }
     });
     $orderTotal->setCurrency($targetCurrency);
     $orderTotal->setGrossAmount($grossTotal);
     $orderTotal->setNetAmount($netTotal);
     $orderTotal->setTaxAmount($taxTotal);
     return $orderTotal;
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 public function createFromCartProduct(CartProductInterface $cartProduct, OrderInterface $order)
 {
     $orderProduct = new OrderProduct();
     $product = $cartProduct->getProduct();
     $attribute = $cartProduct->getAttribute();
     $sellPrice = $cartProduct->getSellPrice();
     $baseCurrency = $sellPrice->getCurrency();
     $targetCurrency = $order->getCurrency();
     $grossAmount = $this->currencyHelper->convert($sellPrice->getFinalGrossAmount(), $baseCurrency, $targetCurrency);
     $netAmount = $this->currencyHelper->convert($sellPrice->getFinalNetAmount(), $baseCurrency, $targetCurrency);
     $taxAmount = $this->currencyHelper->convert($sellPrice->getFinalTaxAmount(), $baseCurrency, $targetCurrency);
     $sellPrice = new Price();
     $sellPrice->setGrossAmount($grossAmount);
     $sellPrice->setNetAmount($netAmount);
     $sellPrice->setTaxAmount($taxAmount);
     $sellPrice->setTaxRate($sellPrice->getTaxRate());
     $sellPrice->setCurrency($targetCurrency);
     $orderProduct->setSellPrice($sellPrice);
     $orderProduct->setBuyPrice($product->getBuyPrice());
     $orderProduct->setQuantity($cartProduct->getQuantity());
     $orderProduct->setWeight($cartProduct->getWeight());
     $orderProduct->setProductAttribute($attribute);
     $orderProduct->setProduct($product);
     return $orderProduct;
 }
 /**
  * {@inheritdoc}
  */
 public function visitOrder(OrderInterface $order)
 {
     $orderTotalDetail = $this->initResource();
     $shippingTotal = $order->getShippingTotal();
     $orderTotalDetail->setOrderTotal($shippingTotal);
     $orderTotalDetail->setOrder($order);
     $order->addTotal($orderTotalDetail);
 }
Пример #4
0
 protected function removeTotals(OrderInterface $order)
 {
     $em = $this->getDoctrineHelper()->getEntityManager();
     $totals = $order->getTotals();
     $totals->map(function (OrderTotalDetailInterface $total) use($em) {
         $em->remove($total);
     });
     $em->flush();
 }
 /**
  * {@inheritdoc}
  */
 public function visitOrder(OrderInterface $order)
 {
     if (null !== $order->getCoupon()) {
         $productTotal = $order->getProductTotal();
         $coupon = $order->getCoupon();
         $modifier = $this->calculateModifierValue($coupon, $productTotal->getGrossAmount(), $order->getCurrency());
         if ($modifier > 0) {
             $orderTotal = new OrderTotal();
             $orderTotal->setCurrency($order->getCurrency());
             $orderTotal->setGrossAmount($productTotal->getGrossAmount() * $modifier);
             $orderTotal->setNetAmount($productTotal->getNetAmount() * $modifier);
             $orderTotal->setTaxAmount($productTotal->getTaxAmount() * $modifier);
             $orderTotalDetail = $this->initResource();
             $orderTotalDetail->setOrderTotal($orderTotal);
             $orderTotalDetail->setModifierType($coupon->getModifierType());
             $orderTotalDetail->setModifierValue($modifier);
             $orderTotalDetail->setOrder($order);
             $orderTotalDetail->setSubtraction(true);
             $order->addTotal($orderTotalDetail);
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function visitOrder(OrderInterface $order)
 {
     if (null === $order->getCoupon()) {
         $orderTotal = new OrderTotal();
         $discount = $this->getDiscountForClient($order->getClient());
         if ($discount > 0) {
             $productTotal = $order->getProductTotal();
             $orderTotal->setCurrency($order->getCurrency());
             $orderTotal->setGrossAmount($productTotal->getGrossAmount() * $discount);
             $orderTotal->setNetAmount($productTotal->getNetAmount() * $discount);
             $orderTotal->setTaxAmount($productTotal->getTaxAmount() * $discount);
             $orderTotalDetail = $this->initResource();
             $orderTotalDetail->setOrderTotal($orderTotal);
             $orderTotalDetail->setModifierType('%');
             $orderTotalDetail->setModifierValue($discount);
             $orderTotalDetail->setOrder($order);
             $orderTotalDetail->setSubtraction(true);
             $order->addTotal($orderTotalDetail);
         }
     }
 }
Пример #7
0
 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);
 }
 /**
  * {@inheritdoc}
  */
 public function calculateTotalTaxAmount(OrderInterface $order)
 {
     $amount = 0;
     $targetCurrency = $order->getCurrency();
     $order->getProducts()->map(function (OrderProductInterface $orderProduct) use(&$amount, $targetCurrency) {
         $sellPrice = $orderProduct->getSellPrice();
         $baseCurrency = $sellPrice->getCurrency();
         $taxAmount = $sellPrice->getTaxAmount();
         $amount += $this->currencyHelper->convert($taxAmount, $baseCurrency, $targetCurrency, $orderProduct->getQuantity());
     });
     return $amount;
 }
Пример #9
0
 /**
  * Converts the order's gross total to target currency
  *
  * @param OrderInterface $order
  *
  * @return float
  */
 protected function convertAmount(OrderInterface $order)
 {
     $amount = $order->getOrderTotal()->getGrossAmount();
     $baseCurrency = $order->getCurrency();
     return $this->getCurrencyHelper()->convert($amount, $baseCurrency);
 }
Пример #10
0
 /**
  * @param OrderInterface $order
  *
  * @return \WellCommerce\AppBundle\Processor\PaymentMethodProcessorInterface
  */
 protected function getProcessor(OrderInterface $order)
 {
     $orderProcessor = $order->getPaymentMethod()->getProcessor();
     $processors = $this->get('payment_method.processor.collection');
     return $processors->get($orderProcessor);
 }