سؤال

Hi I have created 3 to 4 stores programatically

Now i want to assign my custom theme to specific store using programatically.

I have store id of each store which i have created.

Below code i have tried , but it assign theme to all the stores including default as well.

/**
     * Assign Theme
     *
     * @return void
     */
    protected function assignTheme($group_id)
    {
        $themes = $this->collectionFactory->create()->loadRegisteredThemes();
        /**
         * @var \Magento\Theme\Model\Theme $theme
         */
        foreach ($themes as $theme) {
            if ($theme->getCode() == self::THEME_NAME) {
                $this->config->assignToStore(
                    $theme,
                    [Store::DEFAULT_STORE_ID],
                    ScopeConfigInterface::SCOPE_TYPE_DEFAULT
                );
            }
        }
    }

How can i pass store id to this code , or any alternate way to do this ?

هل كانت مفيدة؟

المحلول

You can do it by installData or upgradeData scripts. (Refer this)

Then use following code in your script.

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;
        ..................
    }


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

NOTE: change {{theme_id}} and {{store_id}} with your theme and store id

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى magento.stackexchange
scroll top