public function determineOrderPrices(OrderInterface $order, PricingContextInterface $pricingContext = null)
 {
     // not implemented
     if ($pricingContext === null) {
         $pricingContext = new PricingContext();
     }
     foreach ($order->getItems() as $item) {
         $this->determineOrderItemPrices($item, $pricingContext);
     }
     // summing it up
     $itemsTotalNet = 0;
     // updating prices for each item
     foreach ($order->getItems() as $item) {
         // this is the total value since we want to capture any calculations that happen on a specific item
         $itemsTotalNet += $item->getPrice('netValue');
     }
     $order->setPrice('totalNet', $itemsTotalNet);
     $order->setPrice('totalValue', $itemsTotalNet);
     // if pricing context has taxation enabled we calculate the taxes with the percentage set
     // example taxRates : 0.10 for 10%, 0.25 for 25%
     if (isset($pricingContext['partner'])) {
         if ($partner = $pricingContext['partner']) {
             /** @var $partner \Vespolina\Entity\Partner\Partner */
             if (count($partner->getPreferredPaymentProfile())) {
                 /** @var $address \Vespolina\Entity\Partner\AddressInterface */
                 $paymentProfile = $partner->getPreferredPaymentProfile();
                 $rate = $this->taxProvider->getTaxByState($paymentProfile->getBillingState());
                 $totalTax = $itemsTotalNet * $rate;
                 $order->setPrice('taxRate', $rate);
                 $order->setPrice('taxes', $totalTax);
                 $order->setPrice('totalValue', $itemsTotalNet + $totalTax);
             }
         }
     }
 }
Example #2
0
 public function createOrderFromCart(OrderInterface $cart)
 {
     $order = $this->orderManager->createOrder();
     $order->setCustomer($cart->getCustomer());
     $order->setOrderDate(new \DateTime());
     $this->orderManager->setOrderState($order, 'unprocessed');
     // $order->setPrices($cart->getPrices());    //TODO: order pricing should be independent from a cart
     // Copy the (sales) channel if it is provided
     if (null != $cart->getChannel()) {
         $order->setChannel($cart->getChannel());
     }
     //$fulfillmentAgreement = $this->orderManager->createFulfillmentAgreement();
     //$paymentAgreement = $this->orderManager->createPaymentAgreement();
     //$order->setFulfillmentAgreement($fulfillmentAgreement);
     //$order->setPaymentAgreement($paymentAgreement);
     $items = $cart->getItems();
     if (null != $items) {
         foreach ($cart->getItems() as $cartItem) {
             $orderItem = $this->orderManager->addProductToOrder($order, $cartItem->getProduct());
             //$orderItem->setPricing($cartItem->getPricing());
             $this->orderManager->setItemQuantity($orderItem, $cartItem->getQuantity());
             $this->orderManager->setOrderItemState($orderItem, 'unprocessed');
         }
     }
     return $order;
 }
 public function determineOrderPrices(OrderInterface $order, PricingContextInterface $pricingContext = null)
 {
     // not implemented
     if ($pricingContext === null) {
         $pricingContext = new PricingContext();
     }
     if (!($orderPricingSet = $order->getPricing())) {
         $orderPricingSet = new PricingSet();
         $order->setPricing($orderPricingSet);
     }
     // preparing context
     if ($pricingContext->offsetExists('partner')) {
         $paymentProfile = $pricingContext['partner']->getPreferredPaymentProfile();
         $rate = $this->taxProvider->getTaxByState($paymentProfile->getBillingState());
         $pricingContext['taxRate'] = $rate;
         $orderPricingSet->set('taxRate', $rate);
     }
     // determining order pricing
     foreach ($order->getItems() as $item) {
         $this->determineOrderItemPrices($item, $pricingContext);
     }
     // summing it up
     $itemsTotalNet = 0;
     $itemsTotalValue = 0;
     $itemsTotalTax = 0;
     // updating prices for each item
     foreach ($order->getItems() as $item) {
         // this is the total value since we want to capture any calculations that happen on a specific item
         $itemsTotalNet += $item->getPricing()->get('netValue');
         $itemsTotalValue += $item->getPricing()->get('totalValue');
         $itemsTotalTax += $item->getPricing()->get('taxes');
     }
     $orderPricingSet->set('totalNet', $itemsTotalNet);
     $orderPricingSet->set('totalValue', $itemsTotalValue);
     $orderPricingSet->set('taxes', $itemsTotalTax);
     $orderPricingSet->setProcessingState(PricingSet::PROCESSING_FINISHED);
 }
Example #4
0
 public function clearOrder(OrderInterface $order)
 {
     $order->clearAttributes();
 }