/**
  * 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;
 }
 /**
  * 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));
 }
Пример #3
0
 /**
  * Returns the shoppingcart of the current user or false if there's no
  * member object registered.
  * 
  * @return mixed false|SilvercartShoppingCart
  * 
  * @author Sebastian Diel <*****@*****.**>,
  *         Sascha Koehler <*****@*****.**>
  * @since 15.11.2014
  */
 public function SilvercartShoppingCart()
 {
     $controller = Controller::curr();
     if ($this->class == $controller->class && !SilvercartTools::isIsolatedEnvironment() && !SilvercartTools::isBackendEnvironment()) {
         $member = SilvercartCustomer::currentUser();
         if (!$member) {
             return false;
         }
         return $member->getCart();
     } else {
         return false;
     }
 }
Пример #4
0
 /**
  * returns a page link by IdentifierCode
  *
  * @param string $identifierCode the DataObjects IdentifierCode
  *
  * @return string
  *
  * @author Sascha Koehler <*****@*****.**>, Sebastian Diel <*****@*****.**>
  * @since 21.02.2013
  */
 public function PageByIdentifierCodeLink($identifierCode = "SilvercartFrontPage")
 {
     return SilvercartTools::PageByIdentifierCodeLink($identifierCode);
 }
 /**
  * Returns a link to trigger the search with this query
  *
  * @return string 
  * 
  * @author Sebastian Diel <*****@*****.**>
  * @since 05.06.2012
  */
 public function Link()
 {
     $searchResultsLink = SilvercartTools::PageByIdentifierCodeLink('SilvercartSearchResultsPage');
     return $searchResultsLink . 'SearchByQuery/' . $this->ID;
 }
 /**
  * Action to show a product detail page.
  * Returns the rendered detail page.
  * 
  * @param SS_HTTPRequest $request Request
  * 
  * @return string
  * 
  * @author Sebastian Diel <*****@*****.**>
  * @since 03.07.2013
  */
 public function detail(SS_HTTPRequest $request)
 {
     $params = $request->allParams();
     $productID = $params['ID'];
     $product = SilvercartProduct::get()->byID($productID);
     $productLink = $product->Link();
     $calledLink = $request->getURL();
     if (strpos($calledLink, '/') != strpos($productLink, '/')) {
         if (strpos($productLink, '/') == 0) {
             $calledLink = '/' . $calledLink;
         } elseif (strpos($calledLink, '/') == 0) {
             $productLink = '/' . $productLink;
         }
     }
     if ($calledLink != $productLink) {
         SilvercartTools::redirectPermanentlyTo($productLink);
     }
     $this->setProduct($product);
     return $this->render();
 }
 /**
  * Modifies the default address form fields
  * 
  * @param bool $withUpdate Execute update method of decorators?
  * 
  * @return array
  */
 public function getFormFields($withUpdate = true)
 {
     parent::getFormFields(false);
     if (!array_key_exists('InvoiceAddressAsShippingAddress', $this->formFields)) {
         foreach ($this->formFields as $fieldName => $fieldData) {
             $this->formFields['Invoice_' . $fieldName] = $fieldData;
             $this->formFields['Shipping_' . $fieldName] = $fieldData;
             unset($this->formFields[$fieldName]);
         }
         if (array_key_exists('Invoice_IsPackstation', $this->formFields)) {
             unset($this->formFields['Invoice_PostNumber']);
             unset($this->formFields['Invoice_Packstation']);
             unset($this->formFields['Invoice_IsPackstation']);
         }
         $this->formFields['InvoiceAddressAsShippingAddress'] = array('type' => 'CheckboxField', 'title' => _t('SilvercartAddress.InvoiceAddressAsShippingAddress'), 'value' => '1', 'jsEvents' => array('setEventHandler' => array('type' => 'click', 'callFunction' => 'toggleShippingAddressSection')));
         $this->formFields['Email'] = array('type' => 'TextField', 'title' => _t('SilvercartAddress.EMAIL'), 'checkRequirements' => array('isEmailAddress' => true, 'isFilledIn' => true));
         if ($this->UseMinimumAgeToOrder()) {
             $days = array('' => '');
             for ($day = 1; $day <= 31; $day++) {
                 $days[$day] = $day;
             }
             $this->formFields = array_merge($this->formFields, array('BirthdayDay' => array('type' => 'DropdownField', 'title' => _t('SilvercartPage.BIRTHDAY'), 'value' => $days, 'checkRequirements' => array('isFilledIn' => true)), 'BirthdayMonth' => array('type' => 'DropdownField', 'title' => _t('SilvercartPage.MONTH'), 'value' => SilvercartTools::getMonthMap(''), 'checkRequirements' => array('isFilledIn' => true)), 'BirthdayYear' => array('type' => 'TextField', 'title' => _t('SilvercartPage.YEAR'), 'maxLength' => 4, 'checkRequirements' => array('isFilledIn' => true, 'isNumbersOnly' => true, 'hasLength' => 4))));
         }
     }
     if ($this->EnableBusinessCustomers()) {
         $this->formFields['Invoice_TaxIdNumber']['checkRequirements']['isFilledInDependantOn']['field'] = 'Invoice_IsBusinessAccount';
         $this->formFields['Shipping_TaxIdNumber']['checkRequirements']['isFilledInDependantOn']['field'] = 'Shipping_IsBusinessAccount';
         $this->formFields['Invoice_Company']['checkRequirements']['isFilledInDependantOn']['field'] = 'Invoice_IsBusinessAccount';
         $this->formFields['Shipping_Company']['checkRequirements']['isFilledInDependantOn']['field'] = 'Shipping_IsBusinessAccount';
     }
     if ($this->InvoiceAddressIsAlwaysShippingAddress()) {
         $this->formFields['InvoiceAddressAsShippingAddress']['type'] = 'HiddenField';
         unset($this->formFields['InvoiceAddressAsShippingAddress']['jsEvents']);
     }
     if ($withUpdate && !empty($this->class)) {
         $this->extend('updateFormFields', $this->formFields);
     }
     return $this->formFields;
 }
Пример #8
0
 /**
  * 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);
 }
 /**
  * processor method
  *
  * @return void
  *
  * @author Sebastian Diel <*****@*****.**>,
  *         Sascha Koehler <*****@*****.**>
  * @since 15.11.2014
  */
 public function process()
 {
     $checkoutData = $this->controller->getCombinedStepData();
     $member = SilvercartCustomer::currentUser();
     if ($member instanceof Member) {
         // Vorbereitung der Parameter zur Erzeugung der Bestellung
         if (isset($checkoutData['Email'])) {
             $customerEmail = $checkoutData['Email'];
         } else {
             $customerEmail = '';
         }
         if (isset($checkoutData['Note'])) {
             $customerNote = $checkoutData['Note'];
         } else {
             $customerNote = '';
         }
         $anonymousCustomer = SilvercartCustomer::currentAnonymousCustomer();
         if ($anonymousCustomer) {
             // add a customer number to anonymous customer when ordering
             $anonymousCustomer->CustomerNumber = SilvercartNumberRange::useReservedNumberByIdentifier('CustomerNumber');
             $anonymousCustomer->write();
         }
         $shippingData = SilvercartTools::extractAddressDataFrom('Shipping', $checkoutData);
         $invoiceData = SilvercartTools::extractAddressDataFrom('Invoice', $checkoutData);
         $order = $this->createOrder($customerEmail, $checkoutData, $customerNote);
         $this->extend('onAfterCreateOrder', $order);
         $order->createShippingAddress($shippingData);
         $order->createInvoiceAddress($invoiceData);
         $order->convertShoppingCartPositionsToOrderPositions();
         // send order confirmation mail
         if ($this->sendConfirmationMail) {
             $order->sendConfirmationMail();
         }
         $this->controller->setStepData(array('orderId' => $order->ID));
         $this->controller->addCompletedStep();
         $this->controller->NextStep(false);
     }
     return false;
 }
Пример #10
0
 /**
  * Writes a log entry
  *
  * @param string $type The type to log
  * @param string $text The text to log
  *
  * @return void
  *
  * @author Sebastian Diel <*****@*****.**>
  * @since 04.01.2013
  */
 public function Log($type, $text)
 {
     SilvercartTools::Log($type, $text, get_class($this));
 }
Пример #11
0
 /**
  * Uses DataObject based, editable templates to send the email
  * 
  * @param integer $messageID ???
  * 
  * @return void
  *
  * @author Sebastian Diel <*****@*****.**>
  * @since 25.11.2015
  */
 public function send($messageID = null)
 {
     $variables = $this->template_data->toMap();
     $variables['PasswordResetLink'] = Director::absoluteURL($this->template_data->PasswordResetLink);
     /* @var $member Member */
     $member = singleton('Member');
     foreach ($member->db() as $dbFieldName => $dbFieldType) {
         if (!array_key_exists($dbFieldName, $variables)) {
             $variables[$dbFieldName] = $this->template_data->{$dbFieldName};
         }
     }
     $variables['SalutationText'] = SilvercartTools::getSalutationText($variables['Salutation']);
     SilvercartShopEmail::send('ForgotPasswordEmail', $this->To(), $variables);
 }
Пример #12
0
 /**
  * Switchs the locale from default to the current SS locale and back.
  * This method is called in constructor and destructor.
  * 
  * @param bool $doRestore Should this call restore the locale to the default value?
  * 
  * @return void
  *
  * @author Sebastian Diel <*****@*****.**>
  * @since 18.05.2011
  */
 public static function switchLocale($doRestore = true)
 {
     if (!$doRestore && !is_null(self::$localeToRestore)) {
         return;
     }
     if (is_null(self::$localeToRestore)) {
         self::$localeToRestore = setlocale(LC_ALL, null);
         $currentLocale = i18n::get_locale();
     } else {
         $currentLocale = self::$localeToRestore;
         self::$localeToRestore = null;
     }
     // it's a kind of dirty, because this will not match every possible
     // system locale... It works for plain and utf8 locales.
     setlocale(LC_ALL, $currentLocale . '.utf8', $currentLocale . '.UTF-8', $currentLocale);
 }
 /**
  * Decrement the positions quantity if it is higher than the stock quantity.
  * If this position has a quantity of 5 but the products stock quantity is
  * only 3 the positions quantity would be set to 3.
  * This happens only if the product is not overbookable.
  * 
  * @return void
  * 
  * @author Roland Lehmann <*****@*****.**>, Sebastian Diel <*****@*****.**>
  * @since 26.11.2012
  */
 public function adjustQuantityToStockQuantity()
 {
     if (!SilvercartTools::isIsolatedEnvironment()) {
         if (SilvercartConfig::EnableStockManagement() && !$this->SilvercartProduct()->isStockQuantityOverbookable()) {
             if ($this->Quantity > $this->SilvercartProduct()->StockQuantity) {
                 $this->Quantity = $this->SilvercartProduct()->StockQuantity;
                 $this->write();
                 SilvercartShoppingCartPositionNotice::setNotice($this->ID, "adjusted");
             }
         }
     }
 }
Пример #14
0
 /**
  * Checks if the installation is complete. We assume a complete
  * installation if the Member table has the field "SilvercartShoppingCartID"
  * that is decorated via "SilvercartCustomer".
  * 
  * @return boolean
  * 
  * @author Sascha Koehler <*****@*****.**>, Sebastian Diel <*****@*****.**>
  * @since 04.06.2012
  * @deprecated use SilvercartTools::isInstallationCompleted() instead
  */
 public static function isInstallationCompleted()
 {
     return SilvercartTools::isInstallationCompleted();
 }
 /**
  * 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 whether there is an update available or not
  * 
  * @return bool
  *
  * @author Sebastian Diel <*****@*****.**>
  * @since 24.01.2013
  */
 public function UpdateAvailable()
 {
     $updateAvailable = SilvercartTools::checkForUpdate();
     return $updateAvailable;
 }
 /**
  * Action to delete an address. Checks, whether the given address is related
  * to the logged in customer and deletes it.
  *
  * @param SS_HTTPRequest $request The given request
  * @param string         $context specifies the context from the action to adjust redirect behaviour
  *
  * @return void
  * 
  * @author Sebastian Diel <*****@*****.**>
  * @since 15.11.2014
  */
 public function deleteAddress(SS_HTTPRequest $request, $context = '')
 {
     $params = $request->allParams();
     if (array_key_exists('ID', $params) && !empty($params['ID'])) {
         $addressID = (int) $params['ID'];
         $member = SilvercartCustomer::currentUser();
         $membersAddresses = $member->SilvercartAddresses();
         $membersAddress = $membersAddresses->find('ID', $addressID);
         if ($membersAddresses->count() == 1) {
             // address can't be deleted because it's the only one
             $this->setErrorMessage(_t('SilvercartAddressHolder.ADDRESS_CANT_BE_DELETED', "Sorry, but you can't delete your only address."));
         } elseif ($membersAddress instanceof SilvercartAddress && $membersAddress->exists() && $membersAddress->canDelete()) {
             // Address contains to logged in user - delete it
             if ($member->SilvercartInvoiceAddress()->ID == $addressID) {
                 // set shipping address as users invoice address
                 $member->SilvercartInvoiceAddressID = $member->SilvercartShippingAddress()->ID;
                 $member->write();
             }
             if ($member->SilvercartShippingAddress()->ID == $addressID) {
                 // set invoice address as users shipping address
                 $member->SilvercartShippingAddressID = $member->SilvercartInvoiceAddress()->ID;
                 $member->write();
             }
             $membersAddress->delete();
             $this->setSuccessMessage(_t('SilvercartAddressHolder.ADDRESS_SUCCESSFULLY_DELETED', 'Your address was successfully deleted.'));
         } else {
             // possible break in attempt!
             $this->setErrorMessage(_t('SilvercartAddressHolder.ADDRESS_NOT_FOUND', 'Sorry, but the given address was not found.'));
         }
     }
     if (!empty($context)) {
         $this->redirectBack();
     } else {
         $this->redirect(SilvercartTools::PageByIdentifierCodeLink('SilvercartAddressHolder'));
     }
 }
 /**
  * Returns the "My Account" page object.
  * 
  * @return SilvercartMyAccountHolder
  * 
  * @author Sascha Koehler <*****@*****.**>
  * @since 26.05.2011
  */
 public function MyAccountPage()
 {
     return SilvercartTools::PageByIdentifierCode('SilvercartMyAccountHolder');
 }
Пример #19
0
//AssetAdmin::$menuCode = 'files';
Config::inst()->update('AssetAdmin', 'menuCode', 'files');
Config::inst()->update('CMSFileAddController', 'menuCode', 'files');
Config::inst()->update('CMSSettingsController', 'menuCode', 'config');
Config::inst()->update('SecurityAdmin', 'menuCode', 'customer');
Config::inst()->update('CMSPagesController', 'menuSortIndex', 10);
Config::inst()->update('WidgetSetAdmin', 'menuSortIndex', 20);
Config::inst()->update('ReportAdmin', 'menuSortIndex', 30);
Config::inst()->update('AssetAdmin', 'menuSortIndex', 1);
Config::inst()->update('SecurityAdmin', 'menuSortIndex', 30);
Config::inst()->update('CMSSettingsController', 'menuSortIndex', 1);
// ----------------------------------------------------------------------------
// Dirty bugfixes ....
// ----------------------------------------------------------------------------
if (array_key_exists('Email', $_POST)) {
    $_POST['Email'] = SilvercartTools::prepareEmailAddress($_POST['Email']);
}
$cacheDirectories = array('cacheblock' => getTempFolder() . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'cacheblock', 'silvercart' => getTempFolder() . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'silvercart');
if (Director::isDev()) {
    $cachelifetime = 1;
} else {
    $cachelifetime = 86400;
}
foreach ($cacheDirectories as $cacheName => $cacheDirectory) {
    SilvercartCleanCacheTask::register_cache_directory($cacheDirectory);
    if (!is_dir($cacheDirectory)) {
        mkdir($cacheDirectory);
    }
    SS_Cache::add_backend($cacheName, 'File', array('cache_dir' => $cacheDirectory, 'hashed_directory_level' => 1));
    SS_Cache::set_cache_lifetime($cacheName, $cachelifetime);
    SS_Cache::pick_backend($cacheName, $cacheName);
 /**
  * Returns the CustomHtmlFormConfig or triggers an error if not existent.
  *
  * @return SilvercartConfig|false
  *
  * @author Sascha Koehler <*****@*****.**>, Roland Lehmann
  * @since 10.02.2013
  */
 public static function getConfig()
 {
     if (is_null(self::$config)) {
         self::$config = SiteConfig::current_site_config();
         if (!self::$config) {
             if (SilvercartTools::isIsolatedEnvironment()) {
                 return false;
             }
             $errorMessage = _t('CustomHtmlFormConfiguration.ERROR_NO_CONFIG');
             self::triggerError($errorMessage);
         }
     }
     return self::$config;
 }
 /**
  * Returns the shipping or invoice address set in checkout
  *
  * @param string $prefix The prefix to use
  *
  * @return SilvercartAddress 
  */
 public function getAddress($prefix)
 {
     $address = false;
     $stepData = $this->getCombinedStepData();
     if ($stepData != false) {
         $addressData = SilvercartTools::extractAddressDataFrom($prefix, $stepData);
         if (!empty($addressData) && array_key_exists('CountryID', $addressData)) {
             $address = new SilvercartAddress($addressData);
             $address->SilvercartCountryID = $addressData['CountryID'];
         }
     }
     return $address;
 }
Пример #22
0
 /**
  * Returns the localized salutation string.
  *
  * @return string
  */
 public function getSalutationText()
 {
     return SilvercartTools::getSalutationText($this->Salutation);
 }
 /**
  * Renders the navigation.
  *
  * @param SiteTree $rootPage The root page to start with
  * @param int      $level    The current level
  *
  * @return string
  *
  * @author Sascha Koehler <*****@*****.**>
  * @since 22.05.2012
  */
 public function renderNavigation($rootPage, $level = 0)
 {
     $renderStr = '';
     $isActivePage = false;
     if ($this->getLevelsToShow() != 0 && $level > $this->getLevelsToShow()) {
         return $renderStr;
     }
     $childPages = $rootPage->Children();
     $childPageStr = '';
     if ($childPages->exists()) {
         $childLevel = $level + 1;
         foreach ($childPages as $childPage) {
             if ($childPage->ShowInMenus) {
                 $childPageStr .= $this->renderNavigation($childPage, $childLevel);
             }
         }
     }
     if (Controller::curr()->ID === $rootPage->ID) {
         $isActivePage = true;
     }
     $showChildPages = false;
     $isSectionPage = false;
     if (SilvercartTools::findPageIdInHierarchy($rootPage->ID)) {
         $showChildPages = true;
         $isSectionPage = true;
     }
     if (method_exists($rootPage, 'OriginalLink')) {
         $link = $rootPage->OriginalLink();
     } else {
         $link = $rootPage->Link();
     }
     if ($rootPage->ID === $this->getStartPage()->ID) {
         $isRootPage = true;
     } else {
         $isRootPage = false;
     }
     $data = array('MenuTitle' => $rootPage->getMenuTitle(), 'Title' => $rootPage->getTitle(), 'Link' => $link, 'ShowChildPages' => $showChildPages, 'ShowSiblings' => $this->showSiblings, 'ChildPages' => $childPageStr, 'IsActivePage' => $isActivePage, 'IsSectionPage' => $isSectionPage, 'IsRootPage' => $isRootPage);
     $parser = new SSViewer('SilvercartSubNavigationWidgetEntry');
     $renderStr .= $parser->process(new DataObject($data));
     return $renderStr;
 }
Пример #24
0
 /**
  * Returns the translated plural name of the object. If no translation exists
  * the class name will be returned.
  * 
  * @return string the objects plural name
  * 
  * @author Roland Lehmann <*****@*****.**>
  * @since 13.07.2012
  */
 public function plural_name()
 {
     return SilvercartTools::plural_name_for($this);
 }
 /**
  * Renders the product group navigation.
  *
  * @param SiteTree $rootPage    The root page to start with
  * @param SiteTree $currentPage The current SiteTree object
  * @param int      $level       The current level
  *
  * @return string
  * 
  * @author Sebastian Diel <*****@*****.**>,
  *         Sascha Koehler <*****@*****.**>
  * @since 24.11.2014
  */
 public function renderProductGroupNavigation($rootPage, $currentPage, $level = 0)
 {
     $renderStr = '';
     $isActivePage = false;
     $level++;
     if ($this->levelsToShow == 0 || $level <= $this->levelsToShow) {
         if (!($this->expandActiveSectionOnly && ($this->levelsToShow != 0 && $level > $this->levelsToShow || $level > 1) && SilvercartTools::findPageIdInHierarchy($rootPage->getParent()->ID) === false)) {
             $childPages = $rootPage->Children();
             $childPageStr = '';
             if ($childPages && $childPages->Count() > 0) {
                 foreach ($childPages as $childPage) {
                     $childPageStr .= $this->renderProductGroupNavigation($childPage, $currentPage, $level);
                 }
             }
             if (Controller::curr()->ID === $rootPage->ID) {
                 $isActivePage = true;
             }
             if (SilvercartTools::findPageIdInHierarchy($rootPage->ID) || $rootPage->ID === $currentPage->ID) {
                 $isActiveSection = true;
             } else {
                 $isActiveSection = false;
             }
             $data = new ArrayData(array('MenuTitle' => $rootPage->getMenuTitle(), 'Title' => $rootPage->getTitle(), 'Link' => $rootPage->Link(), 'LinkOrSection' => $rootPage->LinkOrSection(), 'ChildPages' => $childPageStr, 'IsActivePage' => $isActivePage, 'IsActiveSection' => $isActiveSection, 'Level' => $level));
             $renderStr .= $data->renderWith('SilvercartProductGroupNavigationWidgetEntry');
         }
     }
     return $renderStr;
 }
 /**
  * Creates and returns the CSV content to download.
  * $exportContext can be:
  * 0 = all customers with a valid email address
  * 1 = all newsletter recipients
  * 2 = all newsletter recipients with customer account
  * 3 = all newsletter recipients without customer account
  * 4 = all non-newletter recipients with customer account
  * 
  * @param string $exportContext 0|1|2|3|4; Identifies the context to get recipients for
  * 
  * @return string
  */
 protected function getCSVContent($exportContext)
 {
     $membersSql = 'SELECT "M"."Email", "M"."Salutation", "M"."FirstName", "M"."Surname" FROM "Member" AS "M" WHERE "M"."Email" IS NOT NULL';
     $anonymousSql = 'SELECT "ANR"."Email", "ANR"."Salutation", "ANR"."FirstName", "ANR"."Surname" FROM "SilvercartAnonymousNewsletterRecipient" AS "ANR" WHERE "ANR"."Email" IS NOT NULL AND "ANR"."NewsletterOptInStatus" = 1';
     $membersSqlAddition = '';
     switch ($exportContext) {
         case '1':
             // All newletter recipients
             $useMembersSql = true;
             $useAnonymousSql = true;
             $membersSqlAddition = ' AND "M"."NewsletterOptInStatus" = 1';
             break;
         case '2':
             // All newletter recipients with customer account
             $useMembersSql = true;
             $useAnonymousSql = false;
             $membersSqlAddition = ' AND "M"."NewsletterOptInStatus" = 1';
             break;
         case '3':
             // All newletter recipients without customer account
             $useMembersSql = false;
             $useAnonymousSql = true;
             break;
         case '4':
             // All non-newletter recipients
             $useMembersSql = true;
             $useAnonymousSql = false;
             $membersSqlAddition = ' AND "M"."NewsletterOptInStatus" = 0';
             break;
         case '0':
         default:
             // All customers with a valid email address
             $useMembersSql = true;
             $useAnonymousSql = true;
             break;
     }
     $tempFolder = getTempFolder();
     $tempCsvFile = $tempFolder . '/do_newsletter_recipients_export.csv';
     $csvFile = fopen($tempCsvFile, 'w');
     fputcsv($csvFile, array('email', 'salutation', 'firstname', 'surname'));
     if ($useMembersSql) {
         $records = DB::query($membersSql . $membersSqlAddition);
         if ($records->numRecords() > 0) {
             foreach ($records as $record) {
                 $record['Salutation'] = SilvercartTools::getSalutationText($record['Salutation']);
                 fputcsv($csvFile, $record);
             }
         }
     }
     if ($useAnonymousSql) {
         $records = DB::query($anonymousSql);
         if ($records->numRecords() > 0) {
             foreach ($records as $record) {
                 $record['Salutation'] = SilvercartTools::getSalutationText($record['Salutation']);
                 fputcsv($csvFile, $record);
             }
         }
     }
     fclose($csvFile);
     $csvFileContent = file_get_contents($tempCsvFile);
     unlink($tempCsvFile);
     return $csvFileContent;
 }
 /**
  * Returns the attributed shipping methods as string (limited to 150 chars).
  *
  * @return string
  *
  * @author Sascha Koehler <*****@*****.**>, Sebastian Diel <*****@*****.**>
  * @since 05.04.2012
  */
 public function AttributedShippingMethods()
 {
     return SilvercartTools::AttributedDataObject($this->SilvercartShippingMethod());
 }
 /**
  * returns address data as ArrayData to control in template
  *
  * @return ArrayData
  *
  * @author Sebastian Diel <*****@*****.**>,
  *         Sascha Koehler <*****@*****.**>
  * @since 15.11.2014
  */
 public function AddressData()
 {
     $checkoutData = $this->controller->getCombinedStepData();
     if (array_key_exists('ShippingAddress', $checkoutData) && SilvercartCustomer::currentUser()->SilvercartAddresses()->Find('ID', $checkoutData['ShippingAddress'])) {
         $shippingAddress = SilvercartCustomer::currentUser()->SilvercartAddresses()->Find('ID', $checkoutData['ShippingAddress']);
     } else {
         /**
          * @deprecated Fallback for potential dependencies 
          */
         $shippingAddress = SilvercartTools::extractAddressDataFrom('Shipping', $checkoutData);
         $shippingAddress = $this->getAssociativeAddressData($shippingAddress);
         $shippingAddress = new SilvercartAddress($shippingAddress);
         $shippingAddress->setIsAnonymousShippingAddress(true);
     }
     if (array_key_exists('InvoiceAddress', $checkoutData) && SilvercartCustomer::currentUser()->SilvercartAddresses()->Find('ID', $checkoutData['InvoiceAddress'])) {
         $invoiceAddress = SilvercartCustomer::currentUser()->SilvercartAddresses()->Find('ID', $checkoutData['InvoiceAddress']);
     } else {
         /**
          * @deprecated Fallback for potential dependencies 
          */
         $invoiceAddress = SilvercartTools::extractAddressDataFrom('Invoice', $checkoutData);
         $invoiceAddress = $this->getAssociativeAddressData($invoiceAddress, 'Invoice');
         $invoiceAddress = new SilvercartAddress($invoiceAddress);
         $invoiceAddress->setIsAnonymousInvoiceAddress(true);
         if ($this->isAnonymousInvoiceAddressEqualShippingAddress($checkoutData)) {
             $invoiceAddress->setIsAnonymousShippingAddress(true);
         }
     }
     if (array_key_exists('InvoiceAddress', $checkoutData) && array_key_exists('ShippingAddress', $checkoutData)) {
         if ($checkoutData['InvoiceAddress'] === $checkoutData['ShippingAddress']) {
             if (is_array($invoiceAddress)) {
                 /**
                  * @deprecated Fallback for potential dependencies 
                  */
                 $invoiceAddress['isInvoiceAndShippingAddress'] = true;
             } else {
                 SilvercartCustomer::currentUser()->SilvercartShippingAddressID = $checkoutData['ShippingAddress'];
                 SilvercartCustomer::currentUser()->SilvercartInvoiceAddressID = $checkoutData['InvoiceAddress'];
             }
         }
     }
     $addressData = new ArrayData(array('SilvercartShippingAddress' => $shippingAddress, 'SilvercartInvoiceAddress' => $invoiceAddress));
     return $addressData;
 }
 /**
  * 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;
 }