Magento 2 – Get Store ID by Store Code

magento2store-codestore-id

How to get Store ID by store code in Magento 2

Thanks

Best Answer

Please use below code :

$objectManager =  \Magento\Framework\App\ObjectManager::getInstance();    
$storeManager = $objectManager->create("\Magento\Store\Model\StoreManagerInterface");
$storecode = 'de'; //storecode here
    // get array of stores with storecode as key
    $stores = $storeManager->getStores(true, true);
    // check stores array for this storecode 
    if(isset($stores[$storecode]){
        $store_id = $stores[$storecode]->getId();
    }
echo $store_id;
Related Topic