function it_generates_correct_hierarchy_when_product_does_not_have_archetype(ProductInterface $product)
 {
     $product->getMetadataIdentifier()->shouldBeCalled()->willReturn('Product-42');
     $product->getMetadataClassIdentifier()->shouldBeCalled()->willReturn('Product');
     $product->getArchetype()->shouldBeCalled()->willReturn(null);
     $this->getHierarchyByMetadataSubject($product)->shouldReturn(['Product-42', 'Product', 'DefaultPage']);
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function isThereProduct(ProductInterface $product)
 {
     if (!($table = $this->getDocument()->find('css', 'table'))) {
         return false;
     }
     $row = $this->tableManipulator->getRowWithFields($table, ['id' => $product->getId()]);
     return null === $row;
 }
 function it_is_restricted_if_zone_matcher_match_customers_shipping_address(ProductInterface $product, $customerContext, $zoneMatcher, CustomerInterface $customer, AddressInterface $address, ProductInterface $product, ZoneInterface $zone)
 {
     $customerContext->getCustomer()->shouldBeCalled()->willReturn($customer);
     $customer->getShippingAddress()->shouldBeCalled()->willReturn($address);
     $product->getRestrictedZone()->shouldBeCalled()->willReturn($zone);
     $zoneMatcher->matchAll($address)->shouldBeCalled()->willReturn(array($zone));
     $this->isRestricted($product)->shouldReturn(true);
 }
Example #4
0
 function it_recognizes_a_subject_as_not_eligible_if_a_product_taxon_is_not_matched(OrderInterface $subject, OrderItemInterface $item, ProductInterface $reflexBow, TaxonInterface $bows)
 {
     $configuration = ['taxons' => ['swords', 'axes']];
     $bows->getCode()->willReturn('bows');
     $reflexBow->getTaxons()->willReturn([$bows]);
     $item->getProduct()->willReturn($reflexBow);
     $subject->getItems()->willReturn([$item]);
     $this->isEligible($subject, $configuration)->shouldReturn(false);
 }
 /**
  * {@inheritdoc}
  */
 public function provideVariantsPrices(ProductInterface $product)
 {
     $variantsPrices = [];
     /** @var ProductVariantInterface $variant */
     foreach ($product->getVariants() as $variant) {
         $variantsPrices[] = $this->constructOptionsMap($variant);
     }
     return $variantsPrices;
 }
Example #6
0
 /**
  * @param ProductInterface $product
  * @param array $taxons
  *
  * @return bool
  */
 private function hasProductValidTaxon(ProductInterface $product, array $taxons)
 {
     foreach ($product->getTaxons() as $taxon) {
         if (in_array($taxon->getCode(), $taxons)) {
             return true;
         }
     }
     return false;
 }
 /**
  * @When /^I delete the ("[^"]+" product)$/
  * @When /^I try to delete the ("([^"]+)" product)$/
  */
 public function iDeleteTheProduct(ProductInterface $product)
 {
     try {
         $this->sharedStorage->set('product_id', $product->getId());
         $this->productRepository->remove($product);
     } catch (DBALException $exception) {
         $this->sharedStorage->set('last_exception', $exception);
     }
 }
 function it_is_restricted_if_zone_matcher_match_users_shipping_address(ProductInterface $product, $securityContext, $zoneMatcher, TokenInterface $token, UserInterface $user, AddressInterface $address, ProductInterface $product, ZoneInterface $zone)
 {
     $securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED')->shouldBeCalled()->willReturn(true);
     $securityContext->getToken()->shouldBeCalled()->willReturn($token);
     $token->getUser()->shouldBeCalled()->willReturn($user);
     $user->getShippingAddress()->shouldBeCalled()->willReturn($address);
     $product->getRestrictedZone()->shouldBeCalled()->willReturn($zone);
     $zoneMatcher->matchAll($address)->shouldBeCalled()->willReturn(array($zone));
     $this->isRestricted($product)->shouldReturn(true);
 }
 function it_adds_single_item_by_customer(FactoryInterface $orderItemFactory, OrderInterface $order, OrderItemInterface $item, OrderItemQuantityModifierInterface $itemQuantityModifier, ProductInterface $product, SharedStorageInterface $sharedStorage, ProductVariantInterface $variant, ObjectManager $objectManager)
 {
     $sharedStorage->get('order')->willReturn($order);
     $orderItemFactory->createNew()->willReturn($item);
     $product->getMasterVariant()->willReturn($variant);
     $product->getPrice()->willReturn(1234);
     $itemQuantityModifier->modify($item, 1)->shouldBeCalled();
     $item->setVariant($variant)->shouldBeCalled();
     $item->setUnitPrice(1234)->shouldBeCalled();
     $order->addItem($item)->shouldBeCalled();
     $objectManager->flush()->shouldBeCalled();
     $this->theCustomerBoughtSingle($product);
 }
 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 #11
0
 /**
  * @param ProductInterface $product
  * @param array            $data
  */
 private function configureProductPricingCalculator(ProductInterface $product, array $data)
 {
     $product->getMasterVariant()->setPricingCalculator($data['pricing calculator']);
     if (!isset($data['calculator configuration']) || '' === $data['calculator configuration']) {
         throw new \InvalidArgumentException('You must set chosen calculator configuration');
     }
     $product->getMasterVariant()->setPricingConfiguration($this->getPricingCalculatorConfiguration($data));
 }
Example #12
0
 /**
  * @Then /^average rating of (product "[^"]+") should be (\d+)$/
  */
 public function thisProductAverageRatingShouldBe(ProductInterface $product, $averageRating)
 {
     $this->showPage->tryToOpen(['slug' => $product->getSlug()]);
     $this->iShouldSeeAsItsAverageRating($averageRating);
 }
Example #13
0
 /**
  * @param ProductInterface $product
  * @param int $quantity
  */
 private function setProductsQuantity(ProductInterface $product, $quantity)
 {
     $product->getFirstVariant()->setOnHand($quantity);
     $this->saveProduct($product);
 }
Example #14
0
 function it_adds_taxon_to_product(ProductInterface $product, TaxonInterface $taxon)
 {
     $product->addTaxon($taxon)->shouldBeCalled();
     $this->itBelongsTo($product, $taxon);
 }
Example #15
0
 protected function addTranslatedFields(ProductInterface $product, $translatedNames)
 {
     foreach ($translatedNames as $locale => $name) {
         $product->setCurrentLocale($locale);
         $product->setFallbackLocale($locale);
         $product->setName($name);
         $product->setDescription($this->fakers[$locale]->paragraph);
         $product->setShortDescription($this->fakers[$locale]->sentence);
         $product->setMetaKeywords(str_replace(' ', ', ', $this->fakers[$locale]->sentence));
         $product->setMetaDescription($this->fakers[$locale]->sentence);
     }
     $product->setCurrentLocale($this->defaultLocale);
 }
Example #16
0
 /**
  * @Then /^(this product) should no longer have price for channel "([^"]+)"$/
  */
 public function thisProductShouldNoLongerHavePriceForChannel(ProductInterface $product, $channelName)
 {
     $this->updateSimpleProductPage->open(['id' => $product->getId()]);
     try {
         $this->updateSimpleProductPage->getPriceForChannel($channelName);
     } catch (ElementNotFoundException $exception) {
         return;
     }
     throw new \Exception(sprintf('Product "%s" should not have price defined for channel "%s".', $product->getName(), $channelName));
 }
Example #17
0
 /**
  * @Given /^(this product) has (this product option)$/
  * @Given /^(this product) has a ("[^"]+" option)$/
  * @Given /^(this product) has an ("[^"]+" option)$/
  */
 public function thisProductHasThisProductOption(ProductInterface $product, OptionInterface $option)
 {
     $product->addOption($option);
     $this->objectManager->flush();
 }
Example #18
0
 /**
  * @param ProductInterface $product
  * @param array $options
  */
 private function createImages(ProductInterface $product, array $options)
 {
     foreach ($options['images'] as $imageCode => $imagePath) {
         /** @var ImageInterface $productImage */
         $productImage = $this->productImageFactory->createNew();
         $productImage->setCode($imageCode);
         $productImage->setFile(new UploadedFile($imagePath, basename($imagePath)));
         $this->imageUploader->upload($productImage);
         $product->addImage($productImage);
     }
 }
Example #19
0
 /**
  * @Given I want to review product :product
  */
 public function iWantToReviewProduct(ProductInterface $product)
 {
     $this->createPage->open(['slug' => $product->getSlug()]);
 }
Example #20
0
 /**
  * @Given /^(it) (belongs to "[^"]+")$/
  */
 public function itBelongsTo(ProductInterface $product, TaxonInterface $taxon)
 {
     $product->addTaxon($taxon);
     $this->objectManager->flush($product);
 }
 /**
  * @Then the :variant variant of :product product should have :amount items on hold
  */
 public function theVariantOfProductShouldHaveItemsOnHold(ProductVariantInterface $variant, ProductInterface $product, $amount)
 {
     $this->indexPage->open(['productId' => $product->getId()]);
     Assert::same($amount, $this->indexPage->getOnHoldQuantityFor($variant), sprintf('Unexpected on hold quantity for "%s" variant. It should be "%s" but is "%s"', $variant->getName(), $amount, $this->indexPage->getOnHandQuantityFor($variant)));
 }
Example #22
0
 /**
  * @Given /^(product "[^"]+") belongs to ("[^"]+" tax category)$/
  */
 public function productBelongsToTaxCategory(ProductInterface $product, TaxCategoryInterface $taxCategory)
 {
     $product->setTaxCategory($taxCategory);
     $this->productManager->flush($product);
 }
Example #23
0
 /**
  * @Then I should be on :product product detailed page
  */
 public function iShouldBeOnProductDetailedPage(ProductInterface $product)
 {
     Assert::true($this->showPage->isOpen(['slug' => $product->getSlug()]), sprintf('Product %s show page should be open, but it does not.', $product->getName()));
 }
 /**
  * @Then /^(this product) main taxon should be "([^"]+)"$/
  */
 public function thisProductMainTaxonShouldBe(ProductInterface $product, $taxonName)
 {
     /** @var UpdatePageInterface $currentPage */
     $currentPage = $this->currentPageResolver->getCurrentPageWithForm([$this->updateSimpleProductPage, $this->updateConfigurableProductPage], $this->sharedStorage->get('product'));
     $currentPage->open(['id' => $product->getId()]);
     Assert::true($this->updateConfigurableProductPage->isMainTaxonChosen($taxonName), sprintf('The main taxon %s should be chosen, but it does not.', $taxonName));
 }
 /**
  * @param ProductInterface $product
  * @param ProductAssociationTypeInterface $productAssociationType
  * @param array $associatedProducts
  */
 private function createProductAssociation(ProductInterface $product, ProductAssociationTypeInterface $productAssociationType, array $associatedProducts)
 {
     /** @var ProductAssociationInterface $productAssociation */
     $productAssociation = $this->productAssociationFactory->createNew();
     $productAssociation->setType($productAssociationType);
     foreach ($associatedProducts as $associatedProduct) {
         $productAssociation->addAssociatedProduct($associatedProduct);
     }
     $product->addAssociation($productAssociation);
     $this->productAssociationRepository->add($productAssociation);
 }
Example #26
0
 /**
  * {@inheritdoc]
  */
 public function hasProductOutOfStockValidationMessage(ProductInterface $product)
 {
     $message = sprintf('%s does not have sufficient stock.', $product->getName());
     try {
         return $this->getElement('validation_errors')->getText() === $message;
     } catch (ElementNotFoundException $exception) {
         return false;
     }
 }
Example #27
0
 /**
  * @param ProductInterface $product
  *
  * @return NodeElement
  */
 private function getProductRowElement(ProductInterface $product)
 {
     return $this->getElement('product_row', ['%name%' => $product->getName()]);
 }
Example #28
0
 /**
  * @Given the customer bought a single :product using :coupon coupon
  */
 public function theCustomerBoughtSingleUsing(ProductInterface $product, CouponInterface $coupon)
 {
     $order = $this->addProductVariantToOrder($product->getFirstVariant(), $product->getPrice());
     $order->setPromotionCoupon($coupon);
     $this->orderRecalculator->recalculate($order);
     $this->objectManager->flush();
 }
Example #29
0
 /**
  * @Given /^([^"]+) belongs to ("[^"]+" tax category)$/
  */
 public function productBelongsToTaxCategory(ProductInterface $product, TaxCategoryInterface $taxCategory)
 {
     $product->getMasterVariant()->setTaxCategory($taxCategory);
     $this->objectManager->flush();
 }
 function it_throws_an_exception_if_product_page_could_not_be_matched(ProductInterface $product, CurrentPageResolverInterface $currentPageResolver, UpdateConfigurableProductPageInterface $configurableUpdatePage)
 {
     $product->isSimple()->willReturn(true);
     $currentPageResolver->getCurrentPageWithForm([$configurableUpdatePage])->willReturn($configurableUpdatePage);
     $this->shouldThrow(new \InvalidArgumentException('Route name could not be matched to provided pages.'))->during('getCurrentPageWithForm', [[$configurableUpdatePage], $product]);
 }