Question

I need to programmatically set a config based on the Magento instances' base_url. I cannot seem to access the base_url from my install/setup script:

$installer = $this;
$installer->startSetup();
var_dump(Mage::getStoreConfig('web/unsecure/base_url'));
var_dump(Mage::getBaseUrl());
var_dump(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB));
die();

This prints out:

null
string 'index.php/' (length=10)
string '/' (length=1)

I think it is possible that the configs are not initialised at this point and perhaps I need to initialise it. Or it seems more likely that Magento does not know which store the script is referring to. What are your suggestions?

Was it helpful?

Solution

My guess is you are executing this code in the sql directory. This one is only for altering the database structure. As you suspected not everything is initialised when the sql setup scripts are executed.

To work with data, put your code in the data directory.

The output of sql/emzee_exampleextension_setup/install-0.0.1.php:

NULL
string(10) "index.php/"
string(1) "/" 

The output of data/emzee_exampleextension_setup/data-install-0.0.1.php:

string(30) "http://test02.magentoshops.vm/"
string(30) "http://test02.magentoshops.vm/"
string(30) "http://test02.magentoshops.vm/" 
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top