4

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?

7

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/" 
  • 1
    I found this question after banging my head on the desk for 2 hours. I can confirm that from the sql directory, Mage::getStoreConfig(anything) is always empty. But Mage::getConfig()->saveConfig(...) works. – Dr. Gianluigi Zane Zanettini Apr 18 '17 at 12:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.