magento2: getProductUrl does not allow to override the scope in backend context
Preconditions:
- Magento instance 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
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.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 2
- Comments: 26 (13 by maintainers)
Commits related to this issue
- Merge pull request #4247 from magento-qwerty/MAGETWO-99817 Fixed Issues: - MAGETWO-99817: Remove new dependencies added for design edit validations — committed to magento/magento2 by dvoskoboinikov 5 years ago
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.
I have the same issue. There is no ability to retrieve product url for a specific website in the admin area. Preconditions:
Steps to reproduce:
$product->getProductUrl()method to retrieve product urlResult: 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 ObjectMagento\Framework\Url::getBaseUrl()- for the product url Magento executes this method without any paramsMagento\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’ scopePlease reopen this ticket and fix this issue. Thanks.