/** * @covers \Magento\Theme\Model\Config\Customization::getAssignedThemeCustomizations */ public function testGetAssignedThemeCustomizations() { $this->_designPackage->expects($this->once())->method('getConfigurationDesignTheme')->will($this->returnValue($this->_getAssignedTheme()->getId())); $this->_storeManager->expects($this->once())->method('getStores')->will($this->returnValue(array($this->_getStore()))); $this->themeProviderMock->expects($this->once())->method('getThemeCustomizations')->with(\Magento\Framework\App\Area::AREA_FRONTEND)->will($this->returnValue(array($this->_getAssignedTheme(), $this->_getUnassignedTheme()))); $assignedThemes = $this->_model->getAssignedThemeCustomizations(); $this->assertArrayHasKey($this->_getAssignedTheme()->getId(), $assignedThemes); }
/** * @covers \Magento\Theme\Model\Config\Customization::getAssignedThemeCustomizations * @covers \Magento\Theme\Model\Config\Customization::hasThemeAssigned */ public function testGetAssignedThemeCustomizations() { $this->designPackage->expects($this->once())->method('getConfigurationDesignTheme')->willReturn($this->getAssignedTheme()->getId()); $this->storeManager->expects($this->once())->method('getStores')->willReturn([$this->getStore()]); $this->themeProviderMock->expects($this->once())->method('getThemeCustomizations')->with(Area::AREA_FRONTEND)->willReturn([$this->getAssignedTheme(), $this->getUnassignedTheme()]); $assignedThemes = $this->model->getAssignedThemeCustomizations(); $this->assertArrayHasKey($this->getAssignedTheme()->getId(), $assignedThemes); $this->assertTrue($this->model->hasThemeAssigned()); }
/** * Load layout * * @return void */ protected function _renderStoreDesigner() { try { $this->_view->loadLayout(); $this->_setActiveMenu('Magento_DesignEditor::system_design_editor'); $this->_setTitle(); if (!$this->_isFirstEntrance()) { /** @var $assignedThemeBlock * \Magento\DesignEditor\Block\Adminhtml\Theme\Selector\SelectorList\Assigned */ $assignedThemeBlock = $this->_view->getLayout()->getBlock('assigned.theme.list'); $assignedThemeBlock->setCollection($this->_customizationConfig->getAssignedThemeCustomizations()); /** @var $unassignedThemeBlock * \Magento\DesignEditor\Block\Adminhtml\Theme\Selector\SelectorList\Unassigned */ $unassignedThemeBlock = $this->_view->getLayout()->getBlock('unassigned.theme.list'); $unassignedThemeBlock->setCollection($this->_customizationConfig->getUnassignedThemeCustomizations()); $unassignedThemeBlock->setHasThemeAssigned($this->_customizationConfig->hasThemeAssigned()); } /** @var $storeViewBlock \Magento\DesignEditor\Block\Adminhtml\Theme\Selector\StoreView */ $storeViewBlock = $this->_view->getLayout()->getBlock('theme.selector.storeview'); $storeViewBlock->setData('actionOnAssign', 'refresh'); $this->_view->renderLayout(); } catch (\Exception $e) { $this->messageManager->addError(__('We can\'t load the list of themes.')); $this->getResponse()->setRedirect($this->_redirect->getRefererUrl()); $this->_objectManager->get('Psr\\Log\\LoggerInterface')->critical($e); } }
/** * Get an array of stores grouped by theme customization it uses. * * The structure is the following: * array( * theme_id => array(store_id) * ) * * @return array */ protected function _getStoresByThemes() { $assignedThemeIds = array_map(function ($theme) { return $theme->getId(); }, $this->_customizationConfig->getAssignedThemeCustomizations()); $storesByThemes = []; foreach ($this->_customizationConfig->getStoresByThemes() as $themeId => $stores) { /* NOTE We filter out themes not included to $assignedThemeIds array so we only get actually "assigned" themes. So if theme is assigned to store or website and used by store-view only via config fall-back mechanism it will not get to the resulting $storesByThemes array. */ if (!in_array($themeId, $assignedThemeIds)) { continue; } $storesByThemes[$themeId] = []; /** @var $store \Magento\Store\Model\Store */ foreach ($stores as $store) { $storesByThemes[$themeId][] = (int) $store->getId(); } } return $storesByThemes; }