0

Programmatically How can set a theme for specific stores in Magento 2.1

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.