How can i switch a magento store programatically with seo Url without creating seperate folder ?.
I have a storeController in my custom module.
Its not working perfectly. current store cookie value not changed because it automatically goes to default store when i go to homepage.
This is what i want ( i need really a store switch effect).
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).
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.