/**
  * We register the common forms for SilvercartPages here.
  *
  * @return void
  *
  * @author Sebastian Diel <*****@*****.**>,
  *         Sascha Koehler <*****@*****.**>,
  *         Patrick Schneider <*****@*****.**>
  * @since 08.07.2014
  */
 public function onBeforeInit()
 {
     SilvercartTools::initSession();
     i18n::set_default_locale(Translatable::get_current_locale());
     i18n::set_locale(Translatable::get_current_locale());
     $controllerParams = Controller::curr()->getURLParams();
     $anonymousCustomer = SilvercartCustomer::currentAnonymousCustomer();
     if ($anonymousCustomer) {
         Session::set('MemberLoginForm.force_message', true);
         if ($controllerParams['Action'] == 'changepassword') {
             $anonymousCustomer->logOut();
         }
     } else {
         Session::set('MemberLoginForm.force_message', false);
         // used to redirect the logged in user to my-account page
         $backURL = SilvercartTools::PageByIdentifierCodeLink(self::$newPasswordBackURLIdentifierCode);
         $this->owner->extend('updateNewPasswordBackURL', $backURL);
         Session::set('BackURL', $backURL);
         Session::save();
     }
     $this->owner->registerCustomHtmlForm('SilvercartQuickSearchForm', new SilvercartQuickSearchForm($this->owner));
     $this->owner->registerCustomHtmlForm('SilvercartQuickLoginForm', new SilvercartQuickLoginForm($this->owner));
     SilvercartPlugin::call($this->owner, 'init', array($this->owner));
 }
Example #2
0
 /**
  * standard page controller
  *
  * @return void
  * 
  * @author Roland Lehmann <*****@*****.**>,
  *         Sebastian Diel <*****@*****.**>
  * @since 15.11.2014
  */
 public function init()
 {
     if (array_key_exists('HTTP_USER_AGENT', $_SERVER)) {
         if (SilvercartConfig::isUserAgentBlacklisted($_SERVER['HTTP_USER_AGENT'])) {
             exit;
         }
     }
     if (array_key_exists($this->ID, self::$instanceMemorizer)) {
         parent::init();
         return true;
     }
     SilvercartTools::initSession();
     $controller = Controller::curr();
     if ($this != $controller && method_exists($controller, 'getRegisteredCustomHtmlForms')) {
         $registeredCustomHtmlForms = $controller->getRegisteredCustomHtmlForms();
     }
     if ($controller == $this || $controller->forceLoadOfWidgets) {
         $this->loadWidgetControllers();
     }
     $this->loadJSRequirements();
     // We have to check if we are in a customised controller (that's the
     // case for all Security pages). If so, we use the registered forms of
     // the outermost controller.
     if (empty($registeredCustomHtmlForms)) {
         $this->registerCustomHtmlForm('SilvercartQuickSearchForm', new SilvercartQuickSearchForm($this));
         $this->registerCustomHtmlForm('SilvercartQuickLoginForm', new SilvercartQuickLoginForm($this));
         if ($this->getTranslations()) {
             $this->registerCustomHtmlForm('SilvercartChangeLanguageForm', new SilvercartChangeLanguageForm($this));
         }
     } else {
         $this->setRegisteredCustomHtmlForms($registeredCustomHtmlForms);
     }
     $allParams = Controller::curr()->getRequest()->allParams();
     if (Controller::curr() instanceof Security && array_key_exists('Action', $allParams) && strtolower($allParams['Action']) == 'lostpassword' && Member::currentUserID() > 0 && SilvercartCustomer::currentUser() instanceof Member) {
         SilvercartCustomer::currentUser()->logOut();
     }
     if (Member::currentUserID() > 0 && !SilvercartCustomer::currentUser() instanceof Member) {
         Session::set('loggedInAs', 0);
         Session::save();
     }
     // check the SilverCart configuration
     if (!SilvercartTools::isIsolatedEnvironment()) {
         SilvercartConfig::Check();
     }
     // Delete checkout session data if user is not in the checkout process.
     if ($this->class != 'SilvercartCheckoutStep' && $this->class != 'SilvercartCheckoutStep_Controller' && $this->class != 'ErrorPage_Controller' && $this->class != 'Security' && $this->class != 'SilvercartFrontPage_Controller' && !$this->class instanceof SilvercartCheckoutStep_Controller && !$this->class instanceof Security && !is_subclass_of($this->class, 'SilvercartCheckoutStep_Controller')) {
         SilvercartCheckoutStep::deleteSessionStepData();
     }
     // Decorator can use this method to add custom forms and other stuff
     $this->extend('updateInit');
     SilvercartPlugin::call($this, 'init', array($this));
     self::$instanceMemorizer[$this->ID] = true;
     parent::init();
 }