/**
  * Get order subtotal
  *
  * @param Order $order
  *
  * @return Subtotal
  */
 protected function getSubtotal(Order $order)
 {
     $subtotal = new Subtotal();
     $subtotal->setType(Subtotal::TYPE_SUBTOTAL);
     $translation = sprintf('orob2b.order.subtotals.%s', $subtotal->getType());
     $subtotal->setLabel($this->translator->trans($translation));
     $subtotalAmount = 0.0;
     foreach ($order->getLineItems() as $lineItem) {
         if (!$lineItem->getPrice()) {
             continue;
         }
         $rowTotal = $lineItem->getPrice()->getValue();
         if ($lineItem->getPriceType() === OrderLineItem::PRICE_TYPE_UNIT) {
             $rowTotal *= $lineItem->getQuantity();
         }
         if ($order->getCurrency() !== $lineItem->getPrice()->getCurrency()) {
             $rowTotal *= $this->getExchangeRate($lineItem->getPrice()->getCurrency(), $order->getCurrency());
         }
         $subtotalAmount += $rowTotal;
     }
     $subtotal->setAmount($subtotalAmount);
     $subtotal->setCurrency($order->getCurrency());
     return $subtotal;
 }
 /**
  * @param Order $order
  * @return array
  */
 protected function getMatchedPrices(Order $order)
 {
     $matchedPrices = [];
     $productUnitQuantities = $order->getLineItems()->filter(function (OrderLineItem $lineItem) {
         return $lineItem->getProduct() && $lineItem->getProductUnit() && $lineItem->getQuantity();
     })->map(function (OrderLineItem $lineItem) {
         return new ProductUnitQuantity($lineItem->getProduct(), $lineItem->getProductUnit(), $lineItem->getQuantity());
     });
     if ($productUnitQuantities) {
         $matchedPrices = $this->get('orob2b_pricing.provider.product_price')->getMatchedPrices($productUnitQuantities->toArray(), $order->getCurrency(), $this->getPriceList($order));
     }
     /** @var Price $price */
     foreach ($matchedPrices as &$price) {
         if ($price) {
             $price = ['value' => $price->getValue(), 'currency' => $price->getCurrency()];
         }
     }
     return $matchedPrices;
 }
 /**
  * @param Order $order
  */
 public function setOrderCurrency(Order $order)
 {
     if (!$order->getCurrency()) {
         $order->setCurrency($this->localeSettings->getCurrency());
     }
 }