Example #1
0
 /**
  * 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;
 }
Example #2
0
 /**
  * Detect and apply design for the area
  *
  * @param \Magento\Framework\App\RequestInterface $request
  * @return void
  */
 public function detectDesign($request = null)
 {
     if ($this->_code == self::AREA_FRONTEND) {
         $isDesignException = $request && $this->_applyUserAgentDesignException($request);
         if (!$isDesignException) {
             $this->_design->loadChange($this->_scopeResolver->getScope()->getId())->changeDesign($this->_getDesign());
         }
     }
 }
Example #3
0
 /**
  * Apply design of the specified store
  *
  * @param integer $storeId
  * @param string $area
  * @return array initial design parameters(package, store, area)
  */
 protected function _emulateDesign($storeId, $area = \Magento\Framework\App\Area::AREA_FRONTEND)
 {
     $store = $this->_storeManager->getStore();
     $initialDesign = array('area' => $this->_viewDesign->getArea(), 'theme' => $this->_viewDesign->getDesignTheme(), 'store' => $store);
     $storeTheme = $this->_viewDesign->getConfigurationDesignTheme($area, array('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);
         }
     }
     return $initialDesign;
 }