/**
  * 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 removeTotals(OrderInterface $order)
 {
     $em = $this->getDoctrineHelper()->getEntityManager();
     $totals = $order->getTotals();
     $totals->map(function (OrderTotalDetailInterface $total) use($em) {
         $em->remove($total);
     });
     $em->flush();
 }