Skip to content

Conversation

@rav-redchamps
Copy link
Contributor

Description (*)

\Magento\Store\Model\StoreManagerInterface in the admin area was always returning details of Default store instead of the admin store.

If you try below code in backend controller or any other file running for backend

/** @var \Magento\Store\Model\StoreManagerInterface $storeManager */
$storeManager->getStore()->getId()

You will get default store ID ideally 1 instead of admin store id ideally 0

So this pull request fixes this problem and set the admin store as a current store instead of the default store.

Fixed Issues (if relevant)

  1. When the Admin is on a different domain, redirect always fails and causes it to redirect to the front page #12354: When the Admin is on a different domain, redirect always fails and causes it to redirect to the front page
  2. Admin always return default store code, not admin #3147: Admin always return default store code, not admin
  3. Admin controller redirects to frontend #12502: Admin controller redirects to frontend

Manual testing scenarios (*)

  1. Verified by getting current store id in the custom admin controller
  2. Verified code $resultRedirect->setUrl($this->_redirect->getRefererUrl()); from custom admin controller when admin panel has custom domain configured. Previously, it was redirecting to frontend but now it redirects back to referral admin URL

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

@magento-engcom-team
Copy link
Contributor

Hi @rav-redchamps. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento-engcom-team give me test instance - deploy test instance based on PR changes
  • @magento-engcom-team give me 2.3-develop instance - deploy vanilla Magento instance

For more details, please, review the Magento Contributor Assistant documentation

…igured for MAGE_RUN_CODE then it will set non-admin store for backend
@rav-redchamps
Copy link
Contributor Author

@magento-engcom-team seems like the Travis automated test is showing false fail. Kindly check and confirm.

@orlangur orlangur self-assigned this Apr 5, 2019
@orlangur
Copy link
Contributor

orlangur commented Apr 5, 2019

@rav-redchamps contributor is supposed to fix broken tests within a pull request.

You may notice that two of three issues you mentioned where closed as non-issue prior to PR creation.

@orlangur orlangur closed this Apr 5, 2019
@m2-assistant
Copy link

m2-assistant bot commented Apr 5, 2019

Hi @rav-redchamps, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

@rav-redchamps
Copy link
Contributor Author

@orlangur sorry, but why you are so interested to close the issues/pull requests? 🤔 I have seen many valid issues/pull requests closed by you. Are you damn sure there is no issue this pull request is fixing?

People reported the problem, someone made effort to fix it and you just closed it.

Sorry if this all sounds rude.

@orlangur
Copy link
Contributor

orlangur commented Apr 5, 2019

@rav-redchamps you can read all the details in issues closed. Valid issues should be fixed, random changes breaking some tests should not be merged.

You can always share your thoughts for an issue/pull request which seems valid to you and it will be reopened.

@TimQSO
Copy link

TimQSO commented Feb 20, 2020

@orlangur

Well, in #12354 you only refer to the two other tickets. Ticket #3147 is closed by @hshar7 without a reason. And #12502 is closed due inactivity.

But you may mean here that third party plugins use the wrong class $this->_storeManager->getStore()-> instead of \Magento\Store\App\Response\Redirect?

In the mean while, I discovered that specifying the run code for the backend solved my issue. Here is my solution: #12354 (comment)

Strike that, that wasn't the solution. It made things worse. It made Magento think the backend was a store 0 with products and so on and was giving alot of other issues.

I tried this piece of code for a referrer redirect to the url where the request came from, but this also results in a frontend url:

namespace Company\Module\Controller\Index;
use Magento\Framework\Controller\ResultFactory; 

class Actionname name extends \Magento\Framework\App\Action\Action
{      
    public function execute()
    {
        $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);

        // Your code

        $resultRedirect->setUrl($this->_redirect->getRefererUrl());
        return $resultRedirect;
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants