The question:
we have multi store views site.
we provide an option to change store views through dropdown here as below :
once we change option from dropdown, it will display selected store view.
but once we click on any other page[ menu, catalog, Product ,cms ] it will again display old store view.
but it should be in same store view until we change it manually.
Is i need to use cookies for saving ?
observer.php
class Atwix_Ipstoreswitcher_Model_Observer
{
/**
* redirects customer to store view based on GeoIP
* @param $event
*/
public function controllerActionPostdispatch($event)
{
if(!empty($_GET['___from_store']))
{
Mage::app()->setCurrentStore($_GET['___store']);
}
else
{
$geoIP = Mage::getSingleton('geoip/country');
$cnCode = $geoIP->getCountry();
// echo $cnCode;
// echo $cnCode='IN';
switch ($cnCode) {
case "US": {
Mage::app()->setCurrentStore('india');
break;
}
case "IN": {
Mage::app()->setCurrentStore('india');
break;
}
case "CA": {
Mage::app()->setCurrentStore('india');
break;
}
case "UK": {
Mage::app()->setCurrentStore('india');
break;
}
case "AU": {
Mage::app()->setCurrentStore('india');
break;
}
}
}
}
}
language.phtml
<?php if(count($this->getStores())>1): ?>
<?php
$lis = "";
$selCurrency = $this->__('Currency');
foreach ($this->getStores() as $_lang):
if($_lang->getId() == $this->getCurrentStoreId()){
//This line will show SYMBOL only
//$selCurrency = "[".Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol()."]";
//This line will show FULLNAME
$selCurrency = ' '.$this->escapeHtml($_lang->getName());
}
$lis .= '<li><a href="'.$_lang->getCurrentUrl().'" rel="nofollow noreferrer noopener">'.$this->escapeHtml($_lang->getName()).'</a></li>';
endforeach;
?>
<div class="form-language">
<ul id="select-language" title="<?php echo $this->__('Currency') ?>" class="dropDownMenu">
<li><a href=""><?php echo $selCurrency ?></a>
<ul>
<?php echo $lis ?>
</ul>
</li>
</ul>
</div>
<?php endif; ?>
The Solutions:
Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.
Method 1
First of all, looks like your observer.php sets the store always to “India”, is that correct?
About your question, the best option is to have a separate URL for each store view, which could be a subdirectory (example.com/store2
), subdomain (store2.example.com
) or even a new domain (example2.com
).
This link explains more about this topic.
After choosing your approach, you need to:
- Create the Store View in Magento admin panel
- Create the new address (subdomain, subdirectory or new domain) in you server and copy the files index.php and .htaccess to that new folder.
-
Edit the bottom of index.php in the line:
Mage::run($mageRunCode, $mageRunType);
to set your RunCode (code of the store defined in Magento admin) and RunType (store or website). -
Go to
System > Configuration > General > Web
and make sure that you are editing the right Store View (you can change it in the upper left corner under “Current Configuration Scope”). -
Under the tabs
Unsecure
andSecure
, change theBase URL
field to match your new store view URL.
After that, you need to create symlinks for the Magento files, this will allow you to keep navigating in the same store view.
Use SSH to access the root folder of your new storeview
/home/example/example.com/html/store2/
and execute this:
ln -s /home/example/example.com/html/app/ app
ln -s /home/example/example.com/html/includes/ includes
ln -s /home/example/example.com/html/js/ js
ln -s /home/example/example.com/html/lib/ lib
ln -s /home/example/example.com/html/media/ media
ln -s /home/example/example.com/html/skin/ skin
ln -s /home/example/example.com/html/var/ var
This should solve your problem.
If you want to read more:
https://docs.nexcess.net/article/how-to-configure-multiple-magento-storefronts.html
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0