/** * @return array */ public function validatorDataProvider() { $offer = new QuoteProductOffer(); $offer->setQuantity(10); $moreOffer = new QuoteProductOffer(); $moreOffer->setAllowIncrements(true); $moreOffer->setQuantity(10); return [[null, 'orob2b.sale.quoteproductoffer.configurable.offer.blank', QuoteProductToOrderType::FIELD_QUANTITY], [[], 'orob2b.sale.quoteproductoffer.configurable.offer.blank', QuoteProductToOrderType::FIELD_QUANTITY], [[QuoteProductToOrderType::FIELD_QUANTITY => 10], 'orob2b.sale.quoteproductoffer.configurable.offer.blank', QuoteProductToOrderType::FIELD_QUANTITY], [[QuoteProductToOrderType::FIELD_OFFER => new \stdClass(), QuoteProductToOrderType::FIELD_QUANTITY => 10], 'orob2b.sale.quoteproductoffer.configurable.offer.blank', QuoteProductToOrderType::FIELD_QUANTITY], [[QuoteProductToOrderType::FIELD_OFFER => $offer, QuoteProductToOrderType::FIELD_QUANTITY => $offer->getQuantity() - 5], 'orob2b.sale.quoteproductoffer.configurable.quantity.equal', QuoteProductToOrderType::FIELD_QUANTITY], [[QuoteProductToOrderType::FIELD_OFFER => $offer, QuoteProductToOrderType::FIELD_QUANTITY => $offer->getQuantity() + 5], 'orob2b.sale.quoteproductoffer.configurable.quantity.equal', QuoteProductToOrderType::FIELD_QUANTITY], [[QuoteProductToOrderType::FIELD_OFFER => $moreOffer, QuoteProductToOrderType::FIELD_QUANTITY => $moreOffer->getQuantity() - 5], 'orob2b.sale.quoteproductoffer.configurable.quantity.less', QuoteProductToOrderType::FIELD_QUANTITY], [[QuoteProductToOrderType::FIELD_OFFER => $moreOffer, QuoteProductToOrderType::FIELD_QUANTITY => $moreOffer->getQuantity() + 5], null, null], [[QuoteProductToOrderType::FIELD_OFFER => $moreOffer, QuoteProductToOrderType::FIELD_QUANTITY => $moreOffer->getQuantity()], null, null], [[QuoteProductToOrderType::FIELD_OFFER => $offer, QuoteProductToOrderType::FIELD_QUANTITY => $offer->getQuantity()], null, null]]; }
/** * @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); }
/** * @return array */ public function hasIncrementalOffersDataProvider() { $firstNotIncrementedOffer = new QuoteProductOffer(); $firstNotIncrementedOffer->setAllowIncrements(false); $secondNotIncrementedOffer = new QuoteProductOffer(); $secondNotIncrementedOffer->setAllowIncrements(false); $incrementedOffer = new QuoteProductOffer(); $incrementedOffer->setAllowIncrements(true); return ['no offers' => ['offers' => [], 'expected' => false], 'no incremented offers' => ['offers' => [$firstNotIncrementedOffer, $secondNotIncrementedOffer], 'expected' => false], 'one incremented offer' => ['offers' => [$firstNotIncrementedOffer, $secondNotIncrementedOffer, $incrementedOffer], 'expected' => true]]; }
/** * @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; }