Assign custom theme programmatically to store in Magento 2
Today we discuss how to assign custom theme programmatically to store in Magento 2. Sometimes you need to set the theme programmatically. For that, you need theme_id and store_id. You can get theme_id from theme table.
use Magento\Framework\App\Config\ConfigResource\ConfigInterface;
/**
* @var ConfigInterface
*/
private $configInterface;
public function __construct(
ConfigInterface $configInterface
) {
$this->configInterface = $configInterface;
}
/**
* @var ConfigInterface
*/
private $configInterface;
public function __construct(
ConfigInterface $configInterface
) {
$this->configInterface = $configInterface;
}
Following belowcode you can change theme programatically.
$this->configInterface->saveConfig('design/theme/theme_id', {{theme_id}}, 'stores', {{store_id}});
NOTE: change {{theme_id}} and {{store_id}} with your theme id and store id