magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.56k stars 9.32k forks source link

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

Closed artmouse closed 1 year ago

artmouse commented 1 year ago

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:

Store information:

Steps to reproduce

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

English Store View (default) information:

German Store View information:

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.

+$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);
# 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.

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

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

Going to the site...

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.

https://github.com/magento/magento2/blob/35e8e434be0b21072382b3f91c71678efc0242c1/app/code/Magento/Store/Model/StoreSwitcher/ManageStoreCookie.php#L58-L71

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

https://github.com/magento/magento2/blob/35e8e434be0b21072382b3f91c71678efc0242c1/app/code/Magento/Store/Model/StoreCookieManager.php#L72-L78

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)

https://github.com/magento/magento2/blob/35e8e434be0b21072382b3f91c71678efc0242c1/app/code/Magento/Store/Model/Store.php#L1373-L1378

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: https://github.com/magento/magento2/issues/8509

Release note

No response

Triage and priority

m2-assistant[bot] commented 1 year ago

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:

m2-assistant[bot] commented 1 year ago

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: :point_down:

engcom-November commented 1 year ago

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.

artmouse commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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.