/**
  * Returns the input fields for this widget.
  * 
  * @param Widget $widget       Widget to initialize
  * @param array  $fetchMethods Optional list of product fetch methods
  * 
  * @return FieldList
  * 
  * @author Sebastian Diel <*****@*****.**>
  * @since 13.03.2014
  */
 public static function getCMSFieldsForProductSliderWidget(Widget $widget, $fetchMethods = array())
 {
     if (empty($fetchMethods)) {
         $fetchMethods = array('random' => $widget->fieldLabel('fetchMethodRandom'), 'sortOrderAsc' => $widget->fieldLabel('fetchMethodSortOrderAsc'), 'sortOrderDesc' => $widget->fieldLabel('fetchMethodSortOrderDesc'));
     }
     $fields = SilvercartDataObject::getCMSFields($widget, 'ExtraCssClasses', false);
     $productGroupDropdown = new TreeDropdownField('SilvercartProductGroupPageID', $widget->fieldLabel('SilvercartProductGroupPage'), 'SiteTree');
     $productGroupDropdown->setTreeBaseID(SilvercartTools::PageByIdentifierCode('SilvercartProductGroupHolder')->ID);
     $toggleFields = array($fields->dataFieldByName('numberOfProductsToShow'), $fields->dataFieldByName('numberOfProductsToFetch'), $fields->dataFieldByName('fetchMethod'), SilvercartGroupViewHandler::getGroupViewDropdownField('GroupView', $widget->fieldLabel('GroupView'), $widget->GroupView));
     $fields->dataFieldByName('fetchMethod')->setSource($fetchMethods);
     $fields->dataFieldByName('numberOfProductsToShow')->setDescription($widget->fieldLabel('numberOfProductsToShowInfo'));
     $fields->dataFieldByName('isContentView')->setDescription($widget->fieldLabel('isContentViewInfo'));
     if (is_object($fields->dataFieldByName('useSelectionMethod'))) {
         $fields->dataFieldByName('useSelectionMethod')->setSource(array('productGroup' => $widget->fieldLabel('SelectionMethodProductGroup'), 'products' => $widget->fieldLabel('SelectionMethodProducts')));
         $toggleFields[] = $fields->dataFieldByName('useSelectionMethod');
         $productGroupDropdown->setDescription($widget->fieldLabel('SilvercartProductGroupPageDescription'));
     }
     $toggleFields[] = $productGroupDropdown;
     $productDataToggle = ToggleCompositeField::create('ProductDataToggle', $widget->fieldLabel('ProductDataToggle'), $toggleFields)->setHeadingLevel(4);
     $productRelationToggle = ToggleCompositeField::create('ProductRelationToggle', $widget->fieldLabel('ProductRelationToggle'), array($fields->dataFieldByName('SilvercartProducts')))->setHeadingLevel(4);
     $fields->removeByName('numberOfProductsToShow');
     $fields->removeByName('numberOfProductsToFetch');
     $fields->removeByName('fetchMethod');
     $fields->removeByName('useSelectionMethod');
     $fields->removeByName('SilvercartProducts');
     $fields->addFieldToTab("Root.Main", $productDataToggle);
     $fields->addFieldToTab("Root.Main", $productRelationToggle);
     $widget->getCMSFieldsSliderTab($fields);
     //$widget->getCMSFieldsRoundaboutTab($fields);
     return $fields;
 }
 /**
  * Adds the fields for the MirrorProductGroups tab
  *
  * @param FieldList $fields FieldList to add fields to
  * 
  * @return void
  */
 public function getFieldsForProductGroups($fields)
 {
     $productGroupHolder = SilvercartTools::PageByIdentifierCode('SilvercartProductGroupHolder');
     $silvercartProductGroupDropdown = new TreeDropdownField('SilvercartProductGroupID', $this->fieldLabel('SilvercartProductGroup'), 'SiteTree');
     if ($productGroupHolder) {
         $productGroupHolderID = $productGroupHolder->ID;
     } else {
         $productGroupHolderID = 0;
     }
     $silvercartProductGroupDropdown->setTreeBaseID($productGroupHolderID);
     if ($this->exists()) {
         $silvercartProductGroupMirrorPagesField = new TreeMultiselectField('SilvercartProductGroupMirrorPages', $this->fieldLabel('SilvercartProductGroupMirrorPages'), 'SiteTree');
         $silvercartProductGroupMirrorPagesField->setTreeBaseID($productGroupHolderID);
         $fields->removeByName('SilvercartProductGroupMirrorPages');
         $fields->insertBefore($silvercartProductGroupDropdown, 'ProductNumberGroup');
         $fields->insertAfter($silvercartProductGroupMirrorPagesField, 'SilvercartProductGroupID');
     } else {
         $fields->insertBefore($silvercartProductGroupDropdown, 'ProductNumberGroup');
     }
 }
 /**
  * returns a page by IdentifierCode
  *
  * @param string $identifierCode the DataObjects IdentifierCode
  *
  * @return string
  *
  * @author Sascha Koehler <*****@*****.**>, Sebastian Diel <*****@*****.**>
  * @since 21.02.2013
  */
 public function PageByIdentifierCode($identifierCode = "SilvercartFrontPage")
 {
     return SilvercartTools::PageByIdentifierCode($identifierCode);
 }
 /**
  * Returns the "My Account" page object.
  * 
  * @return SilvercartMyAccountHolder
  * 
  * @author Sascha Koehler <*****@*****.**>
  * @since 26.05.2011
  */
 public function MyAccountPage()
 {
     return SilvercartTools::PageByIdentifierCode('SilvercartMyAccountHolder');
 }
 /**
  * Returns an instance of SilvercartCheckoutFormStep2 to represent a valid 
  * checkout context.
  * 
  * @return SilvercartCheckoutFormStep2
  */
 public function getCheckoutContext()
 {
     $checkoutStepPage = SilvercartTools::PageByIdentifierCode('SilvercartCheckoutStep');
     $checkoutStepPageController = ModelAsController::controller_for($checkoutStepPage);
     $checkoutStepPageController->handleRequest($this->getRequest(), DataModel::inst());
     return new SilvercartCheckoutFormStep2($checkoutStepPageController);
 }
 /**
  * Action to execute a search query
  * 
  * @param SS_HTTPRequest $request    Request to check for product data
  * @param bool           $doRedirect Redirect after setting search settings?
  * 
  * @return void
  *
  * @author Sebastian Diel <*****@*****.**>
  * @since 30.06.2014
  */
 public function doSearch(SS_HTTPRequest $request, $doRedirect = true)
 {
     $postVars = $request->postVars();
     if (!array_key_exists('locale', $postVars) || empty($postVars['locale'])) {
         $postVars['locale'] = Translatable::default_locale();
     }
     Translatable::set_current_locale($postVars['locale']);
     i18n::set_locale($postVars['locale']);
     $quickSearchQuery = trim($postVars['quickSearchQuery']);
     $searchContext = 'SilvercartProduct';
     $searchResultsPage = SilvercartTools::PageByIdentifierCode("SilvercartSearchResultsPage");
     $searchQuery = SilvercartSearchQuery::get_by_query(trim(Convert::raw2sql($quickSearchQuery)));
     $searchQuery->Count++;
     $searchQuery->write();
     SilvercartProduct::setDefaultSort('relevance');
     Session::set("searchQuery", $quickSearchQuery);
     Session::set('searchContext', $searchContext);
     Session::save();
     if ($doRedirect) {
         $this->owner->redirect($searchResultsPage->RelativeLink());
     }
 }
 /**
  * Returns the URL for payment notifications.
  *
  * @return string
  *
  * @author Sascha Koehler <*****@*****.**>
  * @since 01.10.2012
  */
 public function getNotificationUrl()
 {
     $notifyUrl = Director::absoluteUrl(SilvercartTools::PageByIdentifierCode('SilvercartPaymentNotification')->Link() . 'process/' . $this->moduleName);
     return $notifyUrl;
 }
 /**
  * Returns the contact form page.
  * 
  * @return SilvercartContactFormPage
  * 
  * @author Sebastian Diel <*****@*****.**>
  * @since 21.04.2015
  */
 protected function ContactPage()
 {
     $contactPage = $this->Controller();
     if ($contactPage->IdentifierCode != 'SilvercartContactFormPage') {
         $contactPage = SilvercartTools::PageByIdentifierCode('SilvercartContactFormPage');
     }
     return $contactPage;
 }