Skip to content

issue/26384 Fix store switcher when using different base url on stores #26548

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

Merged
merged 12 commits into from
Feb 28, 2020

Conversation

TobiasLufinity
Copy link
Contributor

@TobiasLufinity TobiasLufinity commented Jan 27, 2020

Description (*)

When a user switches between stores using the store switcher the request fails if the target store has a different base url than the current. This pull request changes the redirect controller to make the switch request using the targeted store' url instead so the switch is successful.

Fixed Issues (if relevant)

  1. Fixes Store switcher redirects to homepage for multistore setup with different domains #26384 : Store switcher redirects to homepage for multistore setup with different domains
  2. Fixes Store view switcher is wrong , when each store views have different url. #23755 : Store view switcher is wrong , when each store views have different url.

Manual testing scenarios (*)

  1. Have simple Magento 2.4-dev setup with sampledata
  2. Create two or more stores with different base url (i.e default.magento.dev and en.magento.dev)
  3. Go to a category page of one store
  4. Switch between the stores using the store switcher

Result without fix: You end up on the start page, without switched store and not the category on which you were on.
Result with fix: Store is switched and you stay in the same page you were on

Questions or comments

No automated tests has been created for this pull request

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds are green)

@m2-assistant
Copy link

m2-assistant bot commented Jan 27, 2020

Hi @TobiasCodeNull. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

For more details, please, review the Magento Contributor Guide documentation.

@edenduong edenduong self-assigned this Jan 31, 2020
@edenduong edenduong added Component: Store Auto-Tests: Not Covered Changes in Pull Request requires coverage by auto-tests labels Jan 31, 2020
Copy link
Contributor

@edenduong edenduong left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution. Please see my comment. And could you please cover your change by Automation Test? Thank you !

@@ -53,12 +60,14 @@ public function __construct(
StoreResolverInterface $storeResolver,
\Magento\Framework\Session\Generic $session,
\Magento\Framework\Session\SidResolverInterface $sidResolver,
HashGenerator $hashGenerator
HashGenerator $hashGenerator,
StoreManagerInterface $storeManager
Copy link
Contributor

Choose a reason for hiding this comment

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

Please change it to StoreManagerInterface $storeManager = null for backward compatible
https://devdocs.magento.com/guides/v2.3/contributor-guide/backward-compatible-development/

) {
parent::__construct($context);
$this->storeRepository = $storeRepository;
$this->storeResolver = $storeResolver;
$this->hashGenerator = $hashGenerator;
$this->storeManager = $storeManager;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please change to$this->storeManager = $storeManager ?? ObjectManager::getInstance()->get(StoreManagerInterface::class); for backward compatible
https://devdocs.magento.com/guides/v2.3/contributor-guide/backward-compatible-development/

@TobiasLufinity
Copy link
Contributor Author

Simple test made which goes through the controller and make sure that the StoreManager change to the correct store.
Also added the backwards compatibility for the controller.

Copy link
Contributor

@edenduong edenduong left a comment

Choose a reason for hiding this comment

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

Hi. Please add use ... to your code and add some const. Thanks.

*/
protected function setUp()
{
$this->storeManagerMock = $this->getMockBuilder(\Magento\Store\Model\StoreManagerInterface::class)->getMock();
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use Magento\Store\Model\StoreManagerInterface; in all similar class and use the Alias.

*/
public function testExecute()
{
$storeToSwitchToCode = 'sv2';
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add the const const STUB_STORE_TO_SWITCH_TO_CODE = 'sv2'; and const STUB_DEFAULT_STORE_VIEW = 'default';

@TobiasLufinity
Copy link
Contributor Author

Cleaned up code and added Const values.

@engcom-Charlie engcom-Charlie self-assigned this Feb 11, 2020
@edenduong
Copy link
Contributor

Cleaned up code and added Const values.

Hi @TobiasCodeNull. Please resolve the confict code. And please use the alias in the DocBlock also.

@engcom-Charlie
Copy link
Contributor

Hi, @edenduong I'll take care of this.

@TobiasLufinity
Copy link
Contributor Author

I'll leave this to @engcom-Charlie then

@engcom-Charlie engcom-Charlie added the Auto-Tests: Covered All changes in Pull Request is covered by auto-tests label Feb 11, 2020
@engcom-Charlie engcom-Charlie removed the Auto-Tests: Not Covered Changes in Pull Request requires coverage by auto-tests label Feb 11, 2020
@magento-engcom-team
Copy link
Contributor

Hi @edenduong, thank you for the review.
ENGCOM-6869 has been created to process this Pull Request

@magento-engcom-team
Copy link
Contributor

@TobiasCodeNull thank you for contributing. Please accept Community Contributors team invitation here to gain extended permissions for this repository.

@engcom-Delta
Copy link
Contributor

✔️ QA passed

@m2-assistant
Copy link

m2-assistant bot commented Feb 28, 2020

Hi @TobiasCodeNull, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

@viktym
Copy link
Contributor

viktym commented Sep 22, 2020

For Magento versions 2.3.0 - 2.3.5 patch is available in Magento Quality Patches package (MQP)

MQP Installation
$ composer require magento/quality-patches

Applying a Patch
$ ./vendor/bin/magento-patches apply MDVA-30107

Patch Details
https://support.magento.com/hc/en-us/articles/360049869051

@sdzhepa sdzhepa mentioned this pull request May 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants