diff --git a/UPGRADE-1.11.md b/UPGRADE-1.11.md index 8c544ff61b2..ac1f674e0ee 100644 --- a/UPGRADE-1.11.md +++ b/UPGRADE-1.11.md @@ -1,3 +1,10 @@ +# UPGRADE FROM `v1.11.6` TO `v1.11.7` + +1. Method `Sylius\Component\Channel\Repository\ChannelRepository::findOneByHostname` has become deprecated, use +`Sylius\Component\Channel\Repository\ChannelRepository::findOneEnabledByHostname` instead. Simultaneously with this change +`Sylius\Component\Channel\Context\RequestBased\HostnameBasedRequestResolver::findChannel` will start selecting only a channel from a range +of enabled channels. + # UPGRADE FROM `v1.11.2` TO `v1.11.3` 1. Order Processors' priorities have changed and `sylius.order_processing.order_prices_recalculator` has now a higher priority than `sylius.order_processing.order_shipment_processor`. diff --git a/features/channel/filtering_out_disabled_channels.feature b/features/channel/filtering_out_disabled_channels.feature new file mode 100644 index 00000000000..e46e261488c --- /dev/null +++ b/features/channel/filtering_out_disabled_channels.feature @@ -0,0 +1,18 @@ +@channels +Feature: Filtering out disabled channels + In order to avoid mistakes + As a Customer + I want to be able to browse only available shops + + Background: + Given the store operates on a channel named "Fashion" in "USD" currency and with hostname "127.0.0.1" + And the store operates on a channel named "Furniture" in "EUR" currency and with hostname "127.0.0.1" + And there is product "Black T-Shirt" available in "Fashion" channel + And there is product "Old Wardrobe" available in "Furniture" channel + And the channel "Fashion" is disabled + + @ui @api + Scenario: Seeing Furniture shop products + When I check latest products + Then I should see "Old Wardrobe" product + And I should not see "Black T-Shirt" product diff --git a/src/Sylius/Behat/Context/Api/Shop/HomepageContext.php b/src/Sylius/Behat/Context/Api/Shop/HomepageContext.php index 967f656916f..67b3b9b537a 100644 --- a/src/Sylius/Behat/Context/Api/Shop/HomepageContext.php +++ b/src/Sylius/Behat/Context/Api/Shop/HomepageContext.php @@ -39,6 +39,34 @@ public function iCheckLatestProducts(): void ); } + /** + * @Then I should see :productName product + */ + public function iShouldSeeProduct(string $productName): void + { + Assert::true( + $this->responseChecker->hasItemWithValue( + $this->productsClient->getLastResponse(), + 'name', + $productName + ) + ); + } + + /** + * @Then I should not see :productName product + */ + public function iShouldNotSeeProduct(string $productName): void + { + Assert::false( + $this->responseChecker->hasItemWithValue( + $this->productsClient->getLastResponse(), + 'name', + $productName + ) + ); + } + /** * @When I check available taxons */ diff --git a/src/Sylius/Behat/Context/Ui/Shop/HomepageContext.php b/src/Sylius/Behat/Context/Ui/Shop/HomepageContext.php index a06a6e34464..6ee58ccbab1 100644 --- a/src/Sylius/Behat/Context/Ui/Shop/HomepageContext.php +++ b/src/Sylius/Behat/Context/Ui/Shop/HomepageContext.php @@ -51,6 +51,22 @@ public function iShouldSeeProductsInTheList(int $numberOfProducts): void Assert::same(count($this->homePage->getLatestProductsNames()), $numberOfProducts); } + /** + * @Then I should see :productName product + */ + public function iShouldSeeProduct(string $productName): void + { + Assert::inArray($productName, $this->homePage->getLatestProductsNames()); + } + + /** + * @Then I should not see :productName product + */ + public function iShouldNotSeeProduct(string $productName): void + { + Assert::true(!in_array($productName, $this->homePage->getLatestProductsNames())); + } + /** * @Then I should see :firstMenuItem in the menu * @Then I should see :firstMenuItem and :secondMenuItem in the menu diff --git a/src/Sylius/Behat/Resources/config/suites.yml b/src/Sylius/Behat/Resources/config/suites.yml index c4ba1b0fd87..561eb4cbcc1 100644 --- a/src/Sylius/Behat/Resources/config/suites.yml +++ b/src/Sylius/Behat/Resources/config/suites.yml @@ -74,6 +74,7 @@ imports: - suites/ui/admin/locale.yml - suites/ui/admin/login.yml - suites/ui/cart/shopping_cart.yml + - suites/ui/channel/channels.yml - suites/ui/channel/managing_channels.yml - suites/ui/channel/products_accessibility_in_multiple_channels.yml - suites/ui/channel/theming.yml diff --git a/src/Sylius/Behat/Resources/config/suites/api/channel/channels.yml b/src/Sylius/Behat/Resources/config/suites/api/channel/channels.yml new file mode 100644 index 00000000000..4c398b93437 --- /dev/null +++ b/src/Sylius/Behat/Resources/config/suites/api/channel/channels.yml @@ -0,0 +1,19 @@ +# This file is part of the Sylius package. +# (c) Paweł Jędrzejewski + +default: + suites: + ui_channels: + contexts: + - sylius.behat.context.hook.doctrine_orm + + - sylius.behat.context.transform.channel + + - sylius.behat.context.setup.channel + - sylius.behat.context.setup.product + + - sylius.behat.context.api.channel + - sylius.behat.context.api.shop.homepage + + filters: + tags: "@channels&&@api" diff --git a/src/Sylius/Behat/Resources/config/suites/ui/channel/channels.yml b/src/Sylius/Behat/Resources/config/suites/ui/channel/channels.yml new file mode 100644 index 00000000000..cec9bb22572 --- /dev/null +++ b/src/Sylius/Behat/Resources/config/suites/ui/channel/channels.yml @@ -0,0 +1,19 @@ +# This file is part of the Sylius package. +# (c) Paweł Jędrzejewski + +default: + suites: + ui_channels: + contexts: + - sylius.behat.context.hook.doctrine_orm + + - sylius.behat.context.transform.channel + + - sylius.behat.context.setup.channel + - sylius.behat.context.setup.product + + - sylius.behat.context.ui.channel + - sylius.behat.context.ui.shop.homepage + + filters: + tags: "@channels&&@ui" diff --git a/src/Sylius/Bundle/ChannelBundle/Doctrine/ORM/ChannelRepository.php b/src/Sylius/Bundle/ChannelBundle/Doctrine/ORM/ChannelRepository.php index 38811b0bc6e..bf0155b7497 100644 --- a/src/Sylius/Bundle/ChannelBundle/Doctrine/ORM/ChannelRepository.php +++ b/src/Sylius/Bundle/ChannelBundle/Doctrine/ORM/ChannelRepository.php @@ -24,6 +24,11 @@ public function findOneByHostname(string $hostname): ?ChannelInterface return $this->findOneBy(['hostname' => $hostname]); } + public function findOneEnabledByHostname(string $hostname): ?ChannelInterface + { + return $this->findOneBy(['hostname' => $hostname, 'enabled' => true]); + } + public function findOneByCode(string $code): ?ChannelInterface { return $this->findOneBy(['code' => $code]); diff --git a/src/Sylius/Component/Channel/Context/RequestBased/HostnameBasedRequestResolver.php b/src/Sylius/Component/Channel/Context/RequestBased/HostnameBasedRequestResolver.php index b155206fa3c..5d498054bbd 100644 --- a/src/Sylius/Component/Channel/Context/RequestBased/HostnameBasedRequestResolver.php +++ b/src/Sylius/Component/Channel/Context/RequestBased/HostnameBasedRequestResolver.php @@ -25,6 +25,6 @@ public function __construct(private ChannelRepositoryInterface $channelRepositor public function findChannel(Request $request): ?ChannelInterface { - return $this->channelRepository->findOneByHostname($request->getHost()); + return $this->channelRepository->findOneEnabledByHostname($request->getHost()); } } diff --git a/src/Sylius/Component/Channel/Repository/ChannelRepositoryInterface.php b/src/Sylius/Component/Channel/Repository/ChannelRepositoryInterface.php index 076d943b22d..b7169ebbd4b 100644 --- a/src/Sylius/Component/Channel/Repository/ChannelRepositoryInterface.php +++ b/src/Sylius/Component/Channel/Repository/ChannelRepositoryInterface.php @@ -18,8 +18,11 @@ interface ChannelRepositoryInterface extends RepositoryInterface { + /** @deprecated since Sylius 1.11, use the `findOneEnabledByHostname` method instead */ public function findOneByHostname(string $hostname): ?ChannelInterface; + public function findOneEnabledByHostname(string $hostname): ?ChannelInterface; + public function findOneByCode(string $code): ?ChannelInterface; /** diff --git a/src/Sylius/Component/Channel/spec/Context/RequestBased/HostnameBasedRequestResolverSpec.php b/src/Sylius/Component/Channel/spec/Context/RequestBased/HostnameBasedRequestResolverSpec.php index 26e1528ba31..4924827aa38 100644 --- a/src/Sylius/Component/Channel/spec/Context/RequestBased/HostnameBasedRequestResolverSpec.php +++ b/src/Sylius/Component/Channel/spec/Context/RequestBased/HostnameBasedRequestResolverSpec.php @@ -38,7 +38,7 @@ function it_finds_the_channel_by_request_hostname( ): void { $request->getHost()->willReturn('example.org'); - $channelRepository->findOneByHostname('example.org')->willReturn($channel); + $channelRepository->findOneEnabledByHostname('example.org')->willReturn($channel); $this->findChannel($request)->shouldReturn($channel); } @@ -49,7 +49,7 @@ function it_returns_null_if_channel_was_not_found( ): void { $request->getHost()->willReturn('example.org'); - $channelRepository->findOneByHostname('example.org')->willReturn(null); + $channelRepository->findOneEnabledByHostname('example.org')->willReturn(null); $this->findChannel($request)->shouldReturn(null); }