0
votes

I want to programmatically change the base URL (secure and unsecure) for a magento store.

The settings can be changed manually in the backend, seen in the following picture:

http://geo.magenting.com/m/kb/images/attachments/change-magento-base-url_1.jpg

I want to change the values at 4 & 5 for each of my stores.

Something like this:

$store = Mage::getModel('core/store')->load($storeId);
$store -> setBaseUrlSecure("xyz.com");
$store -> save();

Any help on how I can do that?

3

3 Answers

4
votes

This is best done in a data setup script (not a "normal" setup script); see Mage_Core_Model_Resource_Setup::setConfigData().

In the setup script, loop through the stores and set the data as follows:

/*
    ...
    @var $installer Mage_Core_Model_Resource_Setup
*/
$stores = Mage::app()->getStores();
foreach ($stores as $storeId => $store) {
    $installer->setConfigData('web/unsecure/base_url',$value,'stores',$storeId);
    $installer->setConfigData('web/secure/base_url',$sValue,'stores',$storeId);
}

/* ... */

Obviously it's up to you to determine how to inject the URLs for each correct store.

1
votes

I know one way is to update the data directly in your database, but there might be better ways to do it:

SELECT * FROM core_config_data where path like 'web/unsecure/base_url' or path like 'web/secure/base_url';

The scope_id is the store_id when the scope is "stores". You can just update or insert the values there.

0
votes

for production environment you could write in the database at the path 'web/unsecure/base_url' and at the path 'web/secure/base_url' simply {{base_url}}.

So Magento take the actual Url you are on for the base url.