How to get a store (and the current store) programmatically in PHP?

Magento 1.x

Mage::app()->getStore()

Magento 2

/**
 * @param int|string|null|bool|\Magento\Store\Api\Data\StoreInterface $id [optional]
 * @return \Magento\Store\Api\Data\StoreInterface
 * @throws \Magento\Framework\Exception\NoSuchEntityException
 */
function rm_store($id = null) {
	/** @var \Magento\Framework\ObjectManagerInterface $om */
	$om = \Magento\Framework\App\ObjectManager::getInstance();
	/** @var \Magento\Store\Model\StoreManagerInterface $manager */
	$manager = $om->get('Magento\Store\Model\StoreManagerInterface');
	return $manager->getStore($id);
}
1 Like

See also: