Magento2: getProductUrl does not allow to override the scope in backend context

Created on 21 Apr 2016  路  26Comments  路  Source: magento/magento2

Preconditions:

  1. Magento instance with several websites
  2. Each website has a specific domain (base url)

Steps to reproduce:

  1. Open a product page for a specific website in the admin area
  2. Use the $product->getProductUrl() method to retrieve product url

Expected result:

Returned product url relates to specified website

Actual result:

Magento always uses the 'admin' scope (and the default base url) to retrieve product url and returns incorrect url.

I'm trying to implement a custom indexer in Magento 2.0.4. The indexer should send product data to an external service. It is possible to get all store specific values of the product except the product url.

By calling the method $product->getProductUrl() I'm always retreiving the product's url with the admin storekey in it. (for example http://HOST/admin/catalog/product/view/...)

I've looked into the problem and the method getBaseUrl in Magento\Framework\Url offers the possiblity to override the url scope with the parameter _scope.

In backend context the subclass Magento\Backend\Model\Url is used and the call to _getScope() which is executed within the getBaseUrl() method always returns the admin store. Magento\Framework\Url::_getScope() uses the data value of scope instead.

I think that it should be possible to also override the scope in backend context.

Catalog Fixed in 2.3.x Format is valid Ready for Work Reproduced on 2.2.x Reproduced on 2.3.x

Most helpful comment

I have the same issue. There is no ability to retrieve product url for a specific website in the admin area.
Preconditions:

  • Magento instance (v2.1) with several websites
  • Each website has a specific domain (base url)

Steps to reproduce:

  • open a product page for a specific website in the admin area
  • use the $product->getProductUrl() method to retrieve product url

Result:
Magento always uses the 'admin' scope (and the default base url) to retrieve product url and returns incorrect url.

Stack trace:

  • Magento\Catalog\Model\Product\Url::getUrl() method, check out the code $this->getUrlInstance()->setScope($storeId)->getUrl($routePath, $routeParams)
  • Magento\Framework\Url::setScope() - here Magento sets a 'scope' variable in Data Object
  • Magento\Framework\Url::getBaseUrl() - for the product url Magento executes this method without any params
  • Magento\Backend\Model\Url::_getScope() - here Magento checks for the local '_scope' variable which always is null (while the 'scope' is located in the Data Object, Magento\Framework\Url::getData('scope')) and returns the 'admin' scope

Please reopen this ticket and fix this issue. Thanks.

All 26 comments

The GitHub issue tracker is intended for technical issues only. Please refer to the Community Forums or Magento Stack Exchange site for technical questions. In your case, the programming questions forum is likely the most appropriate. Feel free to reopen this issue if you think you have encountered a bug in Magento 2.

This is a technical issue. The method override _getScope() in Magento\Backend\Model\Url breaks the functionality of Magento\Framework\Url::getBaseUrl (which allows to set the scope of the url). Please reopen the ticket!

I have the same issue. There is no ability to retrieve product url for a specific website in the admin area.
Preconditions:

  • Magento instance (v2.1) with several websites
  • Each website has a specific domain (base url)

Steps to reproduce:

  • open a product page for a specific website in the admin area
  • use the $product->getProductUrl() method to retrieve product url

Result:
Magento always uses the 'admin' scope (and the default base url) to retrieve product url and returns incorrect url.

Stack trace:

  • Magento\Catalog\Model\Product\Url::getUrl() method, check out the code $this->getUrlInstance()->setScope($storeId)->getUrl($routePath, $routeParams)
  • Magento\Framework\Url::setScope() - here Magento sets a 'scope' variable in Data Object
  • Magento\Framework\Url::getBaseUrl() - for the product url Magento executes this method without any params
  • Magento\Backend\Model\Url::_getScope() - here Magento checks for the local '_scope' variable which always is null (while the 'scope' is located in the Data Object, Magento\Framework\Url::getData('scope')) and returns the 'admin' scope

Please reopen this ticket and fix this issue. Thanks.

Same issue here. Please reopen the ticket. @piotrekkaminski, please help.

Same issue as well.

@daim2k5, @piotrekkaminski,
Could you kindly reopen the ticket, it's a technical bug not a discussion topic for the forum.

reopening the ticket

Thanks @pboisvert!

@pboisvert Any update on the status of this issue? Thanks

@fetzi, thank you for your report.
We've created internal ticket(s) MAGETWO-84492 to track progress on the issue.

@magento-engcom-team Any update on this issue? :) It is a critical issue that should be fixed in 2.3 in my opinion. Lots of people affected by this.

Hi @milindsingh. Thank you for working on this issue.
Looks like this issue is already verified and confirmed. But if your want to validate it one more time, please, go though the following instruction:

  • [x] 1. Add/Edit Component: XXXXX label(s) to the ticket, indicating the components it may be related to.
  • [ ] 2. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento-engcom-team give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!

  • [ ] 3. Verify that the issue is reproducible on 2.2-develop branch.

    Details- Add the comment @magento-engcom-team give me 2.2-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.2-develop branch, please add the label Reproduced on 2.2.x

  • [ ] 4. If the issue is not relevant or is not reproducible any more, feel free to close it.

@magento-engcom-team give me 2.3-develop instance

Hi @irajneeshgupta. Thank you for your request. I'm working on Magento 2.3-develop instance for you

Hi @shikhamis11. Thank you for working on this issue.
Looks like this issue is already verified and confirmed. But if your want to validate it one more time, please, go though the following instruction:

  • [ ] 1. Add/Edit Component: XXXXX label(s) to the ticket, indicating the components it may be related to.
  • [ ] 2. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento-engcom-team give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!

  • [ ] 3. Verify that the issue is reproducible on 2.2-develop branch.

    Details- Add the comment @magento-engcom-team give me 2.2-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.2-develop branch, please add the label Reproduced on 2.2.x

  • [ ] 4. If the issue is not relevant or is not reproducible any more, feel free to close it.

@fetzi Please don't close this issue just because of frustration. 馃憥 This is a valid issue, and MUST be fixed. @magento-engcom-team Please take a closer look, it's a real issue that affects merchants.

Sorry, but after almost 3 years since ticket creation, I think this step is legit. The way the magento core team handles community issues forced me to stop working with magento.

You are free to open your own issue but I have absolutely no interest in this one any more.

@shikhamis11 Please re-open, or create a new ticket, or remove fetzi from this ticket. Also, as you've assigned this to yourself, would you please talk to your point of contact with Magento so this issue is finally taken care of?

@fetzi yes I know It's annoying to wait so long for any issue to be fixed but still I would suggest you to let this issue remain open this will be surely taken care of.

@ikk0 sure

Valid issues must not be closed even if author stopped working with Magento.

Hi @milindsingh. 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:

  • [ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.
  • [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • [ ] 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • [ ] 4. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento-engcom-team give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.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. Verify that the issue is reproducible on 2.2-develop branch.

    Details- Add the comment @magento-engcom-team give me 2.2-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.2-develop branch, please add the label Reproduced on 2.2.x

Hi @shikhamis11. 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:

  • [ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.
  • [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • [ ] 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • [ ] 4. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento-engcom-team give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.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. Verify that the issue is reproducible on 2.2-develop branch.

    Details- Add the comment @magento-engcom-team give me 2.2-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.2-develop branch, please add the label Reproduced on 2.2.x

  • [ ] 6. Add label Issue: Confirmed once verification is complete.

  • [ ] 7. Make sure that automatic system confirms that report has been added to the backlog.

Hi @Nazar65. 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:

  • [ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.
  • [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • [ ] 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • [ ] 4. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento-engcom-team give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.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. Verify that the issue is reproducible on 2.2-develop branch.

    Details- Add the comment @magento-engcom-team give me 2.2-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.2-develop branch, please add the label Reproduced on 2.2.x

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

The fix will be available with the upcoming 2.3.3 release.

Was this page helpful?
0 / 5 - 0 ratings