Magento 2 Equivalent for Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID)

magento.stackexchange https://magento.stackexchange.com/questions/320985

  •  14-04-2021
  •  | 
  •  

Question

I'm using following code:-

Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID)

Same code I want to use for Magento2, how can I achieve?

Was it helpful?

Solution

Something like:

$this->storeManager->setCurrentStore(0);

Where $this->storeManage is an instance of Magento\Store\Model\StoreManagerInterface

Ex:

public function __construct(
    \Magento\Store\Model\StoreManagerInterface $storeManager
) {
    $this->storeManager = $storeManager;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top