/** * * @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); }
function __construct($controller, $name) { //requirements Requirements::javascript('ecommerce/javascript/EcomOrderForm.js'); //set basics $order = ShoppingCart::current_order(); $order->calculateOrderAttributes($force = true); $requiredFields = array(); // ________________ 3) Payment fields - BOTTOM FIELDS $bottomFields = new CompositeField(); $bottomFields->setID('BottomOrder'); $totalAsCurrencyObject = $order->TotalAsCurrencyObject(); //should instead be $totalobj = $order->dbObject('Total'); $totalOutstandingAsMoneyObject = $order->TotalAsMoneyObject(); $paymentFields = Payment::combined_form_fields($totalOutstandingAsMoneyObject->Nice()); foreach ($paymentFields as $paymentField) { if ($paymentField->class == "HeaderField") { $paymentField->setTitle(_t("OrderForm.MAKEPAYMENT", "Choose Payment")); } $bottomFields->push($paymentField); } if ($paymentRequiredFields = Payment::combined_form_requirements()) { $requiredFields = array_merge($requiredFields, $paymentRequiredFields); } // ________________ 4) FINAL FIELDS $finalFields = new CompositeField(); $finalFields->setID('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 = DataObject::get_one("CheckoutPage"); 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() . '">' . Convert::raw2xml($termsAndConditionsPage->Title) . '</a>' . _t('OrderForm.AGREEWITHTERMS2', '.'), $alreadyTicked)); } $finalFields->push(new TextareaField('CustomerOrderNote', _t('OrderForm.CUSTOMERNOTE', 'Note / Question'), 7, 30)); // ________________ 5) Put all the fields in one FieldSet $fields = new FieldSet($bottomFields, $finalFields); // ________________ 6) Actions and required fields creation + Final Form construction $actions = new FieldSet(new FormAction('processOrder', _t('OrderForm.PROCESSORDER', 'Place order and make payment'))); $validator = new OrderForm_Validator($requiredFields); //we stick with standard validation here, because of the complexity and //hard-coded payment validation that is required $validator->setJavascriptValidationHandler("prototype"); parent::__construct($controller, $name, $fields, $actions, $validator); //extensions need to be set after __construct if ($this->extend('updateFields', $fields) !== null) { $this->setFields($fields); } if ($this->extend('updateActions', $actions) !== null) { $this->setActions($actions); } if ($this->extend('updateValidator', $validator) !== null) { $this->setValidator($validator); } // ________________ 7) Load saved data if ($order) { $this->loadDataFrom($order); } //allow updating via decoration $this->extend('updateOrderForm', $this); }
public function createValidator() { $validator = OrderForm_Validator::create('PaymentMethod'); if (!$this->customer->ID || $this->customer->Password == '') { $validator->addRequiredField('Password'); $validator->addRequiredField('Email'); } $this->extend('updateValidator', $validator); $validator->setForm($this); return $validator; }