Esempio n. 1
0
 protected function setUp()
 {
     $this->_themeFactory = $this->getMock('Magento\\Theme\\Model\\ThemeFactory', ['create'], [], '', false);
     $this->_theme = $this->getMock('Magento\\Theme\\Model\\Theme', ['load', 'getId', 'getType', 'getDomainModel', 'isVirtual', '__wakeup'], [], '', false);
     $this->_themeFactory->expects($this->any())->method('create')->will($this->returnValue($this->_theme));
     $this->_copyService = $this->getMock('Magento\\Theme\\Model\\CopyService', ['copy'], [], '', false);
     $this->_model = new \Magento\DesignEditor\Model\Theme\Context($this->_themeFactory, $this->_copyService);
 }
Esempio n. 2
0
 /**
  * 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;
 }
Esempio n. 3
0
 /**
  * {@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;
 }
Esempio n. 4
0
 /**
  * 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;
 }
Esempio n. 5
0
 /**
  * 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;
 }
 /**
  * @test
  * @return void
  * @covers \Magento\Theme\Model\View\Design::getDesignParams
  * @covers \Magento\Theme\Model\View\Design::getLocale
  * @covers \Magento\Theme\Model\View\Design::getArea
  * @covers \Magento\Theme\Model\View\Design::getDesignTheme
  */
 public function testGetDesignParams()
 {
     $locale = 'locale';
     $area = Design::DEFAULT_AREA;
     $localeMock = $this->getMockForAbstractClass('\\Magento\\Framework\\Locale\\ResolverInterface');
     $localeMock->expects($this->once())->method('getLocale')->will($this->returnValue($locale));
     $this->objectManager->expects($this->once())->method('get')->will($this->returnValue($localeMock));
     $this->state->expects($this->any())->method('getAreaCode')->willReturn($area);
     $this->themeFactory->expects($this->once())->method('create')->willReturn($this->getMockBuilder('Magento\\Framework\\View\\Design\\ThemeInterface')->getMock());
     $params = $this->model->getDesignParams();
     $this->assertInstanceOf('Magento\\Framework\\View\\Design\\ThemeInterface', $params['themeModel']);
     $this->assertEquals($area, $params['area']);
     $this->assertEquals($locale, $params['locale']);
 }
 /**
  * @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;
 }
Esempio n. 9
0
 /**
  * {@inheritdoc}
  */
 public function getThemeById($themeId)
 {
     /** @var $themeModel \Magento\Framework\View\Design\ThemeInterface */
     $themeModel = $this->themeFactory->create();
     return $themeModel->load($themeId);
 }