bug #14155 [BUG] The hostname resolver does not check for the channel status (lruozzi9, jakubtobiasz)

This PR was merged into the 1.11 branch.

Discussion
----------

| Q               | A                                                            |
|-----------------|--------------------------------------------------------------|
| Branch?         | 1.11 <!-- see the comment below -->          |
| Bug fix?        | yes                                                       |
| New feature?    | no                                                       |
| BC breaks?      | no                                                       |
| Deprecations?   | yes <!-- don't forget to update the UPGRADE-*.md file --> |
| Related tickets | continuation of #13697                      |
| License         | MIT                                                          |

<!--
 - Bug fixes must be submitted against the 1.10 or 1.11 branch(the lowest possible)
 - Features and deprecations must be submitted against the master branch
 - Make sure that the correct base branch is set

 To be sure you are not breaking any Backward Compatibilities, check the documentation:
 https://docs.sylius.com/en/latest/book/organization/backward-compatibility-promise.html
-->

What has been done:
- Updated behats (In my opinion now they're now a little bit more natural to read)
- I rebased the PR on top 1.11 and updated the `UPGRADE-1.11.md` and the `UPGRADE-1.10.md` files

We've had a discussion about parametrizing the `HostnameBasedRequestResolver` (what I've done btw 😂) but we decided to drop that idea and keep the original concept.

Thank you @lruozzi9 for your PR we could base on :). 


Commits
-------

28e39e27f7 [Channel] Do not consider disabled channel on hostname based request resolver
27406cdab9 Adjust behat scenarios
066cf33f4e Update UPGRADE files
351425d992 Update deprecation message
55edb2d3ca Remove redundant method
673eb912be Make filtering out scenario available in both ui and api contexts
This commit is contained in:
Mateusz Zalewski 2022-07-18 15:56:19 +02:00 committed by GitHub
commit 9c8395d149
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 119 additions and 3 deletions

View file

@ -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`.

View file

@ -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

View file

@ -39,6 +39,34 @@ final class HomepageContext implements Context
);
}
/**
* @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
*/

View file

@ -51,6 +51,22 @@ final class HomepageContext implements Context
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

View file

@ -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

View file

@ -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"

View file

@ -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"

View file

@ -24,6 +24,11 @@ class ChannelRepository extends EntityRepository implements ChannelRepositoryInt
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]);

View file

@ -25,6 +25,6 @@ final class HostnameBasedRequestResolver implements RequestResolverInterface
public function findChannel(Request $request): ?ChannelInterface
{
return $this->channelRepository->findOneByHostname($request->getHost());
return $this->channelRepository->findOneEnabledByHostname($request->getHost());
}
}

View file

@ -18,8 +18,11 @@ use Sylius\Component\Resource\Repository\RepositoryInterface;
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;
/**

View file

@ -38,7 +38,7 @@ final class HostnameBasedRequestResolverSpec extends ObjectBehavior
): 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 @@ final class HostnameBasedRequestResolverSpec extends ObjectBehavior
): void {
$request->getHost()->willReturn('example.org');
$channelRepository->findOneByHostname('example.org')->willReturn(null);
$channelRepository->findOneEnabledByHostname('example.org')->willReturn(null);
$this->findChannel($request)->shouldReturn(null);
}