/** * Start environment emulation of the specified store * * Function returns information about initial store environment and emulates environment of another store * * @param integer $storeId * @param string $area * @param bool $force A true value will ensure that environment is always emulated, regardless of current store * @return void */ public function startEnvironmentEmulation($storeId, $area = \Magento\Framework\App\Area::AREA_FRONTEND, $force = false) { // Only allow a single level of emulation if ($this->initialEnvironmentInfo !== null) { $this->logger->error(__('Environment emulation nesting is not allowed.')); return; } if ($storeId == $this->_storeManager->getStore()->getStoreId() && !$force) { return; } $this->storeCurrentEnvironmentInfo(); // emulate inline translations $this->inlineTranslation->suspend($this->inlineConfig->isActive($storeId)); // emulate design $storeTheme = $this->_viewDesign->getConfigurationDesignTheme($area, ['store' => $storeId]); $this->_viewDesign->setDesignTheme($storeTheme, $area); if ($area == \Magento\Framework\App\Area::AREA_FRONTEND) { $designChange = $this->_design->loadChange($storeId); if ($designChange->getData()) { $this->_viewDesign->setDesignTheme($designChange->getDesign(), $area); } } // Current store needs to be changed right before locale change and after design change $this->_storeManager->setCurrentStore($storeId); // emulate locale $newLocaleCode = $this->_scopeConfig->getValue($this->_localeResolver->getDefaultLocalePath(), \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId); $this->_localeResolver->setLocale($newLocaleCode); $this->_translate->setLocale($newLocaleCode); $this->_translate->loadData($area); return; }
/** * Apply locale of the specified store * * @param integer $storeId * @param string $area * @return string initial locale code */ protected function _emulateLocale($storeId, $area = \Magento\Framework\App\Area::AREA_FRONTEND) { $initialLocaleCode = $this->_localeResolver->getLocaleCode(); $newLocaleCode = $this->_scopeConfig->getValue($this->_localeResolver->getDefaultLocalePath(), \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId); $this->_localeResolver->setLocaleCode($newLocaleCode); $this->_translate->setLocale($newLocaleCode)->loadData($area, true); return $initialLocaleCode; }
/** * Retrieve Date value for store * * @param int $storeId * @param string $date * @return string|null */ protected function getStoreDate($storeId, $date = null) { if (!isset($this->dates[$storeId])) { $timezone = $this->scopeConfig->getValue($this->localeDate->getDefaultTimezonePath(), \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId); $locale = $this->scopeConfig->getValue($this->localeResolver->getDefaultLocalePath(), \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId); $locale = new \Zend_Locale($locale); $dateObj = new \Magento\Framework\Stdlib\DateTime\Date(null, null, $locale); $dateObj->setTimezone($timezone); $this->dates[$storeId] = [$dateObj, $locale->getTranslation(null, 'date', $locale)]; } if (!$this->dateTime->isEmptyDate($date)) { list($dateObj, $format) = $this->dates[$storeId]; $dateObj->setDate($date, \Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT); return $dateObj->toString($format); } return null; }
/** * Database installation * * @return $this */ public function installDb() { $this->_dbUpdater->updateScheme(); $data = $this->getDataModel()->getConfigData(); /** * Saving host information into DB */ if (!empty($data['use_rewrites'])) { $this->_installSetup->setConfigData(\Magento\Store\Model\Store::XML_PATH_USE_REWRITES, 1); } if (!empty($data['enable_charts'])) { $this->_installSetup->setConfigData(\Magento\Backend\Block\Dashboard::XML_PATH_ENABLE_CHARTS, 1); } else { $this->_installSetup->setConfigData(\Magento\Backend\Block\Dashboard::XML_PATH_ENABLE_CHARTS, 0); } if (!empty($data['admin_no_form_key'])) { $this->_installSetup->setConfigData('admin/security/use_form_key', 0); } $unsecureBaseUrl = $this->_storeManager->getStore()->getBaseUrl('web'); if (!empty($data['unsecure_base_url'])) { $unsecureBaseUrl = $data['unsecure_base_url']; $this->_installSetup->setConfigData(\Magento\Store\Model\Store::XML_PATH_UNSECURE_BASE_URL, $unsecureBaseUrl); } if (!empty($data['use_secure'])) { $this->_installSetup->setConfigData(\Magento\Store\Model\Store::XML_PATH_SECURE_IN_FRONTEND, 1); $this->_installSetup->setConfigData(\Magento\Store\Model\Store::XML_PATH_SECURE_BASE_URL, $data['secure_base_url']); if (!empty($data['use_secure_admin'])) { $this->_installSetup->setConfigData(\Magento\Store\Model\Store::XML_PATH_SECURE_IN_ADMINHTML, 1); } } elseif (!empty($data['unsecure_base_url'])) { $this->_installSetup->setConfigData(\Magento\Store\Model\Store::XML_PATH_SECURE_BASE_URL, $unsecureBaseUrl); } /** * Saving locale information into DB */ $locale = $this->getDataModel()->getLocaleData(); if (!empty($locale['locale'])) { $this->_installSetup->setConfigData($this->_localeResolver->getDefaultLocalePath(), $locale['locale']); } if (!empty($locale['timezone'])) { $this->_installSetup->setConfigData($this->_localeDate->getDefaultTimezonePath(), $locale['timezone']); } if (!empty($locale['currency'])) { $this->_installSetup->setConfigData(\Magento\Directory\Model\Currency::XML_PATH_CURRENCY_BASE, $locale['currency']); $this->_installSetup->setConfigData(\Magento\Directory\Model\Currency::XML_PATH_CURRENCY_DEFAULT, $locale['currency']); $this->_installSetup->setConfigData(\Magento\Directory\Model\Currency::XML_PATH_CURRENCY_ALLOW, $locale['currency']); } if (!empty($data['order_increment_prefix'])) { $this->_setOrderIncrementPrefix($this->_installSetup, $data['order_increment_prefix']); } return $this; }