/** * Set theme which will be editable in store designer * * @param int $themeId * @return $this * @throws CoreException */ public function setEditableThemeById($themeId) { $this->_theme = $this->_themeFactory->create(); if (!$this->_theme->load($themeId)->getId()) { throw new CoreException(__('We can\'t find theme "%1".', $themeId)); } if ($this->_theme->getType() === \Magento\Framework\View\Design\ThemeInterface::TYPE_STAGING) { throw new CoreException(__('Wrong theme type set as editable')); } return $this; }
/** * {@inheritdoc} */ public function getThemeById($themeId) { $theme = $this->cache->load('theme-by-id-' . $themeId); if ($theme) { return unserialize($theme); } /** @var $themeModel \Magento\Framework\View\Design\ThemeInterface */ $themeModel = $this->themeFactory->create(); $themeModel->load($themeId); if ($themeModel->getId()) { $this->cache->save(serialize($themeModel), 'theme-by-id-' . $themeId); } return $themeModel; }
/** * Create theme customization * * @param \Magento\Framework\View\Design\ThemeInterface $theme * @return \Magento\Framework\View\Design\ThemeInterface */ public function createVirtualTheme($theme) { $themeData = $theme->getData(); $themeData['parent_id'] = $theme->getId(); $themeData['theme_id'] = null; $themeData['theme_path'] = null; $themeData['theme_title'] = $this->_getVirtualThemeTitle($theme); $themeData['type'] = \Magento\Framework\View\Design\ThemeInterface::TYPE_VIRTUAL; /** @var $themeCustomization \Magento\Framework\View\Design\ThemeInterface */ $themeCustomization = $this->_themeFactory->create()->setData($themeData); $themeCustomization->getThemeImage()->createPreviewImageCopy($theme); $themeCustomization->save(); $this->_themeCopyService->copy($theme, $themeCustomization); return $themeCustomization; }
/** * 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; }
/** * Design theme model getter * * @return \Magento\Theme\Model\Theme */ public function getDesignTheme() { if ($this->_theme === null) { $this->_theme = $this->_themeFactory->create(); } return $this->_theme; }
/** * @param array $configSchema * @return $this */ public function setThemeConfigSchema(array $configSchema) { // Default Theme Config $defaultTheme = isset($configSchema['default']) ? $configSchema['default'] : false; if ($defaultTheme) { $theme = $this->themeFactory->create()->load($defaultTheme, 'code'); /** @var Theme $theme */ // Theme Validation if ($theme->getId()) { $this->setConfig('design/theme/theme_id', $theme->getId()); } else { $this->logger->warning(__('There is no Theme with code: %1', $defaultTheme)); } } // Website Theme Config foreach ($this->getConfigKey($configSchema, 'websites') as $code => $themeCode) { $website = $this->getWebsite($code); $theme = $this->themeFactory->create()->load($themeCode, 'code'); // Website Validation if (!$website->getId()) { $this->logger->warning(__('There is no Website with code: %1', $code)); continue; } // Theme Validation if (!$theme->getId()) { $this->logger->warning(__('There is no Theme with code: %1', $themeCode)); continue; } // Set Config $this->setConfig('design/theme/theme_id', $theme->getId(), 'websites', $website->getId()); } // Store Theme Config foreach ($this->getConfigKey($configSchema, 'store') as $code => $themeCode) { $store = $this->getStore($code); $theme = $this->themeFactory->create()->load($themeCode, 'code'); // Store Validation if (!$store->getId()) { $this->logger->warning(__('There is no Store with code: %1', $code)); continue; } // Theme Validation if (!$theme->getId()) { $this->logger->warning(__('There is no Theme with code: %1', $themeCode)); continue; } // Set Config $this->setConfig('design/theme/theme_id', $theme->getId(), 'stores', $store->getId()); } return $this; }
/** * {@inheritdoc} */ public function getThemeById($themeId) { /** @var $themeModel \Magento\Framework\View\Design\ThemeInterface */ $themeModel = $this->themeFactory->create(); return $themeModel->load($themeId); }