Exemplo n.º 1
0
 public function testAddQuoteProduct()
 {
     $quote = new Quote();
     $quoteProduct = new QuoteProduct();
     $this->assertNull($quoteProduct->getQuote());
     $quote->addQuoteProduct($quoteProduct);
     $this->assertEquals($quote, $quoteProduct->getQuote());
 }
 /**
  * @param array $offers
  * @return QuoteProduct
  */
 protected function createQuoteProduct(array $offers = [])
 {
     $quoteProduct = new QuoteProduct();
     foreach ($offers as $offer) {
         list($unitCode, $quantity, $allowIncrements) = $offer;
         $offer = $this->createQuoteProductOffer($unitCode, $quantity, $allowIncrements);
         $quoteProduct->addQuoteProductOffer($offer);
         $offer->setQuoteProduct(null);
     }
     return $quoteProduct;
 }
 /**
  * @return array
  */
 public function submitDataProvider()
 {
     $firstUnitOffer = $this->createOffer(1, QuoteProductOffer::PRICE_TYPE_UNIT, 12, 'kg');
     $secondUnitOffer = $this->createOffer(2, QuoteProductOffer::PRICE_TYPE_UNIT, 16, 'kg');
     $thirdUnitOffer = $this->createOffer(3, QuoteProductOffer::PRICE_TYPE_UNIT, 17, 'kg', true);
     $bundledOffer = $this->createOffer(4, QuoteProductOffer::PRICE_TYPE_BUNDLED, 1000, 'item');
     $firstUnitQuoteProduct = new QuoteProduct();
     $firstUnitQuoteProduct->addQuoteProductOffer($firstUnitOffer);
     $secondUnitQuoteProduct = new QuoteProduct();
     $secondUnitQuoteProduct->addQuoteProductOffer($secondUnitOffer)->addQuoteProductOffer($thirdUnitOffer);
     $bundledQuoteProduct = new QuoteProduct();
     $bundledQuoteProduct->addQuoteProductOffer($bundledOffer);
     $unitAndBundledQuote = new Quote();
     $unitAndBundledQuote->addQuoteProduct($firstUnitQuoteProduct)->addQuoteProduct($secondUnitQuoteProduct)->addQuoteProduct($bundledQuoteProduct);
     return ['no products' => ['quote' => new Quote(), 'defaultData' => [], 'submit' => [], 'expectedData' => []], 'unit and bundled products' => ['quote' => $unitAndBundledQuote, 'defaultData' => [$firstUnitQuoteProduct, $secondUnitQuoteProduct, $bundledQuoteProduct], 'submit' => [[QuoteProductToOrderType::FIELD_QUANTITY => '12', QuoteProductToOrderType::FIELD_UNIT => 'kg'], [QuoteProductToOrderType::FIELD_QUANTITY => '16', QuoteProductToOrderType::FIELD_UNIT => 'kg'], [QuoteProductToOrderType::FIELD_QUANTITY => '1000', QuoteProductToOrderType::FIELD_UNIT => 'item']], 'expectedData' => [[QuoteProductToOrderType::FIELD_QUANTITY => 12, QuoteProductToOrderType::FIELD_OFFER => $firstUnitOffer], [QuoteProductToOrderType::FIELD_QUANTITY => 16, QuoteProductToOrderType::FIELD_OFFER => $secondUnitOffer], [QuoteProductToOrderType::FIELD_QUANTITY => 1000, QuoteProductToOrderType::FIELD_OFFER => $bundledOffer]]]];
 }
 /**
  * @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;
 }
 /**
  * @param string $type
  * @return string
  */
 public function formatType($type)
 {
     $types = QuoteProduct::getTypes();
     if (isset($types[$type])) {
         return $this->formatTypeLabel($types[$type]);
     } else {
         return $this->translator->trans('N/A');
     }
 }
 /**
  * @param float $quantity
  * @param string $unitCode
  * @return float
  */
 protected function roundQuantity($quantity, $unitCode)
 {
     $precision = 0;
     $product = $this->quoteProduct->getProductReplacement() ?: $this->quoteProduct->getProduct();
     if ($product) {
         $unitPrecision = $product->getUnitPrecision($unitCode);
         if ($unitPrecision) {
             $precision = $unitPrecision->getPrecision();
         }
     }
     return $this->roundingService->round($quantity, $precision);
 }
Exemplo n.º 7
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);
 }
Exemplo n.º 8
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 $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 QuoteProduct $quoteProduct
  * @param string $unitCode
  * @param float $quantity
  * @return QuoteProductOffer|null
  */
 public function match(QuoteProduct $quoteProduct, $unitCode, $quantity)
 {
     $expectedQuantity = (double) $quantity;
     $offers = $quoteProduct->getQuoteProductOffers()->filter(function (QuoteProductOffer $offer) use($unitCode) {
         return $offer->getProductUnitCode() === $unitCode;
     });
     $offers = $this->sortOfferByQuantity($offers->toArray());
     $result = null;
     /** @var QuoteProductOffer[] $offers */
     foreach ($offers as $offer) {
         $quantity = (double) $offer->getQuantity();
         $allowIncrements = $offer->isAllowIncrements();
         if ($quantity > $expectedQuantity) {
             break;
         }
         if ($allowIncrements) {
             $result = $offer;
         } elseif ($quantity === $expectedQuantity) {
             $result = $offer;
             break;
         }
     }
     return $result;
 }
 /**
  * @return array
  */
 public function formatTypeProvider()
 {
     $res = ['invalid type' => ['input' => 'asdf', 'expected' => 'N/A']];
     foreach (QuoteProduct::getTypes() as $key => $value) {
         $res[$value] = ['input' => $key, 'expected' => 'orob2b.sale.quoteproduct.type.' . $value];
     }
     return $res;
 }
 /**
  * @param Product $product
  * @param Product $replacement
  * @param int $type
  * @return QuoteProduct
  */
 protected function createQuoteProduct(Product $product = null, Product $replacement = null, $type = QuoteProduct::TYPE_OFFER)
 {
     $quoteProduct = new QuoteProduct();
     $quoteProduct->setType($type)->setProduct($product)->setProductReplacement($replacement);
     return $quoteProduct;
 }
Exemplo n.º 12
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->add('product', ProductSelectType::NAME, ['required' => true, 'label' => 'orob2b.product.entity_label', 'create_enabled' => false])->add('productReplacement', ProductSelectType::NAME, ['required' => false, 'label' => 'orob2b.sale.quoteproduct.product_replacement.label', 'create_enabled' => false])->add('quoteProductRequests', QuoteProductRequestCollectionType::NAME, [])->add('quoteProductOffers', QuoteProductOfferCollectionType::NAME, ['add_label' => 'orob2b.sale.quoteproductoffer.add_label'])->add('type', 'choice', ['label' => 'orob2b.sale.quoteproduct.type.label', 'choices' => $this->formatter->formatTypeLabels(QuoteProduct::getTypes()), 'required' => true, 'expanded' => false])->add('commentCustomer', 'textarea', ['required' => false, 'read_only' => true, 'label' => 'orob2b.sale.quoteproduct.comment_customer.label'])->add('comment', 'textarea', ['required' => false, 'label' => 'orob2b.sale.quoteproduct.comment.label']);
     $builder->addEventListener(FormEvents::PRE_SET_DATA, [$this, 'preSetData']);
 }
Exemplo n.º 13
0
 public function testIsTypeNotAvailable()
 {
     $quoteProduct = new QuoteProduct();
     $quoteProduct->setType(QuoteProduct::TYPE_NOT_AVAILABLE);
     $this->assertTrue($quoteProduct->isTypeNotAvailable());
 }
Exemplo n.º 14
0
 /**
  * @param QuoteProduct $quoteProduct
  * @param RFPRequestProduct $requestProduct
  */
 protected function processRequestProductItems(QuoteProduct $quoteProduct, RFPRequestProduct $requestProduct)
 {
     foreach ($requestProduct->getRequestProductItems() as $requestProductItem) {
         $quoteProductRequest = new QuoteProductRequest();
         $quoteProductRequest->setPrice($requestProductItem->getPrice())->setQuantity($requestProductItem->getQuantity())->setProductUnit($requestProductItem->getProductUnit());
         $quoteProduct->addQuoteProductRequest($quoteProductRequest);
     }
 }
Exemplo n.º 15
0
 /**
  * @param array $offers
  * @param bool $expected
  * @dataProvider hasIncrementalOffersDataProvider
  */
 public function testHasIncrementalOffers(array $offers, $expected)
 {
     $quoteProduct = new QuoteProduct();
     foreach ($offers as $offer) {
         $quoteProduct->addQuoteProductOffer($offer);
     }
     $this->assertSame($expected, $quoteProduct->hasIncrementalOffers());
 }
Exemplo n.º 16
0
 /**
  * @param int $productId
  * @param int $type
  * @param string $comment
  * @param string $commentCustomer
  * @param QuoteProductRequest[] $requests
  * @param QuoteProductOffer[] $offers
  * @return QuoteProduct
  */
 protected function getQuoteProduct($productId = null, $type = null, $comment = null, $commentCustomer = null, array $requests = [], array $offers = [])
 {
     $product = null;
     if ($productId) {
         $product = $this->getEntity('OroB2B\\Bundle\\ProductBundle\\Entity\\Product', $productId);
         foreach ($this->getProductUnitPrecisions() as $precision) {
             $product->addUnitPrecision($precision);
         }
     }
     $quoteProduct = new QuoteProduct();
     $quoteProduct->setQuote($this->getEntity('OroB2B\\Bundle\\SaleBundle\\Entity\\Quote', $productId))->setProduct($product)->setType($type)->setComment($comment)->setCommentCustomer($commentCustomer);
     foreach ($requests as $request) {
         $quoteProduct->addQuoteProductRequest($request);
     }
     foreach ($offers as $offer) {
         $quoteProduct->addQuoteProductOffer($offer);
     }
     return $quoteProduct;
 }
Exemplo n.º 17
0
 /**
  * @param int $quoteProductCount
  * @param int $quoteProductOfferCount
  * @param bool|false $allowIncrements
  * @return Quote
  */
 protected function createQuote($quoteProductCount, $quoteProductOfferCount, $allowIncrements = false)
 {
     $quote = new Quote();
     for ($i = 0; $i < $quoteProductCount; $i++) {
         $quoteProduct = new QuoteProduct();
         for ($j = 0; $j < $quoteProductOfferCount; $j++) {
             $quoteProductOffer = new QuoteProductOffer();
             $quoteProductOffer->setAllowIncrements($allowIncrements);
             $quoteProduct->addQuoteProductOffer($quoteProductOffer);
         }
         $quote->addQuoteProduct($quoteProduct);
     }
     return $quote;
 }
 /**
  * @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;
 }