0

I'm working on a module which needs to detect if there are multiple stores activated .Do someone have any function or know any function present in Magento that can help me?

1 Answer 1

1

Look at \Magento\Store\Model\StoreManager. Here is code example

protected $storeManager;

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

public function execute()
{
     if ($this->storeManager->isSingleStoreMode()) {
         //logic
     }
}
3
  • i tried your code but it returns me that the condition is false which is not the case my website doesn't have multiple store
    – Antoine553
    Jul 13, 2017 at 11:55
  • i tried this it give me test 2 public function multishop(){ if ($this->storeManager->isSingleStoreMode()) { echo 'test'; }else{ echo 'test2'; } }
    – Antoine553
    Jul 13, 2017 at 11:55
  • isSingleStoreMode returns true only if ... 1). you have only the one frontend store and 2) if you have choosed the Single store mode under Configuration > General > Single-Store Mode. If you need just check the multiple condition use hasSingleStore method Jul 13, 2017 at 12:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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