2

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?

  • @SureshChikani It was already in the original post. Nevertheless I have added a more precise example. – fritzmg May 11 '18 at 13:15
4

For store group you can use

$this->storeManager->getGroup()->getCode();
  • Thx :). Didn't know that this was called a "group". – fritzmg May 11 '18 at 13:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.