/**
  * returns a single page by IdentifierCode
  * used to retrieve links dynamically
  *
  * @param string $identifierCode the classes name
  * @param bool   $force          Set to true to force a database access
  * 
  * @return SiteTree | false a single object of the site tree; without param the SilvercartFrontPage will be returned
  *
  * @author Sebastian Diel <*****@*****.**>
  * @since 26.07.2016
  */
 public static function PageByIdentifierCode($identifierCode = "SilvercartFrontPage", $force = false)
 {
     if (!array_key_exists($identifierCode, self::$pagesByIdentifierCode) || $force) {
         self::$pagesByIdentifierCode[$identifierCode] = SilvercartPage::get()->filter('IdentifierCode', $identifierCode)->first();
     }
     return self::$pagesByIdentifierCode[$identifierCode];
 }
 /**
  * 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;
 }
Example #3
0
 /**
  * Returns the main navigation root page (set in backend).
  * 
  * @return SilvercartPage
  * 
  * @author Sebastian Diel <*****@*****.**>
  * @since 06.10.2014
  */
 public function MainNavigationRootPage()
 {
     $mainNavigationRootPage = SilvercartPage::get()->filter('UseAsRootForMainNavigation', true)->first();
     if (is_null($mainNavigationRootPage)) {
         $mainNavigationRootPage = SilvercartTools::PageByIdentifierCode('SilvercartProductGroupHolder');
         DB::query('UPDATE SilvercartPage SET UseAsRootForMainNavigation = 1 WHERE ID = ' . $mainNavigationRootPage->ID);
         DB::query('UPDATE SilvercartPage_Live SET UseAsRootForMainNavigation = 1 WHERE ID = ' . $mainNavigationRootPage->ID);
     }
     return $mainNavigationRootPage;
 }