/**
  * 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. 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);
 }