/** * Get scope name and scopeId * @todo refactor to scope resolver * @return void */ private function initScope() { if (is_null($this->getSection())) { $this->setSection(''); } if (is_null($this->getWebsite())) { $this->setWebsite(''); } if (is_null($this->getStore())) { $this->setStore(''); } if ($this->getStore()) { $scope = 'stores'; $store = $this->_storeManager->getStore($this->getStore()); $scopeId = (int) $store->getId(); $scopeCode = $store->getCode(); } elseif ($this->getWebsite()) { $scope = 'websites'; $website = $this->_storeManager->getWebsite($this->getWebsite()); $scopeId = (int) $website->getId(); $scopeCode = $website->getCode(); } else { $scope = 'default'; $scopeId = 0; $scopeCode = ''; } $this->setScope($scope); $this->setScopeId($scopeId); $this->setScopeCode($scopeCode); }
/** * @param \Magento\Framework\App\Helper\Context $context * @param \Magento\Framework\Store\StoreManagerInterface $storeManager * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig * @param array $data * * @throws \InvalidArgumentException */ public function __construct(\Magento\Framework\App\Helper\Context $context, \Magento\Framework\Store\StoreManagerInterface $storeManager, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, array $data = []) { parent::__construct($context); $this->_scopeConfig = $scopeConfig; $this->_currentStore = isset($data['current_store']) ? $data['current_store'] : $storeManager->getStore(); if (!$this->_currentStore instanceof \Magento\Store\Model\Store) { throw new \InvalidArgumentException('Required store object is invalid'); } $this->_website = isset($data['website']) ? $data['website'] : $storeManager->getWebsite(); if (!$this->_website instanceof \Magento\Store\Model\Website) { throw new \InvalidArgumentException('Required website object is invalid'); } }