I have the following Magento 1 code and i would like to know the Magento 2 equivalent of the code.

I've looked around on the web but unable to find a proper solution.


1 Answer 1

 * @var \Magento\Store\Model\StoreManagerInterface

 protected $_storeManager;

public function __construct(
\Magento\Store\Model\StoreManagerInterface $storeManager
) {
    $this->_storeManager = $storeManager;

// now you can set your current store like

  • Thanks. how can i retrieve Mage_Core_Model_App::ADMIN_STORE_ID in Magento 2 or do i just replace this code with a 0 which seems to be the equivalent for Mage_Core_Model_App::ADMIN_STORE_ID which is the id of the admin panel?
    – Jiyaad.D
    Commented May 10, 2017 at 8:50
  • You can directly set It to 0 for admin store id, because admin store always is 0 and in Magento2 ADMIN_STORE_ID constact is Obsolete @Jiyaad.D
    – Keyur Shah
    Commented May 10, 2017 at 9:01
  • It is not switching store, whenever i visit storefront, only default store is visible. Am i missing something? Commented Nov 9, 2017 at 13:53
  • Hi @vinit-chouhan, Did you make the change of store view? How have you solved this problem?
    – Despotars
    Commented Jun 4, 2019 at 8:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.