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

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

  •  14-04-2021
  •  | 
  •  

Pregunta

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?

¿Fue útil?

Solución

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;
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a magento.stackexchange
scroll top