public function testSetProduct()
 {
     $product = new QuoteProduct();
     $this->assertNull($product->getProductSku());
     $product->setProduct((new Product())->setSku('test-sku'));
     $this->assertEquals('test-sku', $product->getProductSku());
 }
 /**
  * @param array $offers
  * @param array $productParams
  * @param array $suggestedProductParams
  * @return QuoteProduct
  */
 protected function createQuoteProduct(array $offers, array $productParams = [], array $suggestedProductParams = [])
 {
     $quoteProduct = new QuoteProduct();
     foreach ($offers as $offer) {
         $quoteProduct->addQuoteProductOffer($offer);
     }
     if ($productParams) {
         $product = new Product();
         $product->addUnitPrecision($this->createPrecision($productParams));
         $quoteProduct->setProduct($product);
     }
     if ($suggestedProductParams) {
         $suggestedProduct = new Product();
         $suggestedProduct->addUnitPrecision($this->createPrecision($suggestedProductParams));
         $quoteProduct->setProductReplacement($suggestedProduct);
     }
     return $quoteProduct;
 }
Example #3
0
 /**
  * @param ObjectManager $manager
  * @param Quote $quote
  * @param string $sku
  * @param array $items
  */
 protected function addQuoteProduct(ObjectManager $manager, Quote $quote, $sku, $items)
 {
     $product = new QuoteProduct();
     if ($this->hasReference($sku)) {
         $product->setProduct($this->getReference($sku));
     } else {
         $product->setProductSku($sku);
     }
     foreach ($items as $item) {
         $productOffer = new QuoteProductOffer();
         $productOffer->setQuantity($item['quantity'])->setPrice((new Price())->setValue($item['price'])->setCurrency($item['currency']));
         if ($this->hasReference($item['unit'])) {
             $productOffer->setProductUnit($this->getReference($item['unit']));
         } else {
             $productOffer->setProductUnitCode($item['unit']);
         }
         $manager->persist($productOffer);
         $product->addQuoteProductOffer($productOffer);
     }
     $manager->persist($product);
     $quote->addQuoteProduct($product);
 }
 /**
  * @param ObjectManager $manager
  * @param Quote $quote
  * @param string $sku
  * @param array $items
  */
 protected function addQuoteProduct(ObjectManager $manager, Quote $quote, $sku, $items)
 {
     $product = new QuoteProduct();
     if ($this->hasReference($sku)) {
         $product->setProduct($this->getReference($sku));
     } else {
         $product->setProductSku($sku);
     }
     foreach ($items as $index => $item) {
         $productOffer = new QuoteProductOffer();
         $productOffer->setAllowIncrements($item['allow_increments'])->setQuantity($item['quantity'])->setPriceType($item['priceType'])->setPrice((new Price())->setValue($item['price'])->setCurrency($item['currency']));
         if ($this->hasReference($item['unit'])) {
             $productOffer->setProductUnit($this->getReference($item['unit']));
         } else {
             $productOffer->setProductUnitCode($item['unit']);
         }
         $manager->persist($productOffer);
         // e.g sale.quote.1.product.1.offer.1
         $this->addReference($quote->getQid() . '.' . $sku . '.offer.' . ($index + 1), $productOffer);
         $product->addQuoteProductOffer($productOffer);
     }
     $manager->persist($product);
     $quote->addQuoteProduct($product);
 }
 /**
  * @param string $sku
  * @param bool $isReplacement
  * @return QuoteProduct
  */
 protected function createQuoteProduct($sku, $isReplacement = false)
 {
     $product = new Product();
     $product->setSku($sku);
     $quoteProduct = new QuoteProduct();
     if ($isReplacement) {
         $quoteProduct->setProductReplacement($product);
     } else {
         $quoteProduct->setProduct($product);
     }
     return $quoteProduct;
 }
 /**
  * "Success" form handler
  *
  * @param RFPRequest $entity
  * @return bool
  */
 protected function onSuccess(RFPRequest $entity)
 {
     $quote = new Quote();
     $quote->setRequest($entity)->setOwner($this->user)->setAccount($entity->getAccount())->setAccountUser($entity->getAccountUser())->setOrganization($this->user->getOrganization());
     foreach ($entity->getRequestProducts() as $requestProduct) {
         $quoteProduct = new QuoteProduct();
         $quoteProduct->setProduct($requestProduct->getProduct())->setType(QuoteProduct::TYPE_REQUESTED)->setCommentAccount($requestProduct->getComment());
         foreach ($requestProduct->getRequestProductItems() as $requestProductItem) {
             $quoteProductRequest = new QuoteProductRequest();
             $quoteProductRequest->setQuantity($requestProductItem->getQuantity())->setPrice($requestProductItem->getPrice())->setProductUnit($requestProductItem->getProductUnit())->setRequestProductItem($requestProductItem);
             $quoteProduct->addQuoteProductRequest($quoteProductRequest);
             $quoteProductOffer = new QuoteProductOffer();
             $quoteProductOffer->setQuantity($requestProductItem->getQuantity())->setProductUnit($requestProductItem->getProductUnit())->setPriceType(QuoteProductOffer::PRICE_TYPE_UNIT)->setAllowIncrements(true);
             $quoteProduct->addQuoteProductOffer($quoteProductOffer);
         }
         $quote->addQuoteProduct($quoteProduct);
     }
     try {
         $this->manager->persist($quote);
         $this->manager->flush();
         $this->quote = $quote;
     } catch (DBALException $e) {
         $this->exception = $e;
         return false;
     }
     return true;
 }
 /**
  * @param Product $product
  * @param int $type
  * @return QuoteProduct
  */
 protected function createQuoteProduct(Product $product, $type)
 {
     static $index = 0;
     $index++;
     $quoteProduct = new QuoteProduct();
     $quoteProduct->setProduct($product)->setType($type)->setComment(sprintf('Seller Notes %s', $index + 1))->setCommentAccount(sprintf('Account Notes %s', $index + 1));
     return $quoteProduct;
 }