10

I am currently working on a magento site that is in 2 languages (French and Dutch). The approach I am taking is as follows:

  • Create a folder in the web root (named nl)
  • Import the index.php and .htaccess file to that folder
  • In the index.php I modify the following line:

    Mage::run('nl'); // to specify the store view i want to load
    

When I check, the categories, CMS content etc are still in the default language. The following code:

Mage::app()->getStore()->getName();

returns the fr store's name.

What is it that I'm doing wrong? I think a viable solution would be to set the store to run in index.php...

Could someone please let me know how to load a store by ID?

Cœur
  • 37,241
  • 25
  • 195
  • 267
maximus 69
  • 1,388
  • 4
  • 22
  • 35

3 Answers3

28

After hours of huffing and puffing i was able to figure out a way to set the store id programatically :)

In the index.php file, (in your language specific folder), add the following:-

$store_id = 'your_store_id_here';
$mageRunCode = 'store view code';
$mageRunType = 'store';

Mage::app()->setCurrentStore($store_id);
Mage::run($mageRunCode, $mageRunType);

Hope someone will find this information useful :)

maximus 69
  • 1,388
  • 4
  • 22
  • 35
  • Can you tell me the location where I should update this code ? – Chiragit007 Sep 17 '13 at 10:08
  • 3
    You could also go with something like `$store = Mage::getModel('core/store')->load([store id]);` if you don't want to globally set the store to one thing for the whole app. This is handy if you're working with a few models like customers and products in the same code and you don't want to limit results to one store for everything. – Pooch Sep 30 '13 at 22:03
  • For some reason, setCurrentStore() wasn't working for me. Instead, I changed $mageRunType to 'group' and then used the store ID for the code. Hope that helps someone. This is with 1.8.1.0. – jessedb Mar 09 '15 at 11:13
  • setCurrentStore() work for me in my case setCurrentStore('default') – jruzafa Jun 10 '16 at 15:24
5

You will get all store details here

<?php
$allStores = Mage::app()->getStores();
foreach ($allStores as $_eachStoreId => $val) 
{
$_storeCode = Mage::app()->getStore($_eachStoreId)->getCode();
$_storeName = Mage::app()->getStore($_eachStoreId)->getName();
$_storeId = Mage::app()->getStore($_eachStoreId)->getId();
echo $_storeId;
echo $_storeCode;
echo $_storeName;
}
?>

To redirect to the specified store, you need to redirect the page along with the store code.

http://www.mywebsite.com/index.php/store_code/

Please check the template/page/switch/stores.phtml for more details

Sarath Tomy
  • 504
  • 4
  • 12
  • Thanks for your reply Sarath, but i haven't enabled 'Add store code to url' in the admin so the above won't work.. – maximus 69 Mar 26 '12 at 11:10
3

If the reason you're doing the htaccess stuff is so that you can generate URLs specific to each store, you may want to go with the configuration option that does that for you, should be in System > Config > Web

kalenjordan
  • 2,446
  • 1
  • 24
  • 38