Example #1
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);
 }