/**
  * 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());
         }
     }
 }
 /**
  * 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());
         }
         if (Member::currentUserID() > 0) {
             foreach ($this->getAllowedPaymentMethods() as $paymentMethod) {
                 if ($paymentMethod->getNestedFormName()) {
                     $formName = $paymentMethod->getNestedFormName();
                 } else {
                     $formName = "SilvercartCheckoutFormStep4DefaultPayment";
                 }
                 $params = array('PaymentMethod' => $paymentMethod->ID);
                 $preferences = array('submitButtonTitle' => sprintf(_t('SilvercartCheckoutFormStep4.CHOOSE_PAYMENT_METHOD', 'I want to pay with %s'), $paymentMethod->Name));
                 $registeredNestedForm = new $formName($this->controller, $params, $preferences, $barebone);
                 $this->registerCustomHtmlForm($formName . $paymentMethod->ID, $registeredNestedForm);
                 $this->addRegisteredNestedForm($registeredNestedForm);
             }
         }
     }
 }
 /**
  * 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());
         }
     }
 }
 /**
  * init
  *
  * @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());
         }
         if ($this->isCustomerLoggedIn()) {
             $this->registerCustomHtmlForm('SilvercartCheckoutFormStep2Regular', new SilvercartCheckoutFormStep2Regular($this->controller));
             Session::set("redirect", $this->controller->Link());
             $this->registerCustomHtmlForm('SilvercartAddAddressForm', new SilvercartAddAddressForm($this->controller));
         } else {
             $this->registerCustomHtmlForm('SilvercartCheckoutFormStep2Anonymous', new SilvercartCheckoutFormStep2Anonymous($this->controller));
         }
     }
 }
 /**
  * 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);
 }