Guest User

added

a guest
Apr 29th, 2016
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4.  
  5. class Atwix_Ipstoreswitcher_Model_Observer
  6. {
  7. /**
  8. * redirects customer to store view based on GeoIP
  9. * @param $event
  10. */
  11. public function controllerActionPostdispatch($event)
  12. {
  13. $cookie = Mage::getSingleton('core/cookie');
  14. if ($cookie->get('geoip_processed') != 1) {
  15. $geoIPCountry = Mage::getSingleton('geoip/country');
  16. $countryCode = $geoIPCountry->getCountry();
  17. if ($countryCode) {
  18. $storeName = Mage::helper('atwix_ipstoreswitcher')->getStoreByCountry($countryCode);
  19. if ($storeName) {
  20. $store = Mage::getModel('core/store')->load($storeName, 'code');
  21. if ($store->getName() != Mage::app()->getStore()->getName()) {
  22. $event->getControllerAction()->getResponse()->setRedirect($store->getCurrentUrl(false));
  23. }
  24. }
  25. }
  26. $cookie->set('geoip_processed', '1', time() + 86400, '/');
  27. }
  28. }
  29. }
  30.  
  31.  
  32. ?>
  33.  
  34. <?php Mage::log($countryCode) ?>
  35. <?php Mage::log($storeName) ?>
Add Comment
Please, Sign In to add comment