/**
  * constructor
  *
  * @param Controller $controller  the controller object
  * @param array      $params      additional parameters
  * @param array      $preferences array with preferences
  * @param bool       $barebone    is the form initialized completely?
  *
  * @return void
  *
  * @author Sebastian Diel <*****@*****.**>,
  *         Sascha Koehler <*****@*****.**>
  * @since 15.11.2014
  */
 public function __construct($controller, $params = null, $preferences = null, $barebone = false)
 {
     $member = SilvercartCustomer::currentUser();
     $checkoutData = $controller->getCombinedStepData();
     if (!$this->payment && $member) {
         if (array_key_exists('PaymentMethod', $checkoutData)) {
             $this->paymentMethodObj = DataObject::get_by_id('SilvercartPaymentMethod', $checkoutData['PaymentMethod']);
             if ($this->paymentMethodObj) {
                 $this->paymentMethodObj->setController($controller);
                 $this->paymentMethodObj->setCancelLink(Director::absoluteURL($controller->Link()) . 'GotoStep/2');
                 $this->paymentMethodObj->setReturnLink(Director::absoluteURL($controller->Link()));
                 $this->paymentMethodObj->setCustomerDetailsByCheckoutData($checkoutData);
                 $this->paymentMethodObj->setInvoiceAddressByCheckoutData($checkoutData);
                 $this->paymentMethodObj->setShippingAddressByCheckoutData($checkoutData);
                 $this->paymentMethodObj->setShoppingCart($member->getCart());
             }
         }
     }
     parent::__construct($controller, $params, $preferences, $barebone);
     if (!$barebone) {
         /*
          * redirect a user if his cart is empty and no order exists
          */
         $checkoutData = $this->controller->getCombinedStepData();
         if (!SilvercartCustomer::currentUser() || !SilvercartCustomer::currentUser()->getCart()->isFilled() && !array_key_exists('orderId', $checkoutData)) {
             $frontPage = SilvercartPage_Controller::PageByIdentifierCode();
             $this->getController()->redirect($frontPage->RelativeLink());
         }
     }
 }
 /**
  * Logged in users get directed to the next step immediately.
  *
  * @return void
  *
  * @author Sascha Koehler <*****@*****.**>, Seabstian Diel <*****@*****.**>
  * @since 08.04.2011
  */
 public function isConditionForDisplayFulfilled()
 {
     $isConditionForDisplayFulfilled = false;
     if (!SilvercartCustomer::currentRegisteredCustomer()) {
         $isConditionForDisplayFulfilled = true;
     }
     return $isConditionForDisplayFulfilled;
 }
 /**
  * Initialise the shopping cart.
  *
  * @return void
  *
  * @author Sebastian Diel <*****@*****.**>,
  *         Sascha Koehler <*****@*****.**>
  * @since 15.11.2014
  */
 public function init()
 {
     if (SilvercartCustomer::currentUser() && SilvercartCustomer::currentUser()->SilvercartShoppingCartID > 0) {
         SilvercartCustomer::currentUser()->getCart();
     }
     parent::init();
     if (SilvercartCustomer::currentUser() && SilvercartCustomer::currentUser()->getCart()->exists() && SilvercartCustomer::currentUser()->getCart()->SilvercartShoppingCartPositions()->count() > 0 && SilvercartConfig::RedirectToCheckoutWhenInCart()) {
         $this->redirect(SilvercartTools::PageByIdentifierCode('SilvercartCheckoutStep')->Link());
     }
 }
 /**
  * Provide additional information if availabel
  *
  * @return string
  *
  * @author Sebastian Diel <*****@*****.**>,
  *         Sascha Koehler <*****@*****.**>
  * @since 15.11.2014
  */
 public function AdditionalInformation()
 {
     $member = SilvercartCustomer::currentUser();
     $text = '';
     if ($member) {
         if (!empty($member->OptInTempText)) {
             $text = $member->OptInTempText;
         }
     }
     return $text;
 }
 /**
  * executed if there are no valdation errors on submit
  * Form data is saved in session
  *
  * @param SS_HTTPRequest $data     contains the frameworks form data
  * @param Form           $form     not used
  * @param array          $formData contains the modules form data
  *
  * @return void
  * 
  * @author Sebastian Diel <*****@*****.**>,
  *         Roland Lehmann <*****@*****.**>
  * @since 15.11.2014
  */
 protected function submitSuccess($data, $form, $formData)
 {
     if ($formData['positionID']) {
         //check if the position belongs to this user. Malicious people could manipulate it.
         $member = SilvercartCustomer::currentUser();
         $position = DataObject::get_by_id('SilvercartShoppingCartPosition', $formData['positionID']);
         if ($position && $member->getCart()->ID == $position->SilvercartShoppingCartID) {
             $position->delete();
             $backLinkPage = DataObject::get_by_id('SiteTree', $formData['BlID']);
             $this->controller->redirect($backLinkPage->Link());
         }
     }
 }
 /**
  * constructor
  *
  * @param Controller $controller  the controller object
  * @param array      $params      additional parameters
  * @param array      $preferences array with preferences
  * @param bool       $barebone    is the form initialized completely?
  *
  * @return void
  * 
  * @author Sebastian Diel <*****@*****.**>
  *         Sascha Koehler <*****@*****.**>
  * @since 15.11.2014
  */
 public function __construct($controller, $params = null, $preferences = null, $barebone = false)
 {
     parent::__construct($controller, $params, $preferences, $barebone);
     if (!$barebone) {
         /*
          * redirect a user if his cart is empty and no order exists
          */
         $checkoutData = $this->controller->getCombinedStepData();
         if (!SilvercartCustomer::currentUser() || !SilvercartCustomer::currentUser()->getCart()->isFilled() && !array_key_exists('orderId', $checkoutData)) {
             $frontPage = SilvercartPage_Controller::PageByIdentifierCode();
             $this->getController()->redirect($frontPage->RelativeLink());
         }
     }
 }
 /**
  * executed if there are no validation errors on submit
  *
  * @param SS_HTTPRequest $data     contains the frameworks form data
  * @param Form           $form     not used
  * @param array          $formData contains the modules form data
  *
  * @return void
  * 
  * @author Sebastian Diel <*****@*****.**>,
  *         Roland Lehmann <*****@*****.**>
  * @since 15.11.2014
  */
 protected function submitSuccess($data, $form, $formData)
 {
     $overwrite = SilvercartPlugin::call($this, 'overwriteSubmitSuccess', array($data, $form, $formData), null, 'boolean');
     if (!$overwrite) {
         if ($formData['positionID']) {
             //check if the position belongs to this user. Malicious people could manipulate it.
             $member = SilvercartCustomer::currentUser();
             $position = DataObject::get_by_id('SilvercartShoppingCartPosition', $formData['positionID']);
             if ($position && $member->getCart()->ID == $position->SilvercartShoppingCartID) {
                 $position->SilvercartProduct()->addToCart($member->getCart()->ID, 1, true);
                 $backLinkPage = DataObject::get_by_id('SiteTree', $formData['BlID']);
                 $this->controller->redirect($backLinkPage->Link());
             }
         }
     }
 }
 /**
  * executed if there are no valdation errors on submit
  * Form data is saved in session
  *
  * @param SS_HTTPRequest $data     contains the frameworks form data
  * @param Form           $form     not used
  * @param array          $formData contains the modules form data
  *
  * @return array to be rendered in the controller
  *
  * @author Sebastian Diel <*****@*****.**>,
  *         Sascha Koehler <*****@*****.**>
  * @since 27.06.2014
  */
 protected function submitSuccess($data, $form, $formData)
 {
     $emailAddress = $formData['emailaddress'];
     $password = $formData['password'];
     // get customers data
     $user = Member::get()->filter('Email', $formData['emailaddress'])->first();
     if ($user) {
         $customer = MemberAuthenticator::authenticate(array('Email' => $emailAddress, 'Password' => $password));
         if ($customer) {
             //transfer cart positions from an anonymous user to the one logging in
             $anonymousCustomer = SilvercartCustomer::currentAnonymousCustomer();
             if ($anonymousCustomer) {
                 if ($anonymousCustomer->getCart()->SilvercartShoppingCartPositions()->exists()) {
                     //delete registered customers cart positions
                     if ($customer->getCart()->SilvercartShoppingCartPositions()) {
                         foreach ($customer->getCart()->SilvercartShoppingCartPositions() as $position) {
                             $position->delete();
                         }
                     }
                     //add anonymous positions to the registered user
                     foreach ($anonymousCustomer->getCart()->SilvercartShoppingCartPositions() as $position) {
                         $customer->getCart()->SilvercartShoppingCartPositions()->add($position);
                     }
                 }
                 $anonymousCustomer->logOut();
                 $anonymousCustomer->delete();
             }
             $customer->logIn();
             $customer->write();
             if ($this->Controller()->redirectedTo() == '') {
                 $myAccountHolder = SilvercartPage_Controller::PageByIdentifierCode("SilvercartMyAccountHolder");
                 $this->Controller()->redirect($myAccountHolder->RelativeLink());
             }
         } else {
             $this->addMessage(_t('SilvercartPage.CREDENTIALS_WRONG', 'Your credentials are incorrect.'));
             Requirements::customScript('jQuery(document).ready(function(){ $("#silvercart-quicklogin-form").slideDown(); });');
             return $this->submitFailure($data, $form);
         }
     } else {
         $this->addMessage(_t('SilvercartPage.CREDENTIALS_WRONG'));
         Requirements::customScript('jQuery(document).ready(function(){ $("#silvercart-quicklogin-form").slideDown(); });');
         return $this->submitFailure($data, $form);
     }
 }
 /**
  * Returns the form fields
  * 
  * @param bool $withUpdate Execute update method of decorators?
  * 
  * @return array
  * 
  * @author Sebastian Diel <*****@*****.**>
  * @since 15.11.2014
  */
 public function getFormFields($withUpdate = true)
 {
     if (empty($this->formFields)) {
         if (Member::currentUserID() > 0) {
             $member = SilvercartCustomer::currentUser();
         } else {
             $member = singleton('Member');
         }
         $address = singleton('SilvercartAddress');
         $this->formFields = array('Salutation' => array('type' => 'DropdownField', 'title' => $address->fieldLabel('Salutation'), 'selectedValue' => $member->Salutation, 'value' => array('' => _t('SilvercartEditAddressForm.EMPTYSTRING_PLEASECHOOSE'), "Frau" => _t('SilvercartAddress.MISSES'), "Herr" => _t('SilvercartAddress.MISTER')), 'checkRequirements' => array('isFilledIn' => true)), 'FirstName' => array('type' => 'TextField', 'title' => $address->fieldLabel('FirstName'), 'value' => $member->FirstName, 'checkRequirements' => array('isFilledIn' => true, 'hasMinLength' => 3)), 'Surname' => array('type' => 'TextField', 'title' => $address->fieldLabel('Surname'), 'value' => $member->Surname, 'checkRequirements' => array('isFilledIn' => true, 'hasMinLength' => 3)), 'Email' => array('type' => 'TextField', 'title' => $member->fieldLabel('Email'), 'value' => $member->Email, 'checkRequirements' => array('isFilledIn' => true, 'isEmailAddress' => true)), 'Message' => array('type' => 'TextareaField', 'title' => _t('SilvercartPage.MESSAGE', 'message'), 'checkRequirements' => array('isFilledIn' => true, 'hasMinLength' => 3)));
         if ($this->EnableStreet()) {
             $requirements = array();
             if ($this->StreetIsRequired()) {
                 $requirements = array('isFilledIn' => true);
             }
             $this->formFields = array_merge($this->formFields, array('Street' => array('type' => 'TextField', 'title' => $address->fieldLabel('Street') . ' / ' . $address->fieldLabel('StreetNumber'), 'checkRequirements' => $requirements), 'StreetNumber' => array('type' => 'TextField', 'title' => $address->fieldLabel('StreetNumber'), 'checkRequirements' => $requirements)));
         }
         if ($this->EnableCity()) {
             $requirements = array();
             if ($this->CityIsRequired()) {
                 $requirements = array('isFilledIn' => true);
             }
             $this->formFields = array_merge($this->formFields, array('Postcode' => array('type' => 'TextField', 'title' => $address->fieldLabel('Postcode'), 'checkRequirements' => $requirements), 'City' => array('type' => 'TextField', 'title' => $address->fieldLabel('Postcode') . ' - ' . $address->fieldLabel('City'), 'checkRequirements' => $requirements)));
         }
         if ($this->EnableCountry()) {
             $requirements = array();
             if ($this->CountryIsRequired()) {
                 $requirements = array('isFilledIn' => true);
             }
             $this->formFields = array_merge($this->formFields, array('SilvercartCountryID' => array('type' => 'DropdownField', 'title' => $address->fieldLabel('SilvercartCountry'), 'value' => SilvercartCountry::getPrioritiveDropdownMap(true, _t('SilvercartEditAddressForm.EMPTYSTRING_PLEASECHOOSE')), 'checkRequirements' => $requirements)));
         }
         if ($this->EnablePhoneNumber()) {
             $requirements = array();
             if ($this->PhoneNumberIsRequired()) {
                 $requirements = array('isFilledIn' => true);
             }
             $this->formFields = array_merge($this->formFields, array('Phone' => array('type' => 'TextField', 'title' => $address->fieldLabel('Phone'), 'checkRequirements' => $requirements)));
         }
     }
     return parent::getFormFields($withUpdate);
 }
 /**
  * executed if there are no valdation errors on submit
  * Form data is saved in session
  *
  * @param SS_HTTPRequest $data     contains the frameworks form data
  * @param Form           $form     not used
  * @param array          $formData contains the modules form data
  *
  * @return array to be rendered in the controller
  *
  * @author Sebastian Diel <*****@*****.**>,
  *         Sascha Koehler <*****@*****.**>
  * @since 27.06.2014
  */
 protected function submitSuccess($data, $form, $formData)
 {
     $emailAddress = $formData['emailaddress'];
     $password = $formData['password'];
     // get customers data
     $user = Member::get()->filter('Email', $formData['emailaddress'])->first();
     if ($user) {
         $customer = MemberAuthenticator::authenticate(array('Email' => $emailAddress, 'Password' => $password));
         if ($customer) {
             //transfer cart positions from an anonymous user to the one logging in
             $anonymousCustomer = SilvercartCustomer::currentAnonymousCustomer();
             if ($anonymousCustomer) {
                 if ($anonymousCustomer->getCart()->SilvercartShoppingCartPositions()->exists()) {
                     //delete registered customers cart positions
                     if ($customer->getCart()->SilvercartShoppingCartPositions()) {
                         foreach ($customer->getCart()->SilvercartShoppingCartPositions() as $position) {
                             $position->delete();
                         }
                     }
                     //add anonymous positions to the registered user
                     foreach ($anonymousCustomer->getCart()->SilvercartShoppingCartPositions() as $position) {
                         $customer->getCart()->SilvercartShoppingCartPositions()->add($position);
                     }
                 }
                 $anonymousCustomer->logOut();
                 $anonymousCustomer->delete();
             }
             $customer->logIn();
             $customer->write();
             $myAccountHolder = SilvercartPage_Controller::PageByIdentifierCode("SilvercartMyAccountHolder");
             $this->controller->redirect($myAccountHolder->RelativeLink());
         } else {
             $this->messages = array('Authentication' => array('message' => _t('SilvercartPage.CREDENTIALS_WRONG', 'Your credentials are incorrect.')));
             return $this->submitFailure($data, $form);
         }
     } else {
         $this->messages = array('Authentication' => array('message' => _t('SilvercartPage.EMAIL_NOT_FOUND', 'This Email address could not be found.')));
         return $this->messages = array('Authentication' => array('message' => _t('SilvercartPage.CREDENTIALS_WRONG')));
     }
 }
 /**
  * constructor. Set alternative form action here.
  *
  * @param Controller $controller  the controller object
  * @param array      $params      additional parameters
  * @param array      $preferences array with preferences
  * @param bool       $barebone    is the form initialized completely?
  *
  * @return void
  *
  * @author Sebastian Diel <*****@*****.**>
  * @since 15.11.2014
  */
 public function __construct($controller, $params = null, $preferences = null, $barebone = false)
 {
     $member = SilvercartCustomer::currentUser();
     $checkoutData = $controller->getCombinedStepData();
     if ($member && is_array($params) && array_key_exists('PaymentMethod', $params)) {
         $paymentMethod = DataObject::get_by_id('SilvercartPaymentMethod', $params['PaymentMethod']);
         if ($paymentMethod) {
             $paymentMethod->setController($controller);
             $paymentMethod->setCancelLink(Director::absoluteURL($controller->Link()) . 'GotoStep/2');
             $paymentMethod->setReturnLink(Director::absoluteURL($controller->Link()));
             $paymentMethod->setCustomerDetailsByCheckoutData($checkoutData);
             $paymentMethod->setInvoiceAddressByCheckoutData($checkoutData);
             $paymentMethod->setShippingAddressByCheckoutData($checkoutData);
             if (array_key_exists('ShippingMethod', $checkoutData)) {
                 $member->getCart()->setShippingMethodID($checkoutData['ShippingMethod']);
             }
             $paymentMethod->setShoppingCart($member->getCart());
             $this->setPaymentMethod($paymentMethod);
         }
     }
     parent::__construct($controller, $params, $preferences, $barebone);
 }
 /**
  * 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));
 }
 /**
  * Is this product buyable with the given stock management settings?
  * If Stock management is deactivated true is returned.
  * If stock management is activated but the quantity is overbookable true is
  * returned.
  *
  * @return boolean Can this product be bought due to stock management
  *                 settings and the customers cart?
  *
  * @author Sebastian Diel <*****@*****.**>,
  *         Roland Lehmann <*****@*****.**>
  * @since 15.11.2014
  */
 public function isBuyableDueToStockManagementSettings()
 {
     //is the product already in the cart?
     $cartPositionQuantity = 0;
     if (SilvercartCustomer::currentUser() && SilvercartCustomer::currentUser()->getCart()) {
         $cartPositionQuantity = SilvercartCustomer::currentUser()->getCart()->getQuantity($this->ID);
     }
     if (SilvercartConfig::EnableStockManagement()) {
         if (!$this->isStockQuantityOverbookable() && $this->StockQuantity - $cartPositionQuantity <= 0) {
             return false;
         }
         if ($this->StockQuantityExpirationDate) {
             $curDate = new DateTime();
             $expirationDate = new DateTime(strftime($this->StockQuantityExpirationDate));
             if ($this->isStockQuantityOverbookable() && $this->StockQuantity - $cartPositionQuantity <= 0 && $expirationDate < $curDate) {
                 return false;
             }
         }
     }
     return true;
 }
 /**
  * set the email for this order
  *
  * @param string $email the email address of the customer
  *
  * @return void
  */
 public function setCustomerEmail($email = null)
 {
     $member = SilvercartCustomer::currentUser();
     if ($member instanceof Member && $member->Email) {
         $email = $member->Email;
     }
     $this->CustomersEmail = $email;
 }
 /**
  * Checks, whether this is an invoice address.
  *
  * @return bool
  * 
  * @author Sebastian Diel <*****@*****.**>,
  *         Ramon Kupper <*****@*****.**>
  * @since 23.02.2016
  */
 public function isShippingAddress()
 {
     $isShippingAddress = false;
     if ($this->ID == SilvercartCustomer::currentUser()->SilvercartShippingAddressID || $this->isAnonymousShippingAddress()) {
         $isShippingAddress = true;
     } else {
         if (Controller::curr() instanceof SilvercartCheckoutStep_Controller) {
             $checkoutData = Controller::curr()->getCombinedStepData();
             if (array_key_exists('ShippingAddress', $checkoutData) && is_numeric($this->ID) && $this->ID > 0 && $this->ID === $checkoutData['ShippingAddress']) {
                 $isShippingAddress = true;
             }
         }
     }
     return $isShippingAddress;
 }
 /**
  * We save the data of the user here.
  *
  * @param SS_HTTPRequest $data     contains the frameworks form data
  * @param Form           $form     not used
  * @param array          $formData contains the modules form data
  *
  * @return void
  *
  * @author Sascha Koehler <*****@*****.**>
  * @since 22.03.2011
  */
 protected function submitSuccess($data, $form, $formData)
 {
     $member = SilvercartCustomer::currentRegisteredCustomer();
     if ($member) {
         $formData['Salutation'] = $member->Salutation;
         $formData['FirstName'] = $member->FirstName;
         $formData['Surname'] = $member->Surname;
         $formData['Email'] = $member->Email;
         // ----------------------------------------------------------------
         // For registered and logged in customers all we have to do is set
         // the respective field in the customer object.
         // ----------------------------------------------------------------
         switch ($formData['NewsletterAction']) {
             case '1':
                 SilvercartNewsletter::subscribeRegisteredCustomer($member);
                 $this->setSessionMessage(sprintf(_t('SilvercartNewsletterStatus.SUBSCRIBED_SUCCESSFULLY'), $formData['Email']));
                 break;
             case '2':
             default:
                 SilvercartNewsletter::unSubscribeRegisteredCustomer($member);
                 $this->setSessionMessage(sprintf(_t('SilvercartNewsletterStatus.UNSUBSCRIBED_SUCCESSFULLY'), $formData['Email']));
         }
     } else {
         // ----------------------------------------------------------------
         // For unregistered customers we have to add / remove them from
         // the datastore for unregistered newsletter recipients.
         //
         // If the given email address belongs to a registered customer we
         // should not do anything but ask the user to log in first.
         // ----------------------------------------------------------------
         if (SilvercartNewsletter::isEmailAllocatedByRegularCustomer($formData['Email'])) {
             $this->setSessionMessage(sprintf(_t('SilvercartNewsletterStatus.REGULAR_CUSTOMER_WITH_SAME_EMAIL_EXISTS'), $formData['Email'], '/Security/Login/?BackURL=' . $this->controller->PageByIdentifierCode('SilvercartNewsletterPage')->Link()));
         } else {
             if ($formData['NewsletterAction'] == '1') {
                 // --------------------------------------------------------
                 // Subscribe to newsletter.
                 // If the user is already subscribed we display a
                 // message accordingly.
                 // --------------------------------------------------------
                 if (SilvercartNewsletter::isEmailAllocatedByAnonymousRecipient($formData['Email'])) {
                     $this->setSessionMessage(sprintf(_t('SilvercartNewsletterStatus.ALREADY_SUBSCRIBED'), $formData['Email']));
                 } else {
                     SilvercartNewsletter::subscribeAnonymousCustomer($formData['Salutation'], $formData['FirstName'], $formData['Surname'], $formData['Email']);
                     $this->setSessionMessage(sprintf(_t('SilvercartNewsletterStatus.SUBSCRIBED_SUCCESSFULLY_FOR_OPT_IN'), $formData['Email']));
                 }
             } else {
                 // --------------------------------------------------------
                 // Unsubscribe from newsletter.
                 // If no email address exists we display a message
                 // accordingly.
                 // --------------------------------------------------------
                 if (SilvercartNewsletter::isEmailAllocatedByAnonymousRecipient($formData['Email'])) {
                     SilvercartNewsletter::unSubscribeAnonymousCustomer($formData['Email']);
                     $this->setSessionMessage(sprintf(_t('SilvercartNewsletterStatus.UNSUBSCRIBED_SUCCESSFULLY'), $formData['Email']));
                 } else {
                     $this->setSessionMessage(sprintf(_t('SilvercartNewsletterStatus.NO_EMAIL_FOUND'), $formData['Email']));
                 }
             }
         }
     }
     $redirectLink = '/';
     $responsePage = SilvercartPage_Controller::PageByIdentifierCode("SilvercartNewsletterResponsePage");
     if ($responsePage) {
         $redirectLink = $responsePage->RelativeLink();
     }
     $this->controller->redirect($redirectLink);
 }
 /**
  * Returns the number of products per page according to where it is set.
  * Highest priority has the customer's configuration setting if available.
  * Next comes the shop owners setting for this page; if that's not
  * configured we use the global setting from SilvercartConfig.
  *
  * @return int
  */
 public function getProductsPerPageSetting()
 {
     $productsPerPage = 0;
     $member = SilvercartCustomer::currentUser();
     if ($member && $member->getSilvercartCustomerConfig() && $member->getSilvercartCustomerConfig()->productsPerPage !== null) {
         $productsPerPage = $member->getSilvercartCustomerConfig()->productsPerPage;
         if ($productsPerPage == 0) {
             $productsPerPage = SilvercartConfig::getProductsPerPageUnlimitedNumber();
         }
     } else {
         if ($this->productsPerPage) {
             $productsPerPage = $this->productsPerPage;
         } else {
             $productsPerPage = SilvercartConfig::ProductsPerPage();
         }
     }
     return $productsPerPage;
 }
 /**
  * determins weather a customer gets prices shown gross or net dependent on
  * customer's invoice address or class
  *
  * @return string returns "gross" or "net"
  * 
  * @author Roland Lehmann <*****@*****.**>,
  *         Sebastian Diel <*****@*****.**>
  * @since 15.11.2014
  */
 public static function Pricetype()
 {
     if (is_null(self::$priceType)) {
         $member = SilvercartCustomer::currentUser();
         $configObject = self::getConfig();
         $silvercartPluginResult = SilvercartPlugin::call($configObject, 'overwritePricetype', array());
         if (!empty($silvercartPluginResult)) {
             self::$priceType = $silvercartPluginResult;
         } elseif ($member) {
             foreach ($member->Groups() as $group) {
                 if (!empty($group->Pricetype) && $group->Pricetype != '---') {
                     self::$priceType = $group->Pricetype;
                     break;
                 }
             }
             if (is_null(self::$priceType)) {
                 self::$priceType = self::DefaultPriceType();
             }
         } else {
             self::$priceType = self::DefaultPriceType();
         }
     }
     return self::$priceType;
 }
 /**
  * Returns the current customer.
  * 
  * @return Member
  */
 public function getCustomer()
 {
     return SilvercartCustomer::currentUser();
 }
 /**
  * Returns the allowed payment methods.
  *
  * @return ArrayList|Boolean
  */
 public function getAllowedPaymentMethods()
 {
     if (is_null($this->allowedPaymentMethods)) {
         $allowedPaymentMethods = new ArrayList();
         $stepData = $this->controller->getCombinedStepData();
         if (SilvercartCustomer::currentUser() instanceof Member && is_array($stepData) && array_key_exists('Shipping_Country', $stepData) && $stepData['Shipping_Country'] != "") {
             $shippingCountry = DataObject::get_by_id('SilvercartCountry', $stepData['Shipping_Country']);
             if ($shippingCountry instanceof SilvercartCountry) {
                 $allowedPaymentMethods = SilvercartPaymentMethod::getAllowedPaymentMethodsFor($shippingCountry, SilvercartCustomer::currentUser()->getCart());
                 if (!$allowedPaymentMethods instanceof ArrayList) {
                     $allowedPaymentMethods = new ArrayList();
                 }
             }
         }
         $this->setAllowedPaymentMethods($allowedPaymentMethods);
     }
     return $this->allowedPaymentMethods;
 }
 /**
  * Creates the cache key for this widget.
  * 
  * @param SilvercartWidget_Controller $widget Widget to get cache key for
  *
  * @return string
  *
  * @author Sebastian Diel <*****@*****.**>
  * @since 15.11.2014
  */
 public static function ProductWidgetCacheKey($widget)
 {
     $key = '';
     if ($widget->Elements() instanceof SS_List && $widget->Elements()->exists()) {
         $map = $widget->Elements()->map('ID', 'LastEditedForCache');
         if ($map instanceof SS_Map) {
             $productMap = $map->toArray();
         } else {
             $productMap = $map;
         }
         if (!is_array($productMap)) {
             $productMap = array();
         }
         if ($widget->Elements()->exists() && (empty($productMap) || count($productMap) == 1 && array_key_exists('', $productMap))) {
             $productMap = array();
             foreach ($widget->Elements() as $page) {
                 $map = $page->Elements->map('ID', 'LastEditedForCache');
                 if ($map instanceof SS_Map) {
                     $productMapToAdd = $map->toArray();
                 } else {
                     $productMapToAdd = $map;
                 }
                 $productMap = array_merge($productMap, $productMapToAdd);
             }
         }
         $productMapIDs = implode('_', array_keys($productMap));
         sort($productMap);
         $productMapLastEdited = array_pop($productMap);
         $groupIDs = '';
         if (Member::currentUserID() > 0) {
             $groupIDs = implode('-', SilvercartCustomer::currentUser()->getGroupIDs());
         }
         $keyParts = array(i18n::get_locale(), $productMapIDs, $productMapLastEdited, $widget->LastEdited, $groupIDs);
         $key = implode('_', $keyParts);
     }
     return $key;
 }
 /**
  * Returns the target customer group.
  * 
  * @param array $formData Submitted form data.
  * 
  * @return Group
  */
 public function getTargetCustomerGroup($formData)
 {
     if (array_key_exists('IsBusinessAccount', $formData) && $formData['IsBusinessAccount'] == '1') {
         $customerGroup = SilvercartCustomer::default_customer_group_b2b();
     } else {
         $customerGroup = SilvercartCustomer::default_customer_group();
     }
     return $customerGroup;
 }
 /**
  * Disable editing for all Member types.
  *
  * @param Member $member Member, defined for compatibility with parent
  *
  * @return bool
  *
  * @author Sebastian Diel <*****@*****.**>
  * @since 15.11.2014
  */
 public function canEdit($member = null)
 {
     if ($member === null) {
         $member = SilvercartCustomer::currentUser();
     }
     if ($member && $member->inGroup('administrators')) {
         return true;
     }
     return false;
 }
 /**
  * We save the chosen value for the products per page in the customer's
  * configuration object here and redirect to the last view.
  *
  * @param SS_HTTPRequest $data     contains the frameworks form data
  * @param Form           $form     not used
  * @param array          $formData contains the modules form data
  *
  * @return void
  *
  * @author Sebastian Diel <*****@*****.**>,
  *         Sascha Koehler <*****@*****.**>
  * @since 15.11.2014
  */
 public function submitSuccess($data, $form, $formData)
 {
     $backLink = $this->controller->Link();
     $member = SilvercartCustomer::currentUser();
     $product = singleton('SilvercartProduct');
     $sortableFrontendFields = $product->sortableFrontendFields();
     $sortableFrontendFieldValues = array_keys($sortableFrontendFields);
     $sortOrder = $sortableFrontendFieldValues[$data['SortOrder']];
     SilvercartProduct::setDefaultSort($sortOrder);
     if (!$member) {
         $member = SilvercartCustomer::createAnonymousCustomer();
     }
     if ($member) {
         $member->getSilvercartCustomerConfig()->productsPerPage = $data['productsPerPage'];
         $member->getSilvercartCustomerConfig()->write();
     }
     if (isset($formData['backLink'])) {
         $backLink = $formData['backLink'];
     }
     $this->controller->redirect($backLink, 302);
 }
 /**
  * Returns the context address.
  * 
  * @return SilvercartAddress
  */
 public function getAddress()
 {
     $member = SilvercartCustomer::currentUser();
     $id = $this->customParameters['addressID'];
     if ($member && $id) {
         $filter = array("MemberID" => $member->ID, "ID" => $id);
         $this->address = SilvercartAddress::get()->filter($filter)->first();
     }
     return $this->address;
 }
 /**
  * chpppopt stands for "CHange Products Per Page Option".
  * Changes the quantity of products to display in a product lists.
  * 
  * @param SS_HTTPRequest $request Request
  * 
  * @return string
  * 
  * @author Sebastian Diel <*****@*****.**>
  * @since 27.11.2014
  */
 public function chpppopt(SS_HTTPRequest $request)
 {
     $member = SilvercartCustomer::currentUser();
     $newOption = $request->param('ID');
     $product = singleton('SilvercartProduct');
     $sortableFrontendFields = $product->sortableFrontendFields();
     $sortableFrontendFieldValues = array_keys($sortableFrontendFields);
     if (array_key_exists($newOption, $sortableFrontendFieldValues)) {
         $sortOrder = $sortableFrontendFieldValues[$newOption];
         SilvercartProduct::setDefaultSort($sortOrder);
     }
     if ($member instanceof Member && $member->exists()) {
         $member->getSilvercartCustomerConfig()->productsPerPage = $newOption;
         $member->getSilvercartCustomerConfig()->write();
     }
     self::setProductsPerPage($newOption);
     $this->redirect($this->Link());
 }
 /**
  * Returns the current customer.
  * 
  * @return Member
  */
 public function getCustomer()
 {
     return SilvercartCustomer::currentRegisteredCustomer();
 }
 /**
  * Returns the prices amount
  * 
  * @param bool              $plain              Set to true to load the price amount without any manipulation
  * @param float             $amountToGetFeeFor  Amount to get fee for
  * @param SilvercartCountry $countryToGetFeeFor Amount to get fee for
  *
  * @return float
  *
  * @author Sebastian Diel <*****@*****.**>,
  *         Sascha Koehler <*****@*****.**>
  * @since 15.11.2014
  */
 public function getPriceAmount($plain = false, $amountToGetFeeFor = null, $countryToGetFeeFor = null)
 {
     $price = (double) $this->Price->getAmount();
     if (!$plain) {
         if (SilvercartConfig::PriceType() == 'net') {
             $price = $price - $this->getTaxAmount($price);
         }
         if (SilvercartCustomer::currentUser() && SilvercartCustomer::currentUser()->SilvercartShoppingCartID > 0) {
             $silvercartShoppingCart = SilvercartCustomer::currentUser()->getCart();
             $shoppingCartValue = $silvercartShoppingCart->getTaxableAmountWithoutFees();
             if (is_null($amountToGetFeeFor)) {
                 $amountToGetFeeFor = $shoppingCartValue->getAmount();
             }
             if (is_null($countryToGetFeeFor)) {
                 $countryToGetFeeFor = $this->SilvercartShippingMethod()->getShippingCountry();
             }
             if ($this->ShippingIsFree($amountToGetFeeFor, $countryToGetFeeFor)) {
                 $price = 0.0;
             }
         }
         $price = round($price, 2);
         $this->extend('updatePriceAmount', $price);
     } elseif (!is_null($amountToGetFeeFor) && !is_null($countryToGetFeeFor) && $this->ShippingIsFree($amountToGetFeeFor, $countryToGetFeeFor)) {
         $price = 0.0;
     }
     return $price;
 }
 /**
  * The newsletter checkbox should not be shown if a registered customer has
  * already subscribed to the newsletter.
  * 
  * @return boolean answer 
  * 
  * @author Roland Lehmann <*****@*****.**>
  * @since 22.7.2011
  */
 public function showNewsletterCheckbox()
 {
     $customer = SilvercartCustomer::currentRegisteredCustomer();
     if ($customer && $customer->SubscribedToNewsletter == 1) {
         return false;
     }
     return true;
 }
Beispiel #30
0
 /**
  * determine the tax rate. This method can be extended via DataExtension
  * to implement project specific behavior.
  * 
  * @param bool $ignoreTaxExemption Determines whether to ignore tax exemption or not.
  *
  * @return float the tax rate in percent
  * 
  * @author Roland Lehmann <*****@*****.**>,
  *         Sebastian Diel <*****@*****.**>
  * @since 15.11.2014
  */
 public function getTaxRate($ignoreTaxExemption = false)
 {
     $overwritten = $this->extend('getTaxRate');
     if (empty($overwritten)) {
         $member = SilvercartCustomer::currentUser();
         if (!$ignoreTaxExemption && $member instanceof Member && $member->doesNotHaveToPayTaxes()) {
             $rate = 0;
         } else {
             $rate = $this->Rate;
         }
     } else {
         $rate = $overwritten[0];
     }
     return $rate;
 }