Magento 2 get store id

magento 2 set store id programmatically
magento 2 get store phone number
magento 2 get store email
magento get store name
storemanagerinterface magento 2
get store url in magento 2
magento default store id
store url magento 2

magento 2 get store id php

I need to show something based on store id

for exapmle;

					<?php if ($store == "2") {?>
<div class="block-bottom">
						<a class="button-sticky-bottom" href="<?php echo $this->getUrl('') ?>">
						<i class="fa fa-flag" style="font-size: 18px;"></i>
							<span><?php echo __('Language'); ?></span>
						</a>
					
					</div>

<?php } else { ?>
<div class="block-bottom">
						<a class="button-sticky-bottom" href="<?php echo $this->getUrl('') ?>">
						<i class="fa fa-flag" style="font-size: 18px;"></i>
							<span><?php echo __('Language1'); ?></span>
						</a>
					
					</div>

<?php } ?>		
<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$storeManager = $objectManager->create('\Magento\Store\Model\StoreManagerInterface');
$storeId = $storeManager->getStore()->getId();
if($storeId == 1){
    echo 'Store Id 1 code here';
}else{
    echo 'other stores code here';
}
?>

How to Get Store Information in Magento 2 – Mageplaza, It is possible to collect all information of your magento 2 store including store id, store name, store url, and store website via this article. Get the Best Magento Website & See How We Can Help You Become More Profitable. Contact Us. Get eCommerce Strategy, Implementation & Support With Our Personal & Consultative Approach

$storeManager = \Magento\Framework\App\ObjectManager::getInstance()->get('\Magento\Store\Model\StoreManagerInterface');

if ($storeManager->getStore()->getStoreId() == 1) {
    echo 'Hello';
} else {
    echo 'Thanks';
}

The use of object manager is not recommended. It is better to arrange this code for the class of the block using the constructor

Magento 2 get current store, Method getStoreId() returns id from the current active Magento 2 store. Different scope. If you want to check if this code was called from adminhtml  Get a Magento site with unlimited growth. We're a custom Magento development company. Our team of designers, developers and marketers work to build your next great site.

It didnt worked. What is wrong?

<?php
$storeManager = \Magento\Framework\App\ObjectManager::getInstance()->get('\Magento\Store\Model\StoreManagerInterface');

if ($storeManager->getStore()->getStoreId() == 1) { ?>
   <div class="block-bottom">
						<a class="button-sticky-bottom" href="<?php echo $this->getUrl('') ?>">
						<i class="fa fa-flag" style="font-size: 18px;"></i>
							<span><?php echo __('Language'); ?></span>
						</a>
					
					</div>
<?php } else { ?>
   

					<div class="block-bottom">
						<a class="button-sticky-bottom" href="<?php echo $this->getUrl('') ?>">
						<i class="fa fa-flag" style="font-size: 18px;"></i>
							<span><?php echo __('Language1'); ?></span>
						</a>
					
					</div>
		<?php }
?>		
		

Magento 2 get store id, The getStoreId() method returns the ID from the current active Magento 2 store. Different scope. Note that you can't use isAdmin() to check if this  eTour.com is the newest place to search, delivering top results from across the web. Content updated daily for magento 2.

I would recommend injecting the StoreManagerInterface in your construct and avoid using the object manager.

Example

/**
 * @var \Magento\Store\Model\StoreManagerInterface
 */
protected $storeManager;


public function __construct(Context $context,
                            \Magento\Store\Model\StoreManagerInterface $storeManager)
{
    parent::__construct($context);
    $this->storeManager = $storeManager;

}

public function myFunction()
{
    $storeId = $this->storeManager->getStore()->getId();

    if ($storeId == 1) {
        echo 'Store Id 1 code here';
    } else {
        echo 'other stores code here';
    }
}

How to get a store in Magento 2 programmatically?, This article shows how we can get store information in Magento 2. We will be fetching store id, store code, store name, store url, and store's  Search magento 2. Explore Teoma.us, the leading search site for results around the web.

Magento 2: Get Store Information (Store ID, Code, Name, URL , Hi All,. Here is some codes which will help us to get the store info like magento 2 current Store id, base url, get base currency etc. 1) Magento 2 Current store Id. Magento 2 – How to get Current Store ID, Code, Name, URL and Website ID 1. Using Dependency Injection 2. Using Object Manager

Magento 2 Get Current Store Info, Here, we will see how to get the store information like store id, store code, store name, store URL, and store website in Magento 2  Magento 2 get Store Details– It is very simple to get the store details in Magento 2. There are two ways to get the store information in Magento 2 – 1. Using dependency Injection, 2. Using Object Manager. Here in this post we are going to get the – store id, store code, store name, store website, store url etc.

Get Store Information in Magento 2 Programmatically, In this post I am going to explain how to get current store information like store id, code, name, url and website id in Magento 2. 1. How to get store information in Magento 2 Step 1: Declare in Mageplaza_HelloWorld You will use a block class of the module Mageplaza_HelloWorld, then possibly Step 2: Get store information in .phtml file

Comments
  • Welcome to Stack Overflow. Please review the tour and How to Ask. Help us help you, show us what you tried, explain how it doesn't met your requirements and, when possible, do your best to include a minimal reproducible example.