There are many themes which offer Quick installation or 1 click installer which not only activates the theme but also installs the Sample data (same as shown on theme demo). My Question is how can we add that functionality in our theme?
3 Answers
To install any data or settings (like sample data, products etc) your theme would not a module as well that has an installer script. Inchoo wrote a nice article on installers that should help you set this up, also take a look at this tutorial.
For example, setting your template as active might look something like this
$installer = $this;
$installer->startSetup();
$installer->run("
UPDATE `{$this->getTable('core_config_data')}` SET `value` = 'yourpackagename' WHERE `path` = 'design/package/name';
UPDATE `{$this->getTable('core_config_data')}` SET `value` = 'yourtemplatename' WHERE `path` = 'design/theme/template';
");
$installer->endSetup();
Instead of using an installer executing some SQL query, I would recommend to use instead the function saveConfig
, exactly buit for this. A quick example here :
$installer = $this;
$installer->startSetup();
$setup = new Mage_Core_Model_Config();
$setup->saveConfig('design/package/name', 'yourpackagename');
$installer->endSetup();