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.

 * @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 May 10 '17 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 May 10 '17 at 9:01
  • It is not switching store, whenever i visit storefront, only default store is visible. Am i missing something? – Vinit Chouhan Nov 9 '17 at 13:53
  • Hi @vinit-chouhan, Did you make the change of store view? How have you solved this problem? – Despotars Jun 4 '19 at 8:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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