public function getOrderModifier(OrderInterface $order, string $name) : OrderModifierInterface { if (false === $order->hasModifier($name)) { return $this->createOrderModifier($order, $name); } return $order->getModifier($name); }
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; }
/** * {@inheritdoc} */ public function visitOrder(OrderInterface $order) { $orderProductTotal = $order->getProductTotal(); $orderTotalDetail = $this->initResource(); $orderTotalDetail->setOrderTotal($orderProductTotal); $orderTotalDetail->setOrder($order); $order->addTotal($orderTotalDetail); }
private function setInitialPayment(OrderInterface $order) { $payments = $order->getPayments(); if (0 === $payments->count()) { $payment = $this->paymentManager->createPaymentForOrder($order); $order->addPayment($payment); } }
public function visitOrder(OrderInterface $order) { $order->getProducts()->map(function (OrderProductInterface $orderProduct) { $this->refreshOrderProductSellPrice($orderProduct); $this->refreshOrderProductBuyPrice($orderProduct); $this->refreshOrderProductVariantOptions($orderProduct); }); }
/** * Adds shipping options if available for order's shipping method * * @param OrderInterface $order * @param FormInterface $form */ private function addShippingOptions(OrderInterface $order, FormInterface $form) { if ($order->hasShippingMethod()) { $provider = $this->getOptionsProvider($order->getShippingMethod()); if ($provider instanceof ShippingMethodOptionsProviderInterface) { $form->addChild($this->getElement('select', ['name' => 'shippingMethodOption', 'label' => $this->trans('order.label.shipping_method'), 'options' => ['Wybierz sklep', 'Kraków', 'Warszawa']])); } } }
protected function removeTotals(OrderInterface $order) { $em = $this->getDoctrineHelper()->getEntityManager(); $totals = $order->getTotals(); $totals->map(function (OrderTotalDetailInterface $total) use($em) { $em->remove($total); }); $em->flush(); }
public function createPaymentForOrder(OrderInterface $order) : PaymentInterface { $processor = $order->getPaymentMethod()->getProcessor(); /** @var PaymentInterface $payment */ $payment = $this->initResource(); $payment->setOrder($order); $payment->setState(PaymentInterface::PAYMENT_STATE_CREATED); $payment->setProcessor($processor); $this->createResource($payment, false); return $payment; }
public function changeOrderProductQuantity(OrderProductInterface $orderProduct, OrderInterface $order, int $quantity) { if (false === $order->getProducts()->contains($orderProduct)) { throw new ChangeOrderProductQuantityException($orderProduct); } if ($quantity < 1) { $this->deleteOrderProduct($orderProduct, $order); } else { $orderProduct->setQuantity($quantity); } $this->updateResource($order); }
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 (false === $order->hasShippingMethod()) { $order->setPaymentMethod(null); return; } $shippingMethod = $order->getShippingMethod(); $paymentMethods = $shippingMethod->getPaymentMethods(); if (false === $order->hasPaymentMethod() || false === $paymentMethods->contains($order->getPaymentMethod())) { $order->setPaymentMethod($paymentMethods->first()); } }
/** * {@inheritdoc} */ public function visitOrder(OrderInterface $order) { $shippingMethod = $order->getShippingMethod(); $paymentMethods = $shippingMethod->getPaymentMethods(); if (false === $order->hasPaymentMethod() || false === $paymentMethods->contains($order->getPaymentMethod())) { $order->setPaymentMethod($paymentMethods->first()); } $modifier = $this->orderModifierProvider->getOrderModifier($order, 'payment_surcharge'); $modifier->setCurrency($order->getCurrency()); $modifier->setGrossAmount(0); $modifier->setNetAmount(0); $modifier->setTaxAmount(0); }
/** * {@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); } } }
/** * @param OrderInterface $order * * @return \WellCommerce\Bundle\PaymentBundle\Processor\PaymentMethodProcessorInterface */ protected function getProcessor(OrderInterface $order) { $orderProcessor = $order->getPaymentMethod()->getProcessor(); $processors = $this->get('payment_method.processor.collection'); return $processors->get($orderProcessor); }
public function getCountry() : string { return $this->order->getShippingAddress()->getCountry(); }
/** * Creates an address object * * @param OrderInterface $order * * @return Address */ protected function createAddress(OrderInterface $order) : Address { $address = new Address(); $address->setLine1($order->getBillingAddress()->getLine1()); $address->setLine2($order->getBillingAddress()->getLine2()); $address->setCity($order->getBillingAddress()->getCity()); $address->setPostalCode($order->getBillingAddress()->getPostalCode()); $address->setCountryCode($order->getBillingAddress()->getCountry()); return $address; }
/** * @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; }
private function getPaymentForOrder(OrderInterface $order) : PaymentInterface { return $order->getPayments()->first(); }
/** * {@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; }
private function autoRegisterClient(OrderInterface $order) : ClientInterface { /** @var $client ClientInterface */ $client = $this->get('client.manager')->initResource(); $client->setClientDetails($order->getClientDetails()); $client->setContactDetails($order->getContactDetails()); $client->setBillingAddress($order->getBillingAddress()); $client->setShippingAddress($order->getShippingAddress()); $this->get('client.manager')->createResource($client); $token = new UsernamePasswordToken($client, $client->getPassword(), "client", $client->getRoles()); $this->container->get('security.token_storage')->setToken($token); $event = new InteractiveLoginEvent($this->getRequestHelper()->getCurrentRequest(), $token); $this->get("event_dispatcher")->dispatch('security.interactive_login', $event); return $client; }
public function setOrder(OrderInterface $order) { $this->order = $order; $order->addModifier($this); }
/** * 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); }
/** * {@inheritdoc} */ public function visitOrder(OrderInterface $order) { $currency = $order->getCurrency(); $currencyRate = $this->currencyConverter->getExchangeRate($currency); $order->setCurrencyRate($currencyRate); }
private function isOrderDirty(OrderInterface $order, string $currency, ClientInterface $client = null, string $sessionId) : bool { return $order->getClient() !== $client || $order->getCurrency() !== $currency || $order->getSessionId() !== $sessionId; }
/** * 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); }
public function getCurrency() : string { return $this->order->getCurrency(); }
/** * Returns the collection of costs for current shipping method * * @param OrderInterface $order * * @return Collection */ private function getCurrentShippingMethodCostsCollection(OrderInterface $order) : Collection { return $this->methodProvider->getShippingMethodCosts($order->getShippingMethod(), new OrderContext($order)); }