Magento2 Magento 2获取存储id

Magento2 Magento 2获取存储id,magento2,Magento2,magento 2获取存储id php 我需要根据商店id显示一些内容 例如: 不建议使用对象管理器。最好使用构造函数为块的类安排此代码 不建议使用对象管理器。最好使用构造函数为块的类安排此代码,因为它不起作用。怎么了 它不起作用。怎么了 我建议在构造中注入StoreManagerInterface,并避免使用对象管理器 范例 /** * @var \Magento\Store\Model\StoreManagerInterface */ protected $storeMan

magento 2获取存储id php

我需要根据商店id显示一些内容

例如:


不建议使用对象管理器。最好使用构造函数为块的类安排此代码


不建议使用对象管理器。最好使用构造函数为块的类安排此代码,因为它不起作用。怎么了


它不起作用。怎么了




我建议在构造中注入StoreManagerInterface,并避免使用对象管理器

范例

/**
 * @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';
    }
}

我建议在构造中注入StoreManagerInterface,并避免使用对象管理器

范例

/**
 * @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';
    }
}
欢迎光临。请查看和。帮助我们帮助您,向我们展示您的尝试,解释它如何不满足您的要求,并在可能的情况下,尽最大努力包含。欢迎使用。请查看和。帮助我们帮助您,向我们展示您的尝试,解释它如何不满足您的要求,并在可能的情况下,尽最大努力包含一个。
/**
 * @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';
    }
}