Magento2: Method $product->getUrlInStore() returning extremely long URLs, could be a bug

Created on 20 Jun 2018  ·  7Comments  ·  Source: magento/magento2

I feel like there may be a bug in the following file because the output of $product->getUrlInStore() is not what I'd expect. Query params related to the store are added to the URL in the following file:

https://github.com/magento/magento2/blob/9c14af7a97bcf338662de365d2613c7ca9dbf8c6/app/code/Magento/Store/Url/Plugin/RouteParamsResolver.php#L66

By setting an entire object ($subject->getScope()) as the $storeCoderather than just a string default it is causing a very messy looking URL.

Preconditions

  1. Have a Magento installation with more than 1 store
  2. Add store code to URLs in configuration is set to "no"
  3. Magento version 2.2.3

Steps to reproduce

Use the following code where a product model is loaded and where you can see the result:

<?= $product->getUrlInStore() ?>

Expected result

The URL produced for the product would look like:

https://www.domain.com/my-product.html?___store=default

Actual result

The URL produced is actually very long winded:

https://www.domain.com/my-product.html?___store%5B_data%5D%5Bstore_id%5D=1&___store%5B_data%5D%5Bcode%5D=default&___store%5B_data%5D%5Bwebsite_id%5D=1&___store%5B_data%5D%5Bgroup_id%5D=1&___store%5B_data%5D%5Bname%5D=UK+Mainland&___store%5B_data%5D%5Bsort_order%5D=0&___store%5B_data%5D%5Bis_active%5D=1&___store%5B_data%5D%5Bavailable_currency_codes%5D%5B0%5D=GBP&___store%5B_data%5D%5Bbase_currency%5D%5B_data%5D%5Bcurrency_code%5D=GBP&___store%5B_data%5D%5Bcurrent_currency%5D%5B_data%5D%5Bcurrency_code%5D=GBP
Fixed in 2.1.x Fixed in 2.2.x Fixed in 2.3.x Format is valid Reproduced on 2.1.x Reproduced on 2.2.x Reproduced on 2.3.x bug report

All 7 comments

This can be reproduced on Magento 2.3-develop as well.
And actually from steps to reproduce there is another bug: Having _Add store code to URLs_ set to NO, still shows you the URL like https://www.domain.com/my-product.html?___store=default.

According to the file /app/code/Magento/Store/Url/Plugin/RouteParamsResolver.php and its content, this issue is reproducible on Magento 2.2-develop and Magento 2.1-develop.

Hi @adampmoss. Thank you for your report.
The issue has been fixed in magento/magento2#16468 by @vasilii-b in 2.2-develop branch
Related commit(s):

The fix will be available with the upcoming 2.2.6 release.

Hi @adampmoss. Thank you for your report.
The issue has been fixed in magento/magento2#17261 by @mage2pratik in 2.3-develop branch
Related commit(s):

The fix will be available with the upcoming 2.3.0 release.

@magento-engcom-team , @sidolov hello!!!
there was already a PR created for 2.3-develop - https://github.com/magento/magento2/pull/16309, earlier than one already merged #17261. 😱 what is going on, guys ? Should we check first if issue/PR already created ? 🤦‍♂️
that is totally unfair...

Hi @adampmoss. Thank you for your report.
The issue has been fixed in magento/magento2#16310 by @vasilii-b in 2.1-develop branch
Related commit(s):

The fix will be available with the upcoming 2.1.16 release.

The issue has been reintroduced in commit 22edbb904ae3856afbf871cc6e196edbd3bb679b. The commit is supposed to revert "Customer related values are NULL for guests" ccba42089f1ca465cb43fc60339671db5e9a504a but it actually reverts this fix (at least partly)

Was this page helpful?
0 / 5 - 0 ratings