/**
  * Creates the default SiteTree if not exists
  * 
  * @return SilvercartFrontPage
  *
  * @author Sebastian Diel <*****@*****.**>
  * @since 02.05.2012
  */
 public function createDefaultSiteTree()
 {
     $rootPage = SilvercartPage::get()->filter('IdentifierCode', 'SilvercartCartPage')->first();
     if (!$rootPage) {
         //create a silvercart front page (parent of all other SilverCart pages
         $rootPage = new SilvercartFrontPage();
         $rootPage->IdentifierCode = "SilvercartFrontPage";
         $rootPage->Title = 'SilverCart';
         $rootPage->MenuTitle = "SilverCart";
         if (SiteTree::get_by_link('home')) {
             $rootPage->URLSegment = 'webshop';
         } else {
             $rootPage->URLSegment = 'home';
         }
         $rootPage->ShowInMenus = false;
         $rootPage->ShowInSearch = false;
         $rootPage->Status = "Published";
         $rootPage->CanViewType = "Anyone";
         $rootPage->Content = _t('SilvercartFrontPage.DEFAULT_CONTENT', '<h2>Welcome to <strong>SilverCart</strong> Webshop!</h2>');
         $rootPage->write();
         $rootPage->publish("Stage", "Live");
         //create a silvercart product group holder as a child af the silvercart root
         $productGroupHolder = new SilvercartProductGroupHolder();
         $productGroupHolder->Title = _t('SilvercartProductGroupHolder.DEFAULT_TITLE', 'product groups');
         $productGroupHolder->URLSegment = _t('SilvercartProductGroupHolder.DEFAULT_URLSEGMENT', 'productgroups');
         $productGroupHolder->Status = "Published";
         $productGroupHolder->ParentID = $rootPage->ID;
         $productGroupHolder->IdentifierCode = "SilvercartProductGroupHolder";
         $productGroupHolder->InheritFromParent = false;
         $productGroupHolder->UseAsRootForMainNavigation = true;
         $productGroupHolder->write();
         $productGroupHolder->publish("Stage", "Live");
         //create a cart page
         $cartPage = new SilvercartCartPage();
         $cartPage->Title = _t('SilvercartCartPage.DEFAULT_TITLE');
         $cartPage->URLSegment = _t('SilvercartCartPage.DEFAULT_URLSEGMENT', 'cart');
         $cartPage->Status = "Published";
         $cartPage->ShowInMenus = true;
         $cartPage->ShowInSearch = false;
         $cartPage->IdentifierCode = "SilvercartCartPage";
         $cartPage->ParentID = $rootPage->ID;
         $cartPage->InheritFromParent = false;
         $cartPage->write();
         $cartPage->publish("Stage", "Live");
         //create a silvercart checkout step (checkout) as achild of the silvercart root
         $checkoutStep = new SilvercartCheckoutStep();
         $checkoutStep->Title = _t('SilvercartCheckoutStep.DEFAULT_TITLE');
         $checkoutStep->URLSegment = _t('SilvercartCheckoutStep.DEFAULT_URLSEGMENT', 'checkout');
         $checkoutStep->Status = "Published";
         $checkoutStep->ShowInMenus = true;
         $checkoutStep->ShowInSearch = true;
         $checkoutStep->basename = 'SilvercartCheckoutFormStep';
         $checkoutStep->showCancelLink = true;
         $checkoutStep->cancelPageID = $cartPage->ID;
         $checkoutStep->ParentID = $rootPage->ID;
         $checkoutStep->IdentifierCode = "SilvercartCheckoutStep";
         $checkoutStep->InheritFromParent = false;
         $checkoutStep->write();
         $checkoutStep->publish("Stage", "Live");
         //create a silvercart order confirmation page as a child of the silvercart root
         $orderConfirmationPage = new SilvercartOrderConfirmationPage();
         $orderConfirmationPage->Title = _t('SilvercartOrderConfirmationPage.DEFAULT_TITLE', 'order conirmation page');
         $orderConfirmationPage->URLSegment = _t('SilvercartOrderConfirmationPage.DEFAULT_URLSEGMENT', 'order-conirmation');
         $orderConfirmationPage->Status = "Published";
         $orderConfirmationPage->ShowInMenus = false;
         $orderConfirmationPage->ShowInSearch = false;
         $orderConfirmationPage->CanViewType = "LoggedInUsers";
         $orderConfirmationPage->IdentifierCode = "SilvercartOrderConfirmationPage";
         $orderConfirmationPage->ParentID = $rootPage->ID;
         $orderConfirmationPage->InheritFromParent = false;
         $orderConfirmationPage->write();
         $orderConfirmationPage->publish("Stage", "Live");
         //create a payment notification page as a child of the silvercart root
         $paymentNotification = new SilvercartPaymentNotification();
         $paymentNotification->Title = _t('SilvercartPaymentNotification.DEFAULT_TITLE', 'payment notification');
         $paymentNotification->URLSegment = _t('SilvercartPaymentNotification.DEFAULT_URLSEGMENT', 'payment-notification');
         $paymentNotification->Status = 'Published';
         $paymentNotification->ShowInMenus = 0;
         $paymentNotification->ShowInSearch = 0;
         $paymentNotification->ParentID = $rootPage->ID;
         $paymentNotification->IdentifierCode = "SilvercartPaymentNotification";
         $paymentNotification->InheritFromParent = false;
         $paymentNotification->write();
         $paymentNotification->publish('Stage', 'Live');
         DB::alteration_message('SilvercartPaymentNotification Page created', 'created');
         //create a silvercart registration page as a child of silvercart root
         $registrationPage = new SilvercartRegistrationPage();
         $registrationPage->Title = _t('SilvercartRegistrationPage.DEFAULT_TITLE', 'registration page');
         $registrationPage->URLSegment = _t('SilvercartRegistrationPage.DEFAULT_URLSEGMENT', 'registration');
         $registrationPage->Status = "Published";
         $registrationPage->ShowInMenus = false;
         $registrationPage->ShowInSearch = true;
         $registrationPage->ParentID = $rootPage->ID;
         $registrationPage->IdentifierCode = "SilvercartRegistrationPage";
         $registrationPage->InheritFromParent = false;
         $registrationPage->write();
         $registrationPage->publish("Stage", "Live");
         //create a silvercart registration confirmation page as a child the silvercart registration page
         $registerConfirmationPage = new SilvercartRegisterConfirmationPage();
         $registerConfirmationPage->Title = _t('SilvercartRegisterConfirmationPage.DEFAULT_TITLE', 'register confirmation page');
         $registerConfirmationPage->URLSegment = _t('SilvercartRegisterConfirmationPage.DEFAULT_URLSEGMENT', 'register-confirmation');
         $registerConfirmationPage->Content = _t('SilvercartRegisterConfirmationPage.DEFAULT_CONTENT');
         $registerConfirmationPage->Status = "Published";
         $registerConfirmationPage->ParentID = $registrationPage->ID;
         $registerConfirmationPage->ShowInMenus = false;
         $registerConfirmationPage->ShowInSearch = false;
         $registerConfirmationPage->CanViewType = "LoggedInUsers";
         $registerConfirmationPage->IdentifierCode = "SilvercartRegisterConfirmationPage";
         $registerConfirmationPage->write();
         $registerConfirmationPage->publish("Stage", "Live");
         //create a silvercart search results page as a child of the silvercart root
         $searchResultsPage = new SilvercartSearchResultsPage();
         $searchResultsPage->Title = _t('SilvercartSearchResultsPage.DEFAULT_TITLE', 'search results');
         $searchResultsPage->URLSegment = _t('SilvercartSearchResultsPage.DEFAULT_URLSEGMENT', 'search-results');
         $searchResultsPage->Status = "Published";
         $searchResultsPage->ShowInMenus = false;
         $searchResultsPage->ShowInSearch = false;
         $searchResultsPage->ParentID = $rootPage->ID;
         $searchResultsPage->IdentifierCode = "SilvercartSearchResultsPage";
         $searchResultsPage->InheritFromParent = false;
         $searchResultsPage->write();
         $searchResultsPage->publish("Stage", "Live");
         $this->createDefaultSiteTreeCMSSection($rootPage);
     }
     return $rootPage;
 }
示例#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();
 }