public function visitOrder(OrderInterface $order) { $productTotal = $order->getProductTotal(); $modifiers = $order->getModifiers(); $targetCurrency = $order->getCurrency(); /** @var OrderSummaryInterface $summary */ $summary = $this->factory->create(); $summary->setGrossAmount($productTotal->getGrossPrice()); $summary->setNetAmount($productTotal->getNetPrice()); $summary->setTaxAmount($productTotal->getTaxAmount()); $modifiers->map(function (OrderModifierInterface $modifier) use($summary, $targetCurrency) { $baseCurrency = $modifier->getCurrency(); $grossAmount = $this->helper->convert($modifier->getGrossAmount(), $baseCurrency, $targetCurrency); $netAmount = $this->helper->convert($modifier->getNetAmount(), $baseCurrency, $targetCurrency); $taxAmount = $this->helper->convert($modifier->getTaxAmount(), $baseCurrency, $targetCurrency); if ($modifier->isSubtraction()) { $summary->setGrossAmount($summary->getGrossAmount() - $grossAmount); $summary->setNetAmount($summary->getNetAmount() - $netAmount); $summary->setTaxAmount($summary->getTaxAmount() - $taxAmount); } else { $summary->setGrossAmount($summary->getGrossAmount() + $grossAmount); $summary->setNetAmount($summary->getNetAmount() + $netAmount); $summary->setTaxAmount($summary->getTaxAmount() + $taxAmount); } }); $order->setSummary($summary); }
/** * 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; }
protected function recalculateShippingTotal(OrderInterface $order) { $grossAmount = $order->getShippingTotal()->getGrossAmount(); $taxRate = $order->getShippingMethod()->getTax()->getValue(); $currency = $order->getCurrency(); $orderTotal = $this->orderTotalFactory->createFromSpecifiedValues($grossAmount, $taxRate, $currency); $order->setShippingTotal($orderTotal); }
/** * {@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); } } }
private function calculateCouponModifier(CouponInterface $coupon, OrderInterface $order) : float { $modifierType = $coupon->getModifierType(); $modifierValue = $coupon->getModifierValue(); $baseCurrency = $coupon->getCurrency(); $targetCurrency = $order->getCurrency(); $totalGrossPrice = $order->getProductTotal()->getGrossPrice(); if ('%' === $modifierType) { return $modifierValue / 100; } if ('-' === $modifierType) { $modifierValue = $this->currencyHelper->convert($modifierValue, $baseCurrency, $targetCurrency); return $modifierValue >= $totalGrossPrice ? 1 : $modifierValue / $totalGrossPrice; } return 1; }
/** * {@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); } } }
public function getCurrency() : string { return $this->order->getCurrency(); }
private function isOrderDirty(OrderInterface $order, string $currency, ClientInterface $client = null, string $sessionId) : bool { return $order->getClient() !== $client || $order->getCurrency() !== $currency || $order->getSessionId() !== $sessionId; }
/** * 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); }
/** * @param CartProductInterface $cartProduct * @param OrderInterface $order * * @return \WellCommerce\Bundle\OrderBundle\Entity\OrderProductInterface */ public function prepareOrderProduct(CartProductInterface $cartProduct, OrderInterface $order) { $orderProduct = $this->orderProductFactory->create(); $product = $cartProduct->getProduct(); $attribute = $cartProduct->getAttribute(); $sellPrice = $cartProduct->getSellPrice(); $baseCurrency = $sellPrice->getCurrency(); $targetCurrency = $order->getCurrency(); $grossAmount = $this->getCurrencyHelper()->convert($sellPrice->getFinalGrossAmount(), $baseCurrency, $targetCurrency); $netAmount = $this->getCurrencyHelper()->convert($sellPrice->getFinalNetAmount(), $baseCurrency, $targetCurrency); $taxAmount = $this->getCurrencyHelper()->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; }
/** * Prepares order shipping details * * @param OrderInterface $order * @param ShippingMethodCostInterface $shippingMethodCost */ protected function prepareShippingTotals(OrderInterface $order, ShippingMethodCostInterface $shippingMethodCost) { $cost = $shippingMethodCost->getCost(); $baseCurrency = $cost->getCurrency(); $shippingTotal = new OrderTotal(); $shippingTotal->setGrossAmount($this->currencyHelper->convert($cost->getGrossAmount(), $baseCurrency, $order->getCurrency())); $shippingTotal->setNetAmount($this->currencyHelper->convert($cost->getNetAmount(), $baseCurrency, $order->getCurrency())); $shippingTotal->setTaxAmount($this->currencyHelper->convert($cost->getTaxAmount(), $baseCurrency, $order->getCurrency())); $shippingTotal->setTaxRate($this->currencyHelper->convert($cost->getTaxRate())); $shippingTotal->setCurrency($order->getCurrency()); $order->setShippingTotal($shippingTotal); }
/** * {@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; }
private function calculateTaxAmount(OrderInterface $order) : float { $targetCurrency = $order->getCurrency(); $tax = 0; $order->getProducts()->map(function (OrderProductInterface $orderProduct) use(&$tax, $targetCurrency) { $sellPrice = $orderProduct->getSellPrice(); $baseCurrency = $sellPrice->getCurrency(); $taxAmount = $sellPrice->getTaxAmount(); $tax += $this->helper->convert($taxAmount, $baseCurrency, $targetCurrency, $orderProduct->getQuantity()); }); return $tax; }
/** * {@inheritdoc} */ public function visitOrder(OrderInterface $order) { $currency = $order->getCurrency(); $currencyRate = $this->currencyConverter->getExchangeRate($currency); $order->setCurrencyRate($currencyRate); }