Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX][Core][Checkout] Adding the isEnabled filter to the countries list in checkout while addressing. #15100

Open
wants to merge 2 commits into
base: 1.12
Choose a base branch
from

Conversation

christopherhero
Copy link
Contributor

This change restricts the list of available countries in the checkout->addressing step to those which are enabled.
Currently, when completing the address in checkout, all countries that are assigned to a channel are displayed, regardless of whether the country is enabled (country.enabled).

Q A
Branch? 1.12
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Related tickets X
License MIT

@christopherhero christopherhero requested a review from a team as a code owner June 14, 2023 13:36
@christopherhero christopherhero changed the title [FIX][ChannelBundle][CoreBundle] Adding the isEnabled filter to the l… [FIX][AddressingBundle][Core] Adding the isEnabled filter to the l… Jun 14, 2023
@christopherhero christopherhero changed the title [FIX][AddressingBundle][Core] Adding the isEnabled filter to the l… [FIX][AddressingBundle][Core] Adding the isEnabled filter to the countries list in checkout while addressing. Jun 14, 2023
@christopherhero christopherhero changed the title [FIX][AddressingBundle][Core] Adding the isEnabled filter to the countries list in checkout while addressing. [FIX][Core] Adding the isEnabled filter to the countries list in checkout while addressing. Jun 14, 2023
@christopherhero christopherhero changed the title [FIX][Core] Adding the isEnabled filter to the countries list in checkout while addressing. [FIX][Core][Checkout] Adding the isEnabled filter to the countries list in checkout while addressing. Jun 14, 2023
@jakubtobiasz jakubtobiasz added the Potential Bug Potential bugs or bugfixes, that needs to be reproduced. label Jun 22, 2023
@vvasiloi
Copy link
Contributor

Hey @christopherhero, could you please also cover this:

if ($channel->getCountries()->count() > 0) {
$rootAlias = $queryBuilder->getRootAliases()[0];
$queryBuilder
->andWhere(sprintf('%s.id in (:%s)', $rootAlias, $countriesParameterName))
->setParameter($countriesParameterName, $channel->getCountries())


public function getEnabledCountries(): Collection
{
return $this->getCountries()->filter(fn (CountryInterface $country): bool => true === $country->isEnabled());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about using criteria matching?

Suggested change
return $this->getCountries()->filter(fn (CountryInterface $country): bool => true === $country->isEnabled());
return $this->getCountries()->matching(new Criteria(Criteria::expr()->eq('enabled', true)));

Copy link
Contributor

@vvasiloi vvasiloi Jun 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now the channel countries have eager fetch configured, but it might change in #14286

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about using criteria matching?

Following simpler is better paradigm, filter might be more readable and more common occurrence in the source codes, there is only single matching() in the whole codebase.

return $zoneMembers->matching(Criteria::create()->where(Criteria::expr()->eq('code', $code)))->first();

Right now the channel countries have eager fetch configured, but it might change in #14286

Should it be replaced with $countryRepository->findEnabledForChannel instead?

Copy link
Contributor Author

@christopherhero christopherhero Sep 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be replaced with $countryRepository->findEnabledForChannel instead?

What you mean ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for PR @vvasiloi !

For me the filter is more consistent with the rest of the code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@christopherhero in case of bigger collection relations, it's more optimal to make repository call instead of processing collection directly, but that's more of theoretical question what should be done for EAGER removal, if it will happen.

@diimpp
Copy link
Member

diimpp commented Sep 12, 2023

I've reproduced the issue, it can be re-tagged as bug. /cc @jakubtobiasz

  1. Select few countries for a channel
    image
  2. Start checkout addressing step and see only previously selected countries as available countries list as expected.
    image
  3. Disable one of the countries, repeat checkout addressing step, it continues to show both enabled and disabled countries list instead of showing only enabled countries.
    image
    image

@christopherhero
Copy link
Contributor Author

christopherhero commented Sep 14, 2023

Hey @christopherhero, could you please also cover this:

if ($channel->getCountries()->count() > 0) {
$rootAlias = $queryBuilder->getRootAliases()[0];
$queryBuilder
->andWhere(sprintf('%s.id in (:%s)', $rootAlias, $countriesParameterName))
->setParameter($countriesParameterName, $channel->getCountries())

@vvasiloi I will prepare another PR with the fix for the API.
In a few more places we could have used getEnabledCountries instead of getCountries but in this PR I focused solely on fixing this case described by @diimpp

@jakubtobiasz jakubtobiasz added Bug Confirmed bugs or bugfixes. and removed Potential Bug Potential bugs or bugfixes, that needs to be reproduced. labels Sep 15, 2023
@diimpp
Copy link
Member

diimpp commented Sep 29, 2023

PR looks good code-wise, but I wonder should there be a scenario to cover those cases?

On separate note,

  • Administrator might wonder why channel has a country, but it's not showing up in checkout
  • What about address book, if previously saved country is no longer available, but address is applied to checkout? (Does address book respect countries list per channel at all?)
  • Should address book page hide address for disabled country or indicate unavailability somehow else?
  • Is there a validation for applied countries in checkout?
  • How zones treat disabled countries?
  • Already mentioned api checkout

It sounds like too many places needs to be modified to handle disabled counties within relation.
As an idea, what about disallowing disabling countries, if country is in use? It's a simpler coding solution, but not a great administrator experience, when country might be in use by tens of zones and several channels, one might want to exclude country with single click. (And still will require a solution for address book)

…ist of countries in the addressing step on the cart

- add test case to cover "getEnabledCountries" method
… `getCountries` in Sylius\Bundle\CoreBundle\Form\Extension\AddressTypeExtension
@TheMilek TheMilek force-pushed the issue_enabled_cart_countries branch from fe68689 to 33274bd Compare January 3, 2024 22:55
Copy link

github-actions bot commented Jan 3, 2024

Bunnyshell Preview Environment deployed

It will be automatically stopped in 4 hours.

Use the command /bns:start to start it if it's stopped.

Component Endpoints
mailhog https://mailhog-5a6ytu.bunnyenv.com/
php https://store-5a6ytu.bunnyenv.com/

Available commands:

  • /bns:stop to stop the environment
  • /bns:deploy to redeploy the environment
  • /bns:delete to remove the environment

Comment on lines +94 to +96
* @return Collection|CountryInterface[]
*
* @psalm-return Collection<array-key, CountryInterface>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since psalm was dropped from the project

Suggested change
* @return Collection|CountryInterface[]
*
* @psalm-return Collection<array-key, CountryInterface>
* @return Collection<array-key, CountryInterface>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Confirmed bugs or bugfixes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants