Skip to content

getProductUrl does not allow to override the scope in backend context #4247

@fetzi

Description

@fetzi

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.

Metadata

Metadata

Assignees

Labels

Component: CatalogFixed in 2.3.xThe issue has been fixed in 2.3 release lineIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentReproduced on 2.2.xThe issue has been reproduced on latest 2.2 releaseReproduced on 2.3.xThe issue has been reproduced on latest 2.3 release

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions