Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DefaultStore.php
Go to the documentation of this file.
1 <?php
7 
8 use \Magento\Store\Model\StoreResolver\ReaderList;
9 use \Magento\Store\Model\ScopeInterface;
10 
15 {
19  protected $storeManager;
20 
24  protected $readerList;
25 
29  protected $runMode;
30 
34  protected $scopeCode;
35 
44  public function __construct(
45  \Magento\Store\Model\StoreManagerInterface $storeManager,
48  $scopeCode = null
49  ) {
51  $this->scopeCode = $scopeCode;
52  $this->readerList = $readerList;
53  $this->storeManager = $storeManager;
54  }
55 
65  public function beforeDispatch(
66  \Magento\Framework\App\FrontController $subject,
67  \Magento\Framework\App\RequestInterface $request
68  ) {
69  $reader = $this->readerList->getReader($this->runMode);
70  $defaultStoreId = $reader->getDefaultStoreId($this->scopeCode);
71  $this->storeManager->setCurrentStore($defaultStoreId);
72  }
73 }
beforeDispatch(\Magento\Framework\App\FrontController $subject, \Magento\Framework\App\RequestInterface $request)
__construct(\Magento\Store\Model\StoreManagerInterface $storeManager, ReaderList $readerList, $runMode=ScopeInterface::SCOPE_STORE, $scopeCode=null)