Programmatically How can set a theme for specific stores in Magento 2.1
1 Answer
You can set theme for specific store using below script.
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $config = $objectManager->get("\Magento\Theme\Model\Config"); $storeManager = $objectManager->get('\Magento\Store\Model\StoreManagerInterface'); I have used default luma theme ID, You can change it based on theme.
$themeId = 2; $theme = $objectManager->get("\Magento\Theme\Model\ThemeFactory")->create()->load($themeId); I have get current storeId, you can set store ID as per your requirement.
$storeId= $storeManager->getStore()->getStoreId(); if ($theme->getId()) { $config->assignToStore($theme,[$storeId],'store'); } If you want to set theme based on website then below is the code.
$websiteId = $storeManager->getWebsite()->getId(); if ($theme->getId()) { $config->assignToStore($theme,[$websiteId],'website'); } Thanks.