/**
  * @param Controller $controller
  * @param String $name
  * @param Order $order
  * @param String
  */
 function __construct(Controller $controller, $name, Order $order, $returnToLink = '')
 {
     $fields = new FieldList(new HiddenField('OrderID', '', $order->ID));
     if ($returnToLink) {
         $fields->push(new HiddenField("returntolink", "", convert::raw2att($returnToLink)));
     }
     $bottomFields = new CompositeField();
     $bottomFields->addExtraClass('bottomOrder');
     if ($order->Total() > 0) {
         $paymentFields = EcommercePayment::combined_form_fields($order->getTotalAsMoney()->NiceLongSymbol(false), $order);
         foreach ($paymentFields as $paymentField) {
             $bottomFields->push($paymentField);
         }
         if ($paymentRequiredFields = EcommercePayment::combined_form_requirements($order)) {
             $requiredFields = array_merge($requiredFields, $paymentRequiredFields);
         }
     } else {
         $bottomFields->push(new HiddenField("PaymentMethod", "", ""));
     }
     $fields->push($bottomFields);
     $actions = new FieldList(new FormAction('dopayment', _t('OrderForm.PAYORDER', 'Pay balance')));
     $requiredFields = array();
     $validator = OrderForm_Payment_Validator::create($requiredFields);
     $form = parent::__construct($controller, $name, $fields, $actions, $validator);
     //extension point
     $this->extend('updateFields', $fields);
     $this->setFields($fields);
     $this->extend('updateActions', $actions);
     $this->setActions($actions);
     $this->extend('updateValidator', $validator);
     $this->setValidator($validator);
     $this->setFormAction($controller->Link($name));
     $oldData = Session::get("FormInfo.{$this->FormName()}.data");
     if ($oldData && (is_array($oldData) || is_object($oldData))) {
         $this->loadDataFrom($oldData);
     }
     $this->extend('updateOrderForm_Payment', $this);
 }
 /**
  *
  * @param Controller $controller
  * @param String
  */
 function __construct(Controller $controller, $name)
 {
     //requirements
     Requirements::javascript('ecommerce/javascript/EcomOrderForm.js');
     //set basics
     $order = ShoppingCart::current_order();
     $order->calculateOrderAttributes($force = false);
     $requiredFields = array();
     //  ________________  3) Payment fields - BOTTOM FIELDS
     $bottomFields = new CompositeField();
     $bottomFields->addExtraClass('bottomOrder');
     if ($order->Total() > 0) {
         $bottomFields->push(new HeaderField("PaymentHeader", _t("OrderForm.PAYMENT", "Payment"), 3));
         $paymentFields = EcommercePayment::combined_form_fields($order->getTotalAsMoney()->NiceLongSymbol(false), $order);
         foreach ($paymentFields as $paymentField) {
             $bottomFields->push($paymentField);
         }
         if ($paymentRequiredFields = EcommercePayment::combined_form_requirements($order)) {
             $requiredFields = array_merge($requiredFields, $paymentRequiredFields);
         }
     } else {
         $bottomFields->push(new HiddenField("PaymentMethod", "", ""));
     }
     //  ________________  4) FINAL FIELDS
     $finalFields = new CompositeField();
     $finalFields->addExtraClass('finalFields');
     $finalFields->push(new HeaderField('CompleteOrder', _t('OrderForm.COMPLETEORDER', 'Complete Order'), 3));
     // If a terms and conditions page exists, we need to create a field to confirm the user has read it
     if ($termsAndConditionsPage = CheckoutPage::find_terms_and_conditions_page()) {
         $checkoutPage = CheckoutPage::get()->First();
         if ($checkoutPage && $checkoutPage->TermsAndConditionsMessage) {
             $alreadyTicked = false;
             $requiredFields[] = 'ReadTermsAndConditions';
         } else {
             $alreadyTicked = true;
         }
         $finalFields->push(new CheckboxField('ReadTermsAndConditions', _t('OrderForm.AGREEWITHTERMS1', 'I have read and agree with the ') . ' <a href="' . $termsAndConditionsPage->Link() . '">' . trim(Convert::raw2xml($termsAndConditionsPage->Title)) . '</a>' . _t('OrderForm.AGREEWITHTERMS2', '.'), $alreadyTicked));
     }
     $textAreaField = new TextareaField('CustomerOrderNote', _t('OrderForm.CUSTOMERNOTE', 'Note / Question'));
     $finalFields->push($textAreaField);
     //  ________________  5) Put all the fields in one FieldList
     $fields = new FieldList($bottomFields, $finalFields);
     //  ________________  6) Actions and required fields creation + Final Form construction
     $actions = new FieldList(new FormAction('processOrder', _t('OrderForm.PROCESSORDER', 'Place order and make payment')));
     $validator = OrderForm_Validator::create($requiredFields);
     //we stick with standard validation here, because of the complexity and
     //hard-coded payment validation that is required
     parent::__construct($controller, $name, $fields, $actions, $validator);
     $this->setAttribute("autocomplete", "off");
     //extension point
     $this->extend('updateFields', $fields);
     $this->setFields($fields);
     $this->extend('updateActions', $actions);
     $this->setActions($actions);
     $this->extend('updateValidator', $validator);
     $this->setValidator($validator);
     //  ________________  7)  Load saved data
     if ($order) {
         $this->loadDataFrom($order);
     }
     //allow updating via decoration
     $this->extend('updateOrderForm', $this);
 }