Example #1
0
 /**
  * Redirect to allowed store with Geoip
  *
  * @param Varien_Object $observer
  *
  * @return void
  */
 public function redirectStore(Varien_Event_Observer $observer)
 {
     $enabled = Mage::getStoreConfigFlag('geoip/general/enabled');
     $lockStore = Mage::getStoreConfigFlag('geoip/general/lock');
     $exceptions = $this->_getExceptions();
     $fallbackStore = $this->_getFallbackStore();
     if (!$enabled) {
         return;
     }
     $this->checkNoRoute();
     $geoIP = Mage::getSingleton('geoip/country');
     $currentCountry = $geoIP->getCountry();
     $response = Mage::app()->getResponse();
     $session = Mage::getSingleton('core/session');
     $result = new Varien_Object(array('should_proceed' => 1));
     Mage::dispatchEvent('wh_geoip_redirect_store_before', array('result' => $result));
     if (!$result->getShouldProceed()) {
         return;
     }
     if ($this->_validateException($exceptions)) {
         return;
     }
     if ($geoIP->isCountryAllowed($currentCountry)) {
         $session->setIsGeoipRedirected(true);
         return;
     }
     $result = new Varien_Object(array('locked_store' => $lockStore));
     Mage::dispatchEvent('wh_geoip_redirect_store_check_locked_before', array('result' => $result));
     // Only redirect once per session if lock is not enabled
     if (!$result->getLockedStore() && $session->getIsGeoipRedirected()) {
         return;
     }
     // If locked mode is on and country is not in allowed countries: Don't
     // redirect when we are on fallback store.
     if ($result->getLockedStore() && $session->getNotInAllowedList() && Mage::app()->getStore()->getId() == $fallbackStore->getId()) {
         return;
     }
     $store = $this->_getStoreForCountry($currentCountry);
     if (!$store) {
         $store = $fallbackStore;
         $session->setNotInAllowedList(true);
     }
     $event = new Varien_Object(array('store_url' => $store->getCurrentUrl(false)));
     Mage::dispatchEvent('wh_geoip_redirect_store_set_redirect_before', array('result' => $event));
     $session->setIsGeoipRedirected(true);
     $response->setRedirect($event->getStoreUrl())->sendResponse();
     exit;
 }