1

Having multiple development stages, I'd like to keep some magento configurations in a file, and not in the database, so i can have my development version and the production version in sync.

So i need to put in a different place the "base url", that is not the database, because I'd like to export it from production to development

is it possible?

Alive Developer
  • 1,022
  • 1
  • 13
  • 25

1 Answers1

5

It's possible:

<default>
    <web>
        <unsecure>
            <base_url>https://foo.dev/</base_url>
        </unsecure>
        <secure>
            <base_url>https://foo.dev/</base_url>
        </secure>
    </web>
</default>
<websites>
    <ws_code>
        <web>
            <unsecure>
                <base_url>http://ws.foo.dev/</base_url>
            </unsecure>
            <secure>
                <base_url>https://ws.foo.dev/</base_url>
            </secure>
        </web>            
    </ws_code>
</websites>
<stores>
    <store_code>
        <web>
            <unsecure>
                <base_url>http://store.foo.dev/</base_url>
            </unsecure>
            <secure>
                <base_url>https://store.foo.dev/</base_url>
            </secure>
        </web>            
    </store_code>
</stores>

However if anyone ever saves (or has saved) the System > Configuration > Web section in the admin, the values in your config file for that scope will not apply.

There are a couple of strategies for protecting your entries

  1. Use the file-based config approach and disable access to the Web section via admin user roles (for all users). Caveat: you'll need to provide all of the configuration options in your config.

  2. Use setup scripts (PHP) to write the base_url entries to the core_config_data table, and protect them from being overwritten via an observer configured under the adminhtml event area for the core_config_data_save_before event.

You could also combine the observer protection from strategy #2 with the file-based config from strategy #1.

benmarks
  • 23,384
  • 1
  • 62
  • 84
  • where should this config file be located? – Alive Developer Jul 12 '13 at 15:52
  • If it's part of your module config. – benmarks Jul 12 '13 at 16:34
  • `app/etc/config.xml?` – Alive Developer Jul 15 '13 at 14:20
  • 1
    Absolutely not. That is a core file. You could make this part of your module's *`config.xml`*. You could also use the approach of providing any *`.xml`* file in the *`app/etc/`* directory that does not collide with core files. – benmarks Jul 15 '13 at 15:03
  • It worked like a charm!! and can it be done also for cookies? I tries something like ` mydomain.com ` but had no results – Alive Developer Jul 16 '13 at 15:34
  • Just find the partial xpath in *`system.xml`* files. For example, the `cookie_domain` xpath is `web/cookie/cookie_domain` - ref https://github.com/benmarks/magento-mirror/blob/1.7.0.2/app/code/core/Mage/Core/etc/system.xml#L1394 – benmarks Jul 16 '13 at 16:05
  • I've created a file called baseurl.xml and placed it in app/etc and pasted your code above in (with my domain of course). However, it doesn't work and I get a white screen with the error "Fatal error: Call to a member function extend() on a non-object in /blah/htdocs/mage/dev/src/lib/Varien/Simplexml/Config.php on line 600". Any ideas? – PedroKTFC May 01 '14 at 19:49
  • @PedroKTFC Your file has invalid syntax. – benmarks May 01 '14 at 19:51
  • Well so has your answer then! :o) I've even copied and pasted exactly your answer and I still get the error. Should there be any other tags around it? Thanks muchly btw. – PedroKTFC May 01 '14 at 21:40
  • NP. [All XML documents require a root node to be valid.](http://en.wikipedia.org/wiki/Root_element) – benmarks May 01 '14 at 22:22
  • Ben, in case you haven't noticed, I've put the detail of what I've done in an answer below. Still not working, any suggestions? – PedroKTFC May 04 '14 at 14:00
  • Will you move that post to a new question please? That's the "Stack" way of doing things :-) – benmarks May 04 '14 at 16:59
  • Done, see here: http://stackoverflow.com/questions/23478843/unable-to-set-base-url-from-config-file – PedroKTFC May 05 '14 at 18:05
  • [Although I updated the above question, thought I'd echo my findings here] I finally tracked it down! My settings are being overwritten by those in in `app/code/core/Mage/core/etc/config.xml`. This is a pain as all I want is a simple way of specifying base urls for dev/test/prod type environments. Using a module seems a little OTT for something like this. – PedroKTFC May 09 '14 at 07:04
  • Nope; I promise they are being overwritten by the database-based settings. `Mage_Core` config is merged well before your module; see [`Mage_Core_Model_Config::_getDeclaredModuleFiles()`](https://github.com/benmarks/magento-mirror/blob/magento-1.8/app/code/core/Mage/Core/Model/Config.php#L698). Also, see where the DB config is merged in after file merging in [`Mage_Core_Model_Config::init()`](https://github.com/benmarks/magento-mirror/blob/magento-1.8/app/code/core/Mage/Core/Model/Config.php#L248) – benmarks May 09 '14 at 17:57