简体   繁体   English

如何使用seo Url以编程方式切换magento存储?

[英]How can i switch a magento store programatically with seo Url?

How can i switch a magento store programatically with seo Url without creating seperate folder ?. 如何在不创建单独文件夹的情况下使用seo Url编程切换magento存储?

I have a storeController in my custom module. 我的自定义模块中有一个storeController。

Its not working perfectly. 它不能正常工作。 current store cookie value not changed because it automatically goes to default store when i go to homepage. 当前商店的cookie值未更改,因为当我转到首页时它将自动进入默认商店。

This is what i want ( i need really a store switch effect). 这就是我想要的(我确实需要一个存储开关效果)。

www.site.com/module/store/id/ www.site.com/module/store/id/

My Store Controller 我的商店控制器

class Namespace_Module_StoreController extends Mage_Core_Controller_Front_Action
{
 public function indexAction()
 {   
    // site.com/module/store/12-store1

    $id = explode('-',$this->getRequest()->getParam('id'));
    $id = $id[0];

    $store = Mage::getModel( 'core/store' )->load($id); 

    $this->_title($this->__('Module'))->_title($store->getName());

    $rootCategoryId = $store->getRootCategoryId();

    Mage::app()->setCurrentStore($store->getStoreId()); 

    $this->loadLayout();   
    $this->renderLayout();
  }
}

A controller would be far to deep to switch stores at this point. 在这一点上,一个控制器要切换商店将是非常深入的。 Store run codes can only be set when the application loads at bootstrap level (yes, index.php ) and not at any point after (in which the controller dispatches are included). 仅当应用程序以引导程序级别加载时(是, index.php ),才可以设置商店运行代码,而不是在之后的任何时候(包括控制器分派)加载。

Try your luck somewhere else.. A good solution is to use .htaccess to set the MAGE_RUN_CODE (to your desired store view) and MAGE_RUN_TYPE (to store/website) environment variables before bootstrapping ever happens. 一个好的解决方案是使用.htaccess在引导发生之前将MAGE_RUN_CODE (设置为所需的商店视图)和MAGE_RUN_TYPE (设置为存储/网站)环境变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM