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