-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Calling getCurrentUrl on Store will wrongly add "___store" parameter #18941 #19135
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
Calling getCurrentUrl on Store will wrongly add "___store" parameter #18941 #19135
Conversation
Hi @Nazar65. Thank you for your contribution
For more details, please, review the Magento Contributor Assistant documentation |
Hi @larsroettig I'm found a better solution for this issue, please look to the newly commit, now the method getCurrentUrl() returns correct value from second store. |
Any update on this? |
Hi @larsroettig can you review ? |
Hi @Nazar65, I will test it in the evening today 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change looks good. One thing can you please cover this change with an Integration-Test:
dev/tests/integration/testsuite/Magento/Store/Model/StoreTest.php
@larsroettig, yes sure. |
HI @larsroettig all done. |
@Nazar65 the static test will fail https://github.com/magento/magento2/pull/19135/files#diff-feec83996906a9185b3d53fb67ab74a1R285 ;-) Empty Line to mutch :-) |
Fix static test
@larsroettig oops, fixed :) |
✅ Code Review |
Hi @Nazar65 , thanks for the contribution! I just would like to clarify the following: As I can see from the issue description - the expected result is to get an URL that is specific to store but without any "___store" parameters, when requesting a store url in scope of different store having Is there a way to prevent adding a For example, do you think the implementation in https://github.com/magento/magento2/blob/2.3-develop/app/code/Magento/Store/Url/Plugin/RouteParamsResolver.php#L81 is correct? |
Hi @sivaschenko I tried to do without it, but it was used in many ways, in the described problem, this method was not adapted for the option "Use store in url", so it was duplicated twice. Then, without this option, if we disable "use store in url" the parameters we will get an address without the title of the bar. So the problem is simple, we don't need duplicate store code, but the best solution its to leave the functional as it was planned |
@sivaschenko also this method give you a link like this -> http://localhost/index.php?___store=fixture_second_store&___from_store=default i think this is important |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Nazar65 thank you for the contribution! However, I think we should avoid cutting pieces out of urls generated within the same framework. It would be much better to prevent adding unwanted content to urls in the first place.
I wonder if adding an exclamation mark "!" to the beginning of https://github.com/magento/magento2/blob/2.3-develop/app/code/Magento/Store/Url/Plugin/RouteParamsResolver.php#L81 condition is something that can help to fix the problem.
Also, it would be great to cover such changes with an integration test without mocking the Url model (as currently it looks more like unit test that is covering only the specific method and not url generation system as a whole)
@@ -1169,6 +1169,10 @@ public function getCurrentUrl($fromStore = true) | |||
|
|||
$storeUrl = $this->getUrl('', ['_secure' => $this->_storeManager->getStore()->isCurrentlySecure()]); | |||
|
|||
if ($this->_config->getValue(self::XML_PATH_STORE_IN_URL)) { | |||
$storeUrl = preg_replace('/\/'.$this->getCode().'{1}/','',$storeUrl); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Considering that URL is generated in Magento framework, not passed from outside, can you please reorganize the code to prevent adding store code to the URL instead of cutting it off after it is added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Method getUrl add parameters to url for specified scope, $url = $this->_url->setScope($this);
Is this right to change this on getUrl method?
dev/tests/integration/testsuite/Magento/Store/Model/StoreTest.php
Outdated
Show resolved
Hide resolved
@LucaGallinari as an author of the issue, can you please provide your feedback on the fix currently provided. Would removing the store code from URL instead of removing the store URL parameter resolve the issue? |
@sivaschenko so after add your "!" in "use store in url = 0" we have links like this -> http://magento23dev.vg/?___store=second&___from_store=default also this "!" removed # Method $product->getUrlInStore() returning extremely long URLs, could be a bug seems like "!" not related to the issue that was fixed, so we can just add the mark "!", this will solve this issue. |
@Nazar65 thanks for the details, I think that Considering that store code is added to URL when "use store in url = 1" in Store model I think we shouldn't add it second time (when "use store in url = 1") even if it is requested by In case Also, there are other places around the application where the Store code is also retrieved from app/code/Magento/Store/App/Action/Plugin/Context.php However, store resolver is trying to retrieve store code from URL before getting it from parameter: So we need to ensure that removing |
I commented on the original issue, I totally agree with @LucaGallinari and @sivaschenko on restoring the exclamation mark before $useStoreInUrl. From the comments on #16310 , $useStoreInUrl was misunderstood, and not tested when set to yes. That's why we should revert that line and use This should be the only action needed. |
Hi everyone, first of all thank you very much for working on this issue. |
Hi @Thundar thank you for details, @sivaschenko so the best way is to revert mark "!" can we do that ? |
This reverts commit ccba420
@sivaschenko all done :-) |
@Nazar65 considering the global effect of the changes it would be great if you can cover them with integration test. |
@sivaschenko Ok, but i'm already cover this changes with integration test, which scenario i need to cover ? |
@Nazar65 sorry, I mean the case when |
Hi @sivaschenko, i cover changes with integration test, for all places where is used "__store". |
Hi @sivaschenko, thank you for the review. |
@sivaschenko I fixed: failed static tests, and unit. |
@Nazar65 thank you |
Hi @Nazar65. Thank you for your contribution. |
Hi @sivaschenko! If I understand it correctly, we as a community can no longer send in backports to the 2.1 release line, so I'm wondering if this one is on Magento's list for backporting themselves? Thanks! |
Description (*)
I have the config "store code in URL" set to "yes" but when i use the method "getCurrentUrl" on a Store type variable i get the current URL but with the parameter "___store=[code]" in it, if the current store is not the one requested in the URL.
I want to use the getCurrentUrl method in order to redirect the user to the correct store based on some custom logic (like the browser language), but i don't want any additional parameters to be in the URL.
Form what i found out by looking around in the code, the parameter "___store" is mandatory when the config "use store code in URL" is set to "no" but not when it's set to "yes", as in my case. The store code is already in the URL (as set in system config) and it's not necessary to add any other parameters in the URL to remark this.
Fixed Issues (if relevant)
Manual testing scenarios (*)
Contribution checklist (*)