public function testBuildWithoutUnit()
 {
     $sku = 'TEST';
     $qty = 3;
     $data = [ProductDataStorage::ENTITY_ITEMS_DATA_KEY => [[ProductDataStorage::PRODUCT_SKU_KEY => $sku, ProductDataStorage::PRODUCT_QUANTITY_KEY => $qty]]];
     $order = new Order();
     $product = $this->getProductEntity($sku);
     $this->assertMetadataCalled();
     $this->assertRequestGetCalled();
     $this->assertStorageCalled($data);
     $this->assertProductRepositoryCalled($product);
     /** @var \PHPUnit_Framework_MockObject_MockObject|FormBuilderInterface $builder */
     $builder = $this->getMock('Symfony\\Component\\Form\\FormBuilderInterface');
     $this->extension->buildForm($builder, ['data' => $order]);
     $this->assertEmpty($order->getLineItems());
 }
 /**
  * @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;
 }
 /**
  * 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
  * @param array $offers
  * @param int $customQuantity
  */
 protected function assertOrderLineItems(Order $order, array $offers, $customQuantity)
 {
     $this->assertCount(count($offers), $order->getLineItems());
     foreach ($order->getLineItems() as $orderLineItem) {
         /** @var QuoteProductOffer $selectedOffer */
         foreach ($offers as $selectedOffer) {
             $quoteProduct = $selectedOffer->getQuoteProduct();
             if ($quoteProduct->getProduct()->getId() === $orderLineItem->getProduct()->getId()) {
                 if ($selectedOffer->isAllowIncrements()) {
                     $this->assertEquals($customQuantity, $orderLineItem->getQuantity());
                 } else {
                     $this->assertEquals($selectedOffer->getQuantity(), $orderLineItem->getQuantity());
                 }
             }
         }
     }
 }