Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Atwix_Ipstoreswitcher_Model_Observer
- {
- /**
- * redirects customer to store view based on GeoIP
- * @param $event
- */
- public function controllerActionPostdispatch($event)
- {
- $cookie = Mage::getSingleton('core/cookie');
- if ($cookie->get('geoip_processed') != 1) {
- $geoIPCountry = Mage::getSingleton('geoip/country');
- $countryCode = $geoIPCountry->getCountry();
- if ($countryCode) {
- $storeName = Mage::helper('atwix_ipstoreswitcher')->getStoreByCountry($countryCode);
- if ($storeName) {
- $store = Mage::getModel('core/store')->load($storeName, 'code');
- if ($store->getName() != Mage::app()->getStore()->getName()) {
- $event->getControllerAction()->getResponse()->setRedirect($store->getCurrentUrl(false));
- }
- }
- }
- $cookie->set('geoip_processed', '1', time() + 86400, '/');
- }
- }
- }
- ?>
- <?php Mage::log($countryCode) ?>
- <?php Mage::log($storeName) ?>
Add Comment
Please, Sign In to add comment