public function testGetIdentifier()
 {
     $product = $this->getProduct(150);
     $productUnit = new ProductUnit();
     $productUnit->setCode('kg');
     $productUnitQuantity = new ProductUnitQuantity($product, $productUnit, 42);
     $this->assertEquals('150-kg-42', $productUnitQuantity->getIdentifier());
 }
 /**
  * @param ProductUnitQuantity $productUnitQuantity
  * @return array
  */
 protected function getRepositoryData(ProductUnitQuantity $productUnitQuantity)
 {
     $product = $productUnitQuantity->getProduct();
     $productUnit = $productUnitQuantity->getProductUnit();
     return [['id' => $product->getId(), 'code' => $productUnit->getCode(), 'quantity' => 1, 'value' => 20, 'currency' => 'EUR'], ['id' => $product->getId(), 'code' => $productUnit->getCode(), 'quantity' => 1.5, 'value' => 15, 'currency' => 'USD'], ['id' => $product->getId(), 'code' => $productUnit->getCode(), 'quantity' => 20, 'value' => 300, 'currency' => 'USD'], ['id' => $product->getId(), 'code' => $productUnit->getCode(), 'quantity' => 100, 'value' => 1400, 'currency' => 'USD']];
 }
 /**
  * @param Product $product
  * @param ProductUnit $productUnit
  * @param float $quantity
  * @param string $currency
  * @param PriceList $priceList
  * @return Price
  */
 protected function getPrice(Product $product, ProductUnit $productUnit, $quantity, $currency, PriceList $priceList)
 {
     $productUnitQuantity = new ProductUnitQuantity($product, $productUnit, $quantity);
     $identifier = $productUnitQuantity->getIdentifier();
     if (!isset($this->prices[$priceList->getId()][$currency][$identifier])) {
         $prices = $this->productPriceProvider->getMatchedPrices([$productUnitQuantity], $currency, $priceList);
         $this->prices[$priceList->getId()][$currency][$identifier] = $prices[$identifier];
     }
     $price = $this->prices[$priceList->getId()][$currency][$identifier];
     return $price ?: Price::create(mt_rand(10, 1000), $currency);
 }
 /**
  * @param FormEvent $event
  */
 public function updateLineItemPrices(FormEvent $event)
 {
     /** @var Order $order */
     $order = $event->getData();
     if ($order && $order->getLineItems()) {
         $productUnitQuantities = [];
         /** @var OrderLineItem[] $lineItemsWithIdentifier */
         $lineItemsWithIdentifier = [];
         foreach ($order->getLineItems() as $lineItem) {
             if (!$this->isValidForPriceUpdate($lineItem)) {
                 continue;
             }
             $productUnitQuantity = new ProductUnitQuantity($lineItem->getProduct(), $lineItem->getProductUnit(), $lineItem->getQuantity());
             $productUnitQuantities[] = $productUnitQuantity;
             $lineItemsWithIdentifier[$productUnitQuantity->getIdentifier()] = $lineItem;
         }
         $this->fillLineItemsPrice($order->getCurrency(), $productUnitQuantities, $lineItemsWithIdentifier);
     }
 }