I have a requirement where Customer can select from available theme to be shown when they are logged in. Now I have theme's id in customer Eav setup custom attribute, I also have setup a customer_login
event
events.xml
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="customer_login">
<observer name="themepick_customer_login_observer" instance="Afnam\ThemePick\Observer\CustomerLogin" />
</event>
</config>
and in Observer\CustomerLogin.php
public function execute(\Magento\Framework\Event\Observer $observer)
{
$customer_id = $observer->getEvent()->getCustomer()->getId();
$customer = $this->customerRepository->getById( $customer_id );
$id = $customer->getCustomAttribute( Constants::SELECTED_THEME )->getValue();
$themes = $this->collectionFactory->create()->loadRegisteredThemes();
foreach ($themes as $theme) {
if ($theme->getId() == $id) {
$this->config->assignToStore(
$theme,
[Store::DEFAULT_STORE_ID],
ScopeConfigInterface::SCOPE_TYPE_DEFAULT
);
}
}
}
but it doesn't change the theme as expected, I have followed this link https://magento.stackexchange.com/a/140027/26896 and they are changing theme in InstallData
Another important issue is that I dont really want to change the system theme I rather want to apply different themes for different users So it doesn't change the theme for all users but the current user only, and once they logout or check site in other browser with other user so they see default or other assigned theme to that user, Hope I have made myself clear