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);
 }
Exemplo n.º 2
0
 public function testSet()
 {
     $context = new PricingContext();
     $context->set('quantity', 3);
     $this->assertSame(3, $context->get('quantity'), 'the quantity that was set should be returned');
 }