Example #1
0
 function its_price_is_mutable(VariantInterface $masterVariant)
 {
     $masterVariant->setPrice(499)->shouldBeCalled();
     $masterVariant->getPrice()->willReturn(499);
     $this->setPrice(499);
     $this->getPrice()->shouldReturn(499);
 }
Example #2
0
 function its_sku_is_order_item_variant_sku(OrderItemInterface $orderItem, ProductVariantInterface $variant)
 {
     $variant->getSku()->willReturn('test_sku');
     $orderItem->getVariant()->willReturn($variant);
     $this->setOrderItem($orderItem);
     $this->getSku()->shouldReturn('test_sku');
 }
 /**
  * {@inheritdoc}
  */
 public function calculate(ProductVariantInterface $productVariant, array $context)
 {
     Assert::keyExists($context, 'channel');
     $channelPricing = $productVariant->getChannelPricingForChannel($context['channel']);
     Assert::notNull($channelPricing);
     return $channelPricing->getPrice();
 }
Example #4
0
 /**
  * @param ProductVariantInterface $variant
  * @param array $priceRange
  *
  * @return bool
  */
 private function isItemVariantInPriceRange(ProductVariantInterface $variant, array $priceRange)
 {
     $price = $variant->getPrice();
     if (isset($priceRange['min']) && isset($priceRange['max'])) {
         return $priceRange['min'] <= $price && $priceRange['max'] >= $price;
     }
     return $priceRange['min'] <= $price;
 }
Example #5
0
 /**
  * {@inheritdoc}
  */
 public function getOnHoldQuantityFor(ProductVariantInterface $productVariant)
 {
     try {
         return (int) $this->getElement('on_hold_quantity', ['%id%' => $productVariant->getId()])->getText();
     } catch (ElementNotFoundException $exception) {
         return 0;
     }
 }
Example #6
0
 function it_should_inherit_price_from_master_variant(ProductVariantInterface $masterVariant)
 {
     $masterVariant->isMaster()->willReturn(true);
     $masterVariant->getAvailableOn()->willReturn(new \DateTime('yesterday'));
     $masterVariant->getPrice()->willReturn(499);
     $this->setDefaults($masterVariant);
     $this->getPrice()->shouldReturn(499);
 }
 function it_generates_correct_hierarchy_when_product_variant_does_not_have_archetype(ProductVariantInterface $productVariant, ProductInterface $product)
 {
     $productVariant->getMetadataIdentifier()->shouldBeCalled()->willReturn('ProductVariant-42');
     $product->getMetadataIdentifier()->shouldBeCalled()->willReturn('Product-42');
     $product->getMetadataClassIdentifier()->shouldBeCalled()->willReturn('Product');
     $productVariant->getProduct()->shouldBeCalled()->willReturn($product);
     $product->getArchetype()->shouldBeCalled()->willReturn(null);
     $this->getHierarchyByMetadataSubject($productVariant)->shouldReturn(['ProductVariant-42', 'Product-42', 'Product', 'DefaultPage']);
 }
 /**
  * @When /^I delete the ("[^"]+" variant of product "[^"]+")$/
  * @When /^I try to delete the ("[^"]+" variant of product "[^"]+")$/
  */
 public function iDeleteTheVariantOfProduct(ProductVariantInterface $productVariant)
 {
     try {
         $this->sharedStorage->set('product_variant_id', $productVariant->getId());
         $this->productVariantRepository->remove($productVariant);
     } catch (DBALException $exception) {
         $this->sharedStorage->set('last_exception', $exception);
     }
 }
 /**
  * @param ProductVariantInterface $variant
  *
  * @return array
  */
 private function constructOptionsMap(ProductVariantInterface $variant)
 {
     $optionMap = [];
     /** @var ProductOptionValueInterface $option */
     foreach ($variant->getOptionValues() as $option) {
         $optionMap[$option->getOptionCode()] = $option->getValue();
     }
     $optionMap['value'] = $variant->getPrice();
     return $optionMap;
 }
 /**
  * @param ProductVariantInterface $variant
  * @param ChannelInterface $channel
  *
  * @return array
  */
 private function constructOptionsMap(ProductVariantInterface $variant, ChannelInterface $channel)
 {
     $optionMap = [];
     /** @var ProductOptionValueInterface $option */
     foreach ($variant->getOptionValues() as $option) {
         $optionMap[$option->getOptionCode()] = $option->getValue();
     }
     $optionMap['value'] = $this->productVariantPriceCalculator->calculate($variant, ['channel' => $channel]);
     return $optionMap;
 }
 /**
  * @param ProductVariantInterface $productVariant
  */
 private function uploadProductVariantImages(ProductVariantInterface $productVariant)
 {
     $images = $productVariant->getImages();
     foreach ($images as $image) {
         if ($image->hasFile()) {
             $this->uploader->upload($image);
         }
         // Upload failed? Let's remove that image.
         if (null === $image->getPath()) {
             $images->removeElement($image);
         }
     }
 }
 function it_provides_array_containing_product_variant_options_map_with_corresponding_price(ProductInterface $tShirt, ProductOptionValueInterface $black, ProductOptionValueInterface $large, ProductOptionValueInterface $small, ProductOptionValueInterface $white, ProductVariantInterface $blackLargeTShirt, ProductVariantInterface $blackSmallTShirt, ProductVariantInterface $whiteLargeTShirt, ProductVariantInterface $whiteSmallTShirt)
 {
     $tShirt->getVariants()->willReturn([$blackSmallTShirt, $whiteSmallTShirt, $blackLargeTShirt, $whiteLargeTShirt]);
     $blackSmallTShirt->getOptionValues()->willReturn([$black, $small]);
     $whiteSmallTShirt->getOptionValues()->willReturn([$white, $small]);
     $blackLargeTShirt->getOptionValues()->willReturn([$black, $large]);
     $whiteLargeTShirt->getOptionValues()->willReturn([$white, $large]);
     $blackSmallTShirt->getPrice()->willReturn(1000);
     $whiteSmallTShirt->getPrice()->willReturn(1500);
     $blackLargeTShirt->getPrice()->willReturn(2000);
     $whiteLargeTShirt->getPrice()->willReturn(2500);
     $black->getOptionCode()->willReturn('t_shirt_color');
     $white->getOptionCode()->willReturn('t_shirt_color');
     $small->getOptionCode()->willReturn('t_shirt_size');
     $large->getOptionCode()->willReturn('t_shirt_size');
     $black->getValue()->willReturn('Black');
     $white->getValue()->willReturn('White');
     $small->getValue()->willReturn('Small');
     $large->getValue()->willReturn('Large');
     $this->provideVariantsPrices($tShirt)->shouldReturn([['t_shirt_color' => 'Black', 't_shirt_size' => 'Small', 'value' => 1000], ['t_shirt_color' => 'White', 't_shirt_size' => 'Small', 'value' => 1500], ['t_shirt_color' => 'Black', 't_shirt_size' => 'Large', 'value' => 2000], ['t_shirt_color' => 'White', 't_shirt_size' => 'Large', 'value' => 2500]]);
 }
Example #13
0
 /**
  * @param ProductVariantInterface $productVariant
  * @param ChannelInterface $channel
  */
 private function createChannelPricings(ProductVariantInterface $productVariant, ChannelInterface $channel)
 {
     /** @var ChannelPricingInterface $channelPricing */
     $channelPricing = $this->channelPricingFactory->createNew();
     $channelPricing->setChannel($channel);
     $channelPricing->setPrice($this->faker->randomNumber(3));
     $productVariant->addChannelPricing($channelPricing);
 }
Example #14
0
 function it_throws_an_exception_if_a_product_variant_does_not_exist(ProductVariantRepositoryInterface $productVariantRepository, ProductVariantInterface $productVariant)
 {
     $productVariant->getId()->willReturn(1);
     $productVariantRepository->find(1)->willReturn(null);
     $this->shouldThrow(FailureException::class)->during('productVariantShouldExistInTheProductCatalog', [$productVariant]);
 }
 /**
  * @Then /^I should see that the ("[^"]+" variant) has zero on hand quantity$/
  */
 public function iShouldSeeThatTheVariantHasZeroOnHandQuantity(ProductVariantInterface $productVariant)
 {
     Assert::true($this->indexPage->isSingleResourceOnPage(['name' => $productVariant->getName(), 'inventory' => '0 Available on hand']), sprintf('This "%s" variant should have 0 on hand quantity, but it does not.', $productVariant->getName()));
 }
 /**
  * @When I want to modify the :productVariant product variant
  * @When /^I want to modify (this product variant)$/
  */
 public function iWantToModifyAProduct(ProductVariantInterface $productVariant)
 {
     $this->updatePage->open(['id' => $productVariant->getId()]);
 }
 function it_throws_invalid_argument_exception_if_on_hold_quantity_to_decrease_will_be_below_zero(OrderInterface $order, OrderItemInterface $orderItem, ProductVariantInterface $productVariant)
 {
     $productVariant->getOnHold()->willReturn(5);
     $productVariant->isTracked()->willReturn(true);
     $productVariant->getName()->willReturn('t-shirt');
     $orderItem->getVariant()->willReturn($productVariant);
     $orderItem->getQuantity()->willReturn(10);
     $order->getItems()->willReturn([$orderItem]);
     $productVariant->setOnHold(-5)->shouldNotBeCalled();
     $this->shouldThrow(\InvalidArgumentException::class)->during('decrease', [$order]);
 }
 /**
  * @Then /^(variant with code "[^"]+") for ("[^"]+" currency) and ("[^"]+" channel) should be priced at "(?:€|£|\$)([^"]+)"$/
  */
 public function theProductForCurrencyAndChannelShouldBePricedAt(ProductVariantInterface $productVariant, CurrencyInterface $currency, ChannelInterface $channel, $price)
 {
     $this->updatePage->open(['id' => $productVariant->getId(), 'productId' => $productVariant->getProduct()->getId()]);
     Assert::same($this->updatePage->getPricingConfigurationForChannelAndCurrencyCalculator($channel, $currency), $price);
 }
Example #19
0
 /**
  * @Given /^the ("[^"]+" product variant) is tracked by the inventory$/
  */
 public function theProductVariantIsTrackedByTheInventory(ProductVariantInterface $productVariant)
 {
     $productVariant->setTracked(true);
     $this->objectManager->flush();
 }
Example #20
0
 /**
  * {@inheritdoc}
  */
 public function getProduct()
 {
     return $this->variant->getProduct();
 }
Example #21
0
 /**
  * @Given /^("[^"]+" variant of product "[^"]+") belongs to ("[^"]+" tax category)$/
  */
 public function productVariantBelongsToTaxCategory(ProductVariantInterface $productVariant, TaxCategoryInterface $taxCategory)
 {
     $productVariant->setTaxCategory($taxCategory);
     $this->objectManager->flush($productVariant);
 }
 function it_throws_exception_if_there_is_no_variant_price_for_given_channel(ChannelInterface $channel, ProductVariantInterface $productVariant)
 {
     $productVariant->getChannelPricingForChannel($channel)->willReturn(null);
     $this->shouldThrow(\InvalidArgumentException::class)->during('calculate', [$productVariant, ['chanel' => $channel]]);
 }
Example #23
0
 function it_adds_single_product_variant_as_item_by_customer(FactoryInterface $orderItemFactory, OrderInterface $order, OrderItemInterface $item, OrderItemQuantityModifierInterface $itemQuantityModifier, SharedStorageInterface $sharedStorage, ProductVariantInterface $variant, ObjectManager $objectManager)
 {
     $sharedStorage->get('order')->willReturn($order);
     $orderItemFactory->createNew()->willReturn($item);
     $variant->getPrice()->willReturn(1234);
     $itemQuantityModifier->modify($item, 1)->shouldBeCalled();
     $item->setVariant($variant)->shouldBeCalled();
     $item->setUnitPrice(1234)->shouldBeCalled();
     $order->addItem($item)->shouldBeCalled();
     $objectManager->flush()->shouldBeCalled();
     $this->theCustomerBoughtSingleProductVariant($variant);
 }
 /**
  * @Then /^(this variant) should not exist in the product catalog$/
  */
 public function productVariantShouldNotExistInTheProductCatalog(ProductVariantInterface $productVariant)
 {
     Assert::null($this->productVariantRepository->findOneBy(['code' => $productVariant->getCode()]));
 }
Example #25
0
 /**
  * @When /^I delete the ("[^"]+" variant of product "[^"]+")$/
  */
 public function iDeleteTheVariantOfProduct(ProductVariantInterface $productVariant)
 {
     $this->sharedStorage->set('product_variant_id', $productVariant->getId());
     $this->productVariantRepository->remove($productVariant);
 }
Example #26
0
 function let(VariantInterface $variant)
 {
     $variant->setProduct($this)->shouldBeCalled();
     $this->addVariant($variant);
 }
Example #27
0
 function it_returns_a_null_as_product_price_if_a_product_has_no_variants(VariantInterface $variant)
 {
     $variant->setProduct(null)->shouldBeCalled();
     $this->removeVariant($variant);
     $this->getPrice()->shouldReturn(null);
 }
Example #28
0
 /**
  * @param ProductVariantInterface $productVariant
  * @param string $name
  * @param string $locale
  */
 private function addProductVariantTranslation(ProductVariantInterface $productVariant, $name, $locale)
 {
     /** @var ProductVariantTranslationInterface|TranslationInterface $translation */
     $translation = $this->productVariantTranslationFactory->createNew();
     $translation->setLocale($locale);
     $translation->setName($name);
     $productVariant->addTranslation($translation);
 }