/**
  * {@inheritdoc}
  *
  * @param Entity\QuoteProductOffer $quoteProductOffer
  * @param Constraints\QuoteProductOffer $constraint
  */
 public function validate($quoteProductOffer, Constraint $constraint)
 {
     if (!$quoteProductOffer instanceof Entity\QuoteProductOffer) {
         throw new UnexpectedTypeException($quoteProductOffer, 'OroB2B\\Bundle\\SaleBundle\\Entity\\QuoteProductOffer');
     }
     if (null === ($quoteProduct = $quoteProductOffer->getQuoteProduct())) {
         $this->addViolation($constraint);
         return;
     }
     if ($quoteProduct->isTypeNotAvailable()) {
         $product = $quoteProduct->getProductReplacement();
     } else {
         $product = $quoteProduct->getProduct();
     }
     if (null === $product) {
         $this->addViolation($constraint);
         return;
     }
     if ([] === ($allowedUnits = $product->getAvailableUnitCodes())) {
         $this->addViolation($constraint);
         return;
     }
     if (null === ($productUnit = $quoteProductOffer->getProductUnit())) {
         $this->addViolation($constraint);
         return;
     }
     if (!in_array($productUnit->getCode(), $allowedUnits, true)) {
         $this->addViolation($constraint);
         return;
     }
 }
 public function testAddQuoteProductOffer()
 {
     $quoteProduct = new QuoteProduct();
     $quoteProductOffer = new QuoteProductOffer();
     $this->assertNull($quoteProductOffer->getQuoteProduct());
     $quoteProduct->addQuoteProductOffer($quoteProductOffer);
     $this->assertEquals($quoteProduct, $quoteProductOffer->getQuoteProduct());
 }
 /**
  * @param QuoteProductOffer $quoteProductOffer
  * @param float|null $quantity
  * @return OrderLineItem
  */
 protected function createOrderLineItem(QuoteProductOffer $quoteProductOffer, $quantity = null)
 {
     $quoteProduct = $quoteProductOffer->getQuoteProduct();
     if ($quoteProduct->getProductReplacement()) {
         $product = $quoteProduct->getProductReplacement();
     } else {
         $product = $quoteProduct->getProduct();
     }
     $orderLineItem = new OrderLineItem();
     $orderLineItem->setProduct($product)->setProductUnit($quoteProductOffer->getProductUnit())->setQuantity($quantity ?: $quoteProductOffer->getQuantity())->setPriceType($quoteProductOffer->getPriceType())->setPrice($quoteProductOffer->getPrice())->setFromExternalSource(true);
     return $orderLineItem;
 }