Programmatically change magento theme in runtime

Magento is that platform you can provide a solution in hundred way. But you need to know which is the best. Today I discuss about Magento theme change in runtime, that means your system work on many themes. So lets start. Today I discuss two possible way to do this.

Possible way 1:

Write below code in action to set Package and theme for the action

  Mage::getDesign()->setArea('frontend') //Area (frontend/adminhtml)
            ->setPackageName('default') //Name of Package
            ->setTheme('modern'); // Name of theme

Possible way 2 :

Overwrite Mage_Core_Model_Design in following way.

<models>
    <core>
        <rewrite>
            <design>Packagename_Modulename_Model_Design</design>
        </rewrite>
    </core>
</models>

Modify loadChange method as required, I just place an example of that, see following.

public function loadChange($storeId, $date = null)
    {
        $result = $this->getResource()
            ->loadChange($storeId, $date);

        if (!empty($result)) {
            if (!empty($result['design'])) {
                $tmp = explode('/', $result['design']);
                $result['package'] = $tmp[0];
                $result['theme'] = $tmp[1];
            }

            $this->setData($result);
        }
        // your custom code goes here
        // custom condition
        if(true) {
            $result['package'] = 'default';
            $result['theme'] = 'modern';
            $this->setData($result);
        }
        
        return $this;
    }

That’s it.

2 thoughts on “Programmatically change magento theme in runtime

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s