【问题标题】:Magento - Change store base url programaticallyMagento - 以编程方式更改商店基本网址
【发布时间】:2012-11-22 08:13:05
【问题描述】:

我想以编程方式更改 magento 商店的基本 URL(安全和不安全)。

可以在后台手动更改设置,如下图所示:

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

我想为我的每家商店更改 4 和 5 的值。

类似这样的:

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

对我如何做到这一点有任何帮助吗?

【问题讨论】:

    标签: magento


    【解决方案1】:

    这最好在数据设置脚本中完成(不是“普通”设置脚本);见Mage_Core_Model_Resource_Setup::setConfigData()

    在设置脚本中,循环遍历商店并设置数据如下:

    /*
        ...
        @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);
    }
    
    /* ... */
    

    显然,您可以决定如何为每个正确的商店注入 URL。

    【讨论】:

      【解决方案2】:

      我知道一种方法是直接更新数据库中的数据,但可能有更好的方法:

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

      scope_idstore_id,当范围是“存储”时。您可以在那里更新或插入值。

      【讨论】:

        【解决方案3】:

        对于生产环境,您可以在数据库中写入路径'web/unsecure/base_url' 和路径'web/secure/base_url' 只需{{base_url}}

        因此,Magento 将您所在的实际网址作为基本网址。

        【讨论】:

          猜你喜欢
          • 2016-03-26
          • 2018-04-22
          • 1970-01-01
          • 1970-01-01
          • 2015-05-18
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2016-09-27
          相关资源
          最近更新 更多