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

No ability to switch Store View. Store cookie not deleted for default store views with multistore setup. #37666

Closed
3 of 9 tasks
artmouse opened this issue Jun 26, 2023 · 6 comments
Assignees
Labels
Issue: needs update Additional information is require, waiting for response Reported on 2.4.6-p1 Indicates original Magento version for the Issue report. Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it

Comments

@artmouse
Copy link

artmouse commented Jun 26, 2023

Preconditions and environment

A vanilla installation of Magento 2.4.6-p1 with default settings.

  1. Set up Magento 2 multiple websites in sub directories
  2. The site exists and opens as / by default.
  3. The default language of the site is English.
  4. You need to add German language to the site (set up the multi-language store).
  5. The German language should be available as /de/.
  6. Setup instruction
  7. In the future the German store should open by default. (Make the German Store View the default).

Stores and Web Site Configuration:

Web Site information:

  • Name: Main Website
  • Code: base
  • Sort Order: 0
  • Default Store: Main Website Store

Store information:

  • Name: Main Website Store
  • Code: main_website_store
  • Root Category: Default Category
  • Default Store View: English

Steps to reproduce

Add second Store View and change the values of the main Store View for clarity

English Store View (default) information:

  • Store: Main Website Store
  • Name: English
  • Code: en
  • Status: enabled
  • Sort Order: 10

German Store View information:

  • Store: Main Website Store
  • Name: German
  • Status: enabled
  • Code: de
  • Sort Order: 20

For the German store, you need to create a subdirectory in the pub, so that it can be accessed at /de/ and assign a proper URL.

  • Create a subdirectory /de/ in the pub.
  • Place the modified index.php in /de/ directory
+$params = $_SERVER;  
+$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'de';
+$params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'store';  
+$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params);
-$bootstrap = Bootstrap::create(BP, $_SERVER);
  • Allow NGINX to execute index.php file from the /de/ directory.
# PHP entry point for main application
+location ~ (index|get|static|errors/report|errors/404|errors/503|health_check)\.php$ {
-location ~ ^/(index|get|static|errors/report|errors/404|errors/503|health_check)\.php$ {

For Static and Media View Files, you will need to globally change the URL to something like this: https//domain.com/static/(media/) so that the styles would be available in /de/ as well.

  • Stores -> Configuration -> General -> Web (Scope: Default Config)
    • Base URLs
      • Base URL for Static View Files: https//domain.com/static/
      • Base URL for User Media Files: https//domain.com/media/
    • Base URLs (Secure)
      • Secure Base URL for Static View Files: https//domain.com/static/
      • Secure Base URL for User Media Files https//domain.com/media/

Specify a URL for the German store with the prefix /de/.

  • Stores -> Configuration -> General -> Web (Scope: German Store View)
    • Base URLs
      • Base Link URL: https//domain.com/de/
    • Base URLs (Secure)
      • Base Link URL: https//domain.com/de/

Change the main Store View for Store to German. (make it default)

  • Stores -> Settings -> All Stores -> Store (Main Website Store)
    • Change Default Store View: en -> de

Going to the site...

  • Now by default we are redirected to /de/ and the site opens in German (Default, Store View Code: de). Great!
  • The site also displays a language switcher.
  • Switching to English (Store View Code: en) - redirect to / and the language changes.
  • Switch back to German (Default, Store View Code: de) - redirect to /de/ but language does not change, English remains. In the same way all store URLs without the prefix /de/.

Expected result

There is no "store" cookie for the primary Store View.
When the primary Store View (de) is located on the /de/ path and when you switch to another Store View (en) that is located on the / path, the "store" cookie is set for the target Store View (en).

Name Value Domain Path
store en .domain.com /

And when switching from another Store View (en) when the "store" cookie is already set, it checks to match the target Store View ID with the default Store View ID.
If there is a match, the "store" cookie should be removed.

public function switch(StoreInterface $fromStore, StoreInterface $targetStore, string $redirectUrl): string
{
$defaultStoreView = $this->storeManager->getDefaultStoreView();
if ($defaultStoreView !== null) {
if ($defaultStoreView->getId() === $targetStore->getId()) {
$this->storeCookieManager->deleteStoreCookie($targetStore);
} else {
$this->httpContext->setValue(Store::ENTITY, $targetStore->getCode(), $defaultStoreView->getCode());
$this->storeCookieManager->setStoreCookie($targetStore);
}
}
return $redirectUrl;
}

But when try to delete the store cookie in $cookieMetadata set the path /de, but existing "store" cookie has path /.

public function deleteStoreCookie(StoreInterface $store)
{
$cookieMetadata = $this->cookieMetadataFactory->createPublicCookieMetadata()
->setPath($store->getStorePath());
$this->cookieManager->deleteCookie(self::COOKIE_NAME, $cookieMetadata);
}

getStorePath() returns /de, but the "store" cookie has a path / - perhaps because of this the "store" en cookie is not deleted and the site always stays on Store View (en)

public function getStorePath()
{
// phpcs:ignore Magento2.Functions.DiscouragedFunction
$parsedUrl = parse_url($this->getBaseUrl());
return $parsedUrl['path'] ?? '/';
}

Actual result

  1. When the primary Store View (de) is located on the /de/ path and when you switch to another Store View (en) that is located on the / path, the "store" cookie is set for the target Store View (en).
  2. And when switching from another Store View (en) when the "store" cookie is already set, it checks to match the target Store View with the default Store View ID.
  3. If there is a match, the "store" cookie should be removed.

Additional information

Similar problem: #8509

Release note

No response

Triage and priority

  • Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.
@m2-assistant
Copy link

m2-assistant bot commented Jun 26, 2023

Hi @artmouse. Thank you for your report.
To speed up processing of this issue, make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:


Join Magento Community Engineering Slack and ask your questions in #github channel.
⚠️ According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.
🕙 You can find the schedule on the Magento Community Calendar page.
📞 The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.

@engcom-Bravo engcom-Bravo added Reported on 2.4.x Indicates original Magento version for the Issue report. Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it labels Jun 26, 2023
@engcom-November engcom-November self-assigned this Jul 13, 2023
@m2-assistant
Copy link

m2-assistant bot commented Jul 13, 2023

Hi @engcom-November. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: 👇

  • 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
  • 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue.
  • 3. Add Area: XXXXX label to the ticket, indicating the functional areas it may be related to.
  • 4. Verify that the issue is reproducible on 2.4-develop branch
    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!
  • 5. Add label Issue: Confirmed once verification is complete.
  • 6. Make sure that automatic system confirms that report has been added to the backlog.

@engcom-November
Copy link
Contributor

Hello @artmouse,

Thanks for the report and collaboration!

We have tried to reproduce the issue in 2.4-develop instance via the following link.
https://experienceleague.adobe.com/docs/commerce-operations/configuration-guide/multi-sites/ms-admin.html

In order to reproduce this issue we have cretaed two store views, en and de and make de as default store view.
We are able to get the expected result, for de store there is no cookie but for en store cookie is there, Please have a look at the scrreenshot below:
For de store there is no cookie
image

Fot en store cookie is visible with name store
image

Please let us know if we missed anything in order to reproduce the issue.

Thanks.

@engcom-November engcom-November added the Issue: needs update Additional information is require, waiting for response label Jul 13, 2023
@engcom-November engcom-November added Reported on 2.4.6-p1 Indicates original Magento version for the Issue report. and removed Reported on 2.4.x Indicates original Magento version for the Issue report. labels Jul 13, 2023
@artmouse
Copy link
Author

You didn't read the description carefully.
Here the specific task is not to use store codes, but to use subdirectories instead.
Main storeview /de/
Second storeview /

@engcom-November
Copy link
Contributor

Hello @artmouse,

Thank you for your quick response!

As I can understand with the main desription, you need to setup multistore/multiwebsite in your magento instance.
For this you can follow the below official documetnation provided by magento.
https://experienceleague.adobe.com/docs/commerce-operations/configuration-guide/multi-sites/ms-admin.html

If you still want to setup store views in sub directories via following the below link :
instruction

You need to provide us the use case for the same.

Thank you.

@engcom-November
Copy link
Contributor

Hello @artmouse,

We have noticed that this issue has not been updated since long time.
Hence we assume that the issue is fixed now, so we are closing it. Please feel free to raise a new one or reopen this issue if you need more assistance.

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue: needs update Additional information is require, waiting for response Reported on 2.4.6-p1 Indicates original Magento version for the Issue report. Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it
Projects
None yet
Development

No branches or pull requests

3 participants