Skip to content
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

[2.1] Unable to get store URL from admin #5322

Closed
acharrex opened this issue Jun 28, 2016 · 31 comments
Closed

[2.1] Unable to get store URL from admin #5322

acharrex opened this issue Jun 28, 2016 · 31 comments
Labels
bug report Component: Framework/Code Component: Url Event: dmcdindia1 Event: mm19br Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Priority: P3 May be fixed according to the position in the backlog. Progress: done Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround. stale issue Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it

Comments

@acharrex
Copy link

acharrex commented Jun 28, 2016

Preconditions (*)

Magento 2.4-develop

Steps to reproduce (*)

  1. Install Magento from develop branch.
  2. Run the following code from the admin area (by example from a controller):
$url = $this->_objectManager->get('Magento\Store\Model\StoreManagerInterface')
    ->getStore(1) // 1 = default store id
    ->getUrl('myroute')

echo $url;

Expected result (*)

http://mymagentoshop.local/myroute

Actual result (*)

Magento returns an URL prefixed with the admin path:

http://mymagentoshop.local/admin_XXXX/myroute

Note

The following code:

$url = $this->_objectManager->get('Magento\Store\Model\StoreManagerInterface')
    ->getStore($customer->getStoreId())
    ->getBaseUrl();

Works correctly:

http://mymagentoshop.local/

This problem seems to be limited to the "getUrl" method.

This issue was not present with Magento 2.0.7.

@acharrex acharrex changed the title [2.1] Unable get store URL from admin [2.1] Unable to get store URL from admin Jun 28, 2016
@sfedosimov
Copy link

I have the same issue on Magento 2.1.3

@Rabot18
Copy link

Rabot18 commented Feb 20, 2017

Same problem here, up

@sfedosimov
Copy link

sfedosimov commented Feb 20, 2017

Solution (in controller):
$this->url->setScope($this->storeManager->getWebsite($customer->getWebsiteId())->getDefaultStore());

@Rabot18
Copy link

Rabot18 commented Feb 20, 2017

I use it in a class who extends AbstractHelper so i used _urlBuilder like this instead of StoreManagerInterface :

$this->_urlBuilder->setScope($storeId);
return $this->_urlBuilder->getUrl('myurl/action', $defaultParams);

thx @sfedosimov

@choukalos choukalos removed their assignment Feb 21, 2017
@perryholden
Copy link

perryholden commented May 1, 2017

Still an issue as of 2.1.4. In the backend, I get the store from a particular order, and then try to generate a URL for that store:

/** @var \Magento\Store\Model\Store $orderStore */
$orderStore = $this->storeManager->getStore($order->getStore()->getId());
$storeUrl = $orderStore->getUrl('controlleraction');

Expected: https://store.domain.com/controlleraction/...
Result: https://www.domain.com/backend/controlleraction/...

I find that sometimes if I flush the cache, I get the correct URL, but after a while, it returns to the incorrect backend URL.

@perryholden
Copy link

A workaround to get a frontend URL for a store in the backend:

See how Magento is generating the "View" link in the CMS page admin grid via its page actions: Magento\Cms\Ui\Component\Listing\Column\PageActions. It injects the following class in order to build the URL: Magento\Cms\Block\Adminhtml\Page\Grid\Renderer\Action\UrlBuilder, which uses \Magento\Framework\UrlInterface. Well, that UrlInterface has a frontend model and a backend model.

In the CMS module's etc/adminhtml/di.xml, it injects the frontend URL model for that interface:

<type name="Magento\Cms\Block\Adminhtml\Page\Grid\Renderer\Action\UrlBuilder">
    <arguments>
        <argument name="frontendUrlBuilder" xsi:type="object">Magento\Framework\Url</argument>
    </arguments>
</type>

If you don't do this, no matter how you pass it the proper scope, it always resets that scope after getting the base URL. Not good.

Anyhow, I was able to get it working then by doing what Magento\Cms\Block\Adminhtml\Page\Grid\Renderer\Action\UrlBuilder is doing, and using di.xml to pass it the proper URL model. Nevertheless, this should be fixed. There is no reason why I shouldn't be able to just call getUrl() from a store model in the backend.

@magento-engcom-team magento-engcom-team added Application Framework bug report Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed labels Sep 11, 2017
@nmalevanec nmalevanec added the Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed label Nov 29, 2017
@magento-engcom-team
Copy link
Contributor

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

@magento-engcom-team magento-engcom-team added 2.1.x Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release labels Nov 29, 2017
@ashokbhati180
Copy link

I found an issue in magento 2 that it does not load get store URL when cache is enabled . that I am working on magento 2 and my cache is disabled and its working properly but if i enable cache then It redirect to store id 1 always and i did not found my store URL

@magento-engcom-team magento-engcom-team added the Event: distributed-cd Distributed Contribution Day label Mar 19, 2018
@magento-engcom-team magento-engcom-team removed the Event: distributed-cd Distributed Contribution Day label Apr 13, 2018
@m2-community-project m2-community-project bot moved this from Ready for Development to Dev In Progress in Low Priority Backlog Sep 24, 2020
@ghost ghost unassigned shikhamis11 Oct 8, 2020
@m2-community-project m2-community-project bot moved this from Dev In Progress to Ready for Development in Low Priority Backlog Oct 8, 2020
@ghost ghost removed this from Dev in Progress in Community Backlog Oct 20, 2020
@ghost ghost removed this from Ready for Development in Low Priority Backlog Oct 20, 2020
@ghost ghost removed Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development labels Oct 20, 2020
@lfluvisotto
Copy link
Contributor

@magento I am working on it

@ghost ghost added the Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround. label Oct 29, 2020
@gabrieldagama gabrieldagama added the Priority: P3 May be fixed according to the position in the backlog. label Oct 29, 2020
@ghost ghost added this to Pull Request In Progress in Low Priority Backlog Oct 29, 2020
@ghost ghost removed this from Confirmed in Issue Confirmation and Triage Board Oct 29, 2020
@m2-community-project m2-community-project bot moved this from Pull Request In Progress to Ready for Development in Low Priority Backlog Dec 7, 2020
@stale
Copy link

stale bot commented Feb 21, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 14 days if no further activity occurs. Is this issue still relevant? If so, what is blocking it? Is there anything you can do to help move it forward? Thank you for your contributions!

@stale stale bot added the stale issue label Feb 21, 2021
@stale stale bot closed this as completed Mar 7, 2021
@m2-community-project m2-community-project bot moved this from Ready for Development to Done in Low Priority Backlog Mar 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report Component: Framework/Code Component: Url Event: dmcdindia1 Event: mm19br Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Priority: P3 May be fixed according to the position in the backlog. Progress: done Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround. stale issue Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it
Projects
Development

No branches or pull requests