Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

magento set store id programmatically

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?

like image 434
maximus 69 Avatar asked Mar 26 '12 10:03

maximus 69


2 Answers

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 :)

like image 164
maximus 69 Avatar answered Sep 28 '22 00:09

maximus 69


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

like image 45
Sarath Tomy Avatar answered Sep 28 '22 00:09

Sarath Tomy