I'm looking for a solution in PHP to programmatically set the CMS home page in Magento. What I'm looking for is what you get when you use the manual method of selecting a page title from the dropdown in the System->Configuration->Web->CMS Home Page.
I already have the methods to determine pick any one of the set of Page Titles or I can pick from the Set of URL keys for all the CMS pages in the store. If I know either the Page Title or the URL Key, what is the PHP Mage methods to needed to change the current CMS home page.
I have already figured the code to create a new CMS Page as well. I'd just like to be able to select it and make it actively the home page when I'm done.
Edit: 02/18/2012
tried the following without success:
$groups['default']['fields']['cms_home_page']['value'] = 'city-grips-handle-bar-covers';
Mage::getModel('adminhtml/config_data')
->setSection('web')
->setWebsite('Main Website')
->setStore('My Store Name') // Hid Actual Store name here
->setGroups($groups)
->save();
EDIT: Thanks for the screenshot. I didn't have those right. My url when selecting the store is .../index.php/admin/system_config/edit/section/general/website/base/store/default/
Which I assume means website=base, store=default
(source: reefworkshop.com)
I changed the code to:
$groups['default']['fields']['cms_home_page']['value'] = 'city-grips-handle-bar-covers';
Mage::getModel('adminhtml/config_data')
->setSection('web')
->setWebsite('base')
->setStore('default')
->setGroups($groups)
->save();
But I'm still not showing the CMS Home page selected change. I refresh the front end and it doesn't switch. I've also tried clearing cache with no luck. Any ideas? just FYI I'm running Magento CE 1.5.1.0
EDIT:
Here's the file contents that I run. I put the file at the root of my Magento Install.:
<html>
<head>
</head>
<body>
<?php
require_once('app/Mage.php'); //Path to Magento
umask(0);
Mage::app(); // Change default to whatever store you want to run
print('CMS 1<br>');
$groups['default']['fields']['cms_home_page']['value'] = 'city-grips-handle-bar-covers';
print('CMS 2<br>');
Mage::getModel('adminhtml/config_data')
->setSection('web')
->setWebsite('base') // Code is the field name
->setStore('default')
->setGroups($groups)
->save();
print('CMS 3<br>');
?>
</body>
</html>
When I run it is see in the browser window:
CMS 1
CMS 2
CMS 3
EDIT: OK So I found a solution (that works) that was inspired by the last proposed solution:
require_once('app/Mage.php'); //Path to Magento
umask(0);
Mage::app(); // Change default to whatever store you want to run
$Config = new Mage_Core_Model_Config();
$Config ->saveConfig('web/default/cms_home_page', "city-grips-handle-bar-covers");
Mage::app()->cleanCache();
Voila it works. The configuration cache is really all that it needed to be cleaned (I confirmed this manually). So cleaning all the cache is a little overkill but oh well it works.