Question

Using the StoreManagerInterface I am getting the current store via $store = $this->storeManager->getStore().

I then want to get the code of the store. However, when using $store->getCode() I get the code of the store view, not the store.

public function __construct(
    \Magento\Store\Model\StoreManagerInterface $storeManager
){
    $this->storeManager = $storeManager;
}

public function foo()
{
    echo $this->storeManager->getStore()->getCode(); // returns store view code
}

Is there any way to just get the code of the store, not the store view?

Was it helpful?

Solution

For store group you can use

$this->storeManager->getGroup()->getCode();
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top