【发布时间】:2012-11-13 10:40:44
【问题描述】:
我想通过客户的 IP 经营商店。
在 Magento 的后端,用户可以配置具体的商店来加载每个国家。
一看,我看到了类Mage_Core_Model_App的方法
public function run($params)
{
$options = isset($params['options']) ? $params['options'] : array();
$this->baseInit($options);
if ($this->_cache->processRequest()) {
$this->getResponse()->sendResponse();
} else {
$this->_initModules();
$this->loadAreaPart(Mage_Core_Model_App_Area::AREA_GLOBAL, Mage_Core_Model_App_Area::PART_EVENTS);
if ($this->_config->isLocalConfigLoaded()) {
//$scopeCode = isset($params['scope_code']) ? $params['scope_code'] : '';
//===============custom scope by country======================
$scopeCode = Mage::helper('custom/module')->getStoreByGeoip();
//===============custom scope by country======================
$scopeType = isset($params['scope_type']) ? $params['scope_type'] : 'store';
$this->_initCurrentStore($scopeCode, $scopeType);
$this->_initRequest();
Mage_Core_Model_Resource_Setup::applyAllDataUpdates();
}
$this->getFrontController()->dispatch();
}
return $this;
}
在获得好的解决方案的过程中,我想到了另一种选择。
在index.php中写下一段代码:
Mage::app();
Mage::Helper('custom/helper')->getRunCodeByGeoio();
Mage::run($mageRunCode, $mageRunType);
我认为这对性能没有危险,因为这种方法只会在你之前没有创建对象的情况下创建对象
/**
* Get initialized application object.
*
* @param string $code
* @param string $type
* @param string|array $options
* @return Mage_Core_Model_App
*/
public static function app($code = '', $type = 'store', $options = array())
{
if (null === self::$_app) {
self::$_app = new Mage_Core_Model_App();
self::setRoot();
self::$_events = new Varien_Event_Collection();
self::$_config = new Mage_Core_Model_Config();
Varien_Profiler::start('self::app::init');
self::$_app->init($code, $type, $options);
Varien_Profiler::stop('self::app::init');
self::$_app->loadAreaPart(Mage_Core_Model_App_Area::AREA_GLOBAL, Mage_Core_Model_App_Area::PART_EVENTS);
}
return self::$_app;
}
我的问题是......
这是获得解决方案的最佳方法吗??
我认为修改 Mage_Core_Model_App 即使使用重写也是非常危险的
我没有任何级别的活动
另一种选择是在index.php中做业务却失去了后端的管理
正在搜索....,找到了满足我许多要求的扩展, http://www.mageworx.com/store-and-currency-auto-switcher-magento-extension.html 那我就买这个或者做一个类似的扩展。
【问题讨论】:
-
我被分配了相同的任务,并且确实尝试寻找可以帮助我做到这一点的事件,但我能够实现的唯一方法是(在获得 [整个过程]访问者 ip 的国家/地区)重定向到特定(指定)商店。
-
这个模块可以帮助你mageworx.com/…