_theme = $theme; $this->_themeFactory = $themeFactory; $this->_themeCopyService = $themeCopyService; $this->_customizationConfig = $customizationConfig; } /** * Get 'staging' theme * * @return \Magento\Framework\View\Design\ThemeInterface */ public function getStagingTheme() { if (!$this->_stagingTheme) { $this->_stagingTheme = $this->_theme->getStagingVersion(); if (!$this->_stagingTheme) { $this->_stagingTheme = $this->_createStagingTheme(); $this->_themeCopyService->copy($this->_theme, $this->_stagingTheme); } } return $this->_stagingTheme; } /** * Get 'physical' theme * * @return \Magento\Framework\View\Design\ThemeInterface */ public function getPhysicalTheme() { /** @var $parentTheme \Magento\Framework\View\Design\ThemeInterface */ $parentTheme = $this->_theme->getParentTheme(); while ($parentTheme && !$parentTheme->isPhysical()) { $parentTheme = $parentTheme->getParentTheme(); } if (!$parentTheme || !$parentTheme->getId()) { return null; } return $parentTheme; } /** * Check if theme is assigned to ANY store * * @return bool */ public function isAssigned() { return $this->_customizationConfig->isThemeAssignedToStore($this->_theme); } /** * Create 'staging' theme associated with current 'virtual' theme * * @return \Magento\Framework\View\Design\ThemeInterface */ protected function _createStagingTheme() { $stagingTheme = $this->_themeFactory->create(); $stagingTheme->setData( [ 'parent_id' => $this->_theme->getId(), 'theme_path' => null, 'theme_title' => sprintf('%s - Staging', $this->_theme->getThemeTitle()), 'preview_image' => $this->_theme->getPreviewImage(), 'is_featured' => $this->_theme->getIsFeatured(), 'type' => \Magento\Framework\View\Design\ThemeInterface::TYPE_STAGING, ] ); $stagingTheme->save(); return $stagingTheme; } }