diff --git a/features/product/viewing_products/not_seeing_lowest_price_for_product_that_has_taxon_excluded_on_channel.feature b/features/product/viewing_products/not_seeing_lowest_price_for_product_that_has_taxon_excluded_on_channel.feature index 90c104a3a5..1fed8eead7 100644 --- a/features/product/viewing_products/not_seeing_lowest_price_for_product_that_has_taxon_excluded_on_channel.feature +++ b/features/product/viewing_products/not_seeing_lowest_price_for_product_that_has_taxon_excluded_on_channel.feature @@ -9,12 +9,10 @@ Feature: Not seeing the lowest price for a product that has a taxon excluded on And the store classifies its products as "Category" And the "Category" taxon has children taxons "Groceries" and "Special offers" And the "Groceries" taxon has child taxon "Vegetables" - And the store has a product "Broccoli" priced at "$20.00" - And it belongs to "Vegetables" + And the store has a product "Broccoli" priced at "$20.00" belonging to the "Vegetables" taxon And this product's price changed to "$10.00" and original price changed to "$20.00" And the store also has a product "Cauliflower" priced at "$25.00" - And it belongs to "Vegetables" - And it belongs to "Special offers" + And it belongs to "Vegetables" and "Special offers" And this product's price changed to "$15.00" and original price changed to "$25.00" And I am logged in as an administrator diff --git a/src/Sylius/Behat/Context/Api/Admin/ManagingChannelsContext.php b/src/Sylius/Behat/Context/Api/Admin/ManagingChannelsContext.php index 977e6cf771..7a3fa697d0 100644 --- a/src/Sylius/Behat/Context/Api/Admin/ManagingChannelsContext.php +++ b/src/Sylius/Behat/Context/Api/Admin/ManagingChannelsContext.php @@ -24,7 +24,6 @@ use Sylius\Component\Core\Model\ChannelInterface; use Sylius\Component\Core\Model\TaxonInterface; use Sylius\Component\Currency\Model\CurrencyInterface; use Sylius\Component\Locale\Model\LocaleInterface; -use Sylius\Component\Resource\Model\ResourceInterface; use Webmozart\Assert\Assert; final class ManagingChannelsContext implements Context diff --git a/src/Sylius/Behat/Context/Setup/ProductContext.php b/src/Sylius/Behat/Context/Setup/ProductContext.php index 89f64b45c8..7f6c2f5ac4 100644 --- a/src/Sylius/Behat/Context/Setup/ProductContext.php +++ b/src/Sylius/Behat/Context/Setup/ProductContext.php @@ -64,6 +64,7 @@ final class ProductContext implements Context private SlugGeneratorInterface $slugGenerator, private \ArrayAccess $minkParameters, private MessageBusInterface $eventBus, + private ProductTaxonContext $productTaxonContext, ) { } @@ -74,7 +75,7 @@ final class ProductContext implements Context * @Given /^the store(?:| also) has a product "([^"]+)" priced at ("[^"]+")$/ * @Given /^the store(?:| also) has a product "([^"]+)" priced at ("[^"]+") in ("[^"]+" channel)$/ */ - public function storeHasAProductPricedAt($productName, int $price = 100, ChannelInterface $channel = null) + public function storeHasAProductPricedAt($productName, int $price = 100, ChannelInterface $channel = null): void { $product = $this->createProduct($productName, $price, $channel); @@ -88,10 +89,9 @@ final class ProductContext implements Context string $productName, int $price = 100, TaxonInterface $taxon, - ) { - $productTaxon = $this->createProductTaxon($taxon); + ): void { $product = $this->createProduct($productName, $price); - $product->addProductTaxon($taxon); + $this->productTaxonContext->itBelongsTo($product, $taxon); $this->saveProduct($product); } diff --git a/src/Sylius/Behat/Context/Setup/ProductTaxonContext.php b/src/Sylius/Behat/Context/Setup/ProductTaxonContext.php index c1ee0b0f7f..6b8f83d419 100644 --- a/src/Sylius/Behat/Context/Setup/ProductTaxonContext.php +++ b/src/Sylius/Behat/Context/Setup/ProductTaxonContext.php @@ -43,6 +43,20 @@ final class ProductTaxonContext implements Context $this->objectManager->flush(); } + /** + * @Given /^(it|this product) (belongs to "[^"]+" and "[^"]+")$/ + */ + public function itBelongsToAnd(ProductInterface $product, iterable $taxons) + { + foreach ($taxons as $taxon) { + $productTaxon = $this->createProductTaxon($taxon, $product); + $product->addProductTaxon($productTaxon); + } + + $this->objectManager->persist($product); + $this->objectManager->flush(); + } + /** * @Given the product :product has a main taxon :taxon * @Given /^(this product) has a main (taxon "[^"]+")$/ @@ -53,12 +67,7 @@ final class ProductTaxonContext implements Context $this->objectManager->flush(); } - /** - * @param int|null $position - * - * @return ProductTaxonInterface - */ - private function createProductTaxon(TaxonInterface $taxon, ProductInterface $product, $position = null) + private function createProductTaxon(TaxonInterface $taxon, ProductInterface $product, ?int $position = null): ProductTaxonInterface { /** @var ProductTaxonInterface $productTaxon */ $productTaxon = $this->productTaxonFactory->createNew(); diff --git a/src/Sylius/Behat/Context/Transform/TaxonContext.php b/src/Sylius/Behat/Context/Transform/TaxonContext.php index b38b66349b..f236d7d866 100644 --- a/src/Sylius/Behat/Context/Transform/TaxonContext.php +++ b/src/Sylius/Behat/Context/Transform/TaxonContext.php @@ -37,7 +37,7 @@ final class TaxonContext implements Context * @Transform /^taxon "([^"]+)"$/ * @Transform :taxon */ - public function getTaxonByName($name) + public function getTaxonByName(string $name) { $taxons = $this->taxonRepository->findByName($name, $this->locale); @@ -53,7 +53,7 @@ final class TaxonContext implements Context /** * @Transform /^taxon with "([^"]+)" code$/ */ - public function getTaxonByCode($code) + public function getTaxonByCode(string $code) { $taxon = $this->taxonRepository->findOneBy(['code' => $code]); Assert::notNull($taxon, sprintf('Taxon with code "%s" does not exist.', $code)); @@ -65,8 +65,9 @@ final class TaxonContext implements Context * @Transform /^classified as "([^"]+)" or "([^"]+)"$/ * @Transform /^configured with "([^"]+)" and "([^"]+)"$/ * @Transform /^"([^"]+)" and "([^"]+)" taxons$/ + * @Transform /^belongs to "([^"]+)" and "([^"]+)"/ */ - public function getTaxonsByNames(...$taxonNames): iterable + public function getTaxonsByNames(string ...$taxonNames): iterable { foreach ($taxonNames as $taxonName) { yield $this->getTaxonByName($taxonName); diff --git a/src/Sylius/Behat/Resources/config/services/contexts/setup.xml b/src/Sylius/Behat/Resources/config/services/contexts/setup.xml index 8a220aff3c..a364891901 100644 --- a/src/Sylius/Behat/Resources/config/services/contexts/setup.xml +++ b/src/Sylius/Behat/Resources/config/services/contexts/setup.xml @@ -158,6 +158,7 @@ +