cancel
Showing results for 
Search instead for 
Did you mean: 

How to assign custom theme programmatically to store in magento 2

SOLVED

How to assign custom theme programmatically to store in magento 2

Hi

I have multiple stores in my Magento website setup

I am having a concept where each store has a different theme, so I would like to assign my custom theme to a specific store using programmatically.

Can anyone have an idea how can I achieve this?

1 ACCEPTED SOLUTION

Accepted Solutions

Re: How to assign custom theme programmatically to store in magento 2

Hi @Noah_Sinnis 

 

You can achieve this functionality by creating installData or upgradeData scripts.

After creating script add below code to that file :

 

use Magento\Framework\App\Config\ConfigResource\ConfigInterface;

/**
* @var ConfigInterface
*/
private $configInterface;

public function __construct(
.....................
ConfigInterface $configInterface,
................
) {
................
$this->configInterface = $configInterface;
..................
}


$this->configInterface->saveConfig('design/theme/theme_id', {{theme_id}}, 'stores', {{store_id}});

 

You can get theme_id from theme table.

 

For more details refer this link - https://magento.stackexchange.com/questions/213806/magento-2-how-to-assign-custom-theme-to-specific-...

 

Hope it helps !

if issue solved,Click Kudos & Accept as Solution

View solution in original post

5 REPLIES 5

Re: How to assign custom theme programmatically to store in magento 2

Hi @Noah_Sinnis 

 

Does it mean you would like to add your custom theme to store using programatically ?

 

if issue solved,Click Kudos & Accept as Solution

Re: How to assign custom theme programmatically to store in magento 2

Yes, I mean the same.

Re: How to assign custom theme programmatically to store in magento 2

Hi @Noah_Sinnis 

 

You can achieve this functionality by creating installData or upgradeData scripts.

After creating script add below code to that file :

 

use Magento\Framework\App\Config\ConfigResource\ConfigInterface;

/**
* @var ConfigInterface
*/
private $configInterface;

public function __construct(
.....................
ConfigInterface $configInterface,
................
) {
................
$this->configInterface = $configInterface;
..................
}


$this->configInterface->saveConfig('design/theme/theme_id', {{theme_id}}, 'stores', {{store_id}});

 

You can get theme_id from theme table.

 

For more details refer this link - https://magento.stackexchange.com/questions/213806/magento-2-how-to-assign-custom-theme-to-specific-...

 

Hope it helps !

if issue solved,Click Kudos & Accept as Solution

Re: How to assign custom theme programmatically to store in magento 2

Yes, I have tried the code and it works.

 

Thank you for your help.

Re: How to assign custom theme programmatically to store in magento 2

Hi @Noah_Sinnis 

 

Glad to know that its work for you !

 

Happy to help and keep helping Smiley Happy

if issue solved,Click Kudos & Accept as Solution