/** *@return Boolean + redirection **/ protected function processForm($data, $form, $request, $link = "") { $member = Member::currentUser(); if (!$member) { $form->sessionMessage(_t('Account.DETAILSNOTSAVED', 'Your details could not be saved.'), 'bad'); $this->controller->redirectBack(); } $form->saveInto($member); $password = ShopAccountForm_PasswordValidator::clean_password($data); if ($password) { $member->changePassword($password); } elseif ($data["PasswordCheck1"]) { $form->sessionMessage(_t('Account.NO_VALID_PASSWORD', 'You need to enter a valid password.'), 'bad'); $this->controller->redirectBack(); } if ($member->validate()->valid()) { $member->write(); if ($link) { return $this->controller->redirect($link); } else { $form->sessionMessage(_t('Account.DETAILSSAVED', 'Your details have been saved.'), 'good'); $this->controller->redirectBack(); } } else { $form->sessionMessage(_t('Account.NO_VALID_DATA', 'Your details can not be updated.'), 'bad'); $this->controller->redirectBack(); } }
/** * Check if the password is good enough * @param data (from form) * @return String */ protected function validPasswordHasBeenEntered($data) { return ShopAccountForm_PasswordValidator::clean_password($data); }
/** * Process final confirmation and payment * * {@link Payment} instance is created, linked to the order, * and payment is processed {@link EcommercePayment::processPayment()} * * @param array $data Form request data submitted from OrderForm * @param Form $form Form object for this action * @param HTTPRequest $request Request object for this action */ function processOrder(array $data, Form $form, SS_HTTPRequest $request) { $this->saveDataToSession($data); //save for later if necessary $order = ShoppingCart::current_order(); //check for cart items if (!$order) { $form->sessionMessage(_t('OrderForm.ORDERNOTFOUND', 'Your order could not be found.'), 'bad'); $this->controller->redirectBack(); return false; } if ($order && $order->TotalItems($recalculate = true) < 1) { // WE DO NOT NEED THE THING BELOW BECAUSE IT IS ALREADY IN THE TEMPLATE AND IT CAN LEAD TO SHOWING ORDER WITH ITEMS AND MESSAGE $form->sessionMessage(_t('Order.NOITEMSINCART', 'Please add some items to your cart.'), 'bad'); $this->controller->redirectBack(); return false; } if ($this->extend("OrderFormBeforeFinalCalculation", $data, $form, $request)) { $form->sessionMessage(_t('Order.ERRORWITHFORM', 'There was an error with your order, please review and submit again.'), 'bad'); $this->controller->redirectBack(); return false; } //RUN UPDATES TO CHECK NOTHING HAS CHANGED $oldTotal = $order->Total(); //if the extend line below does not return null then we know there // is an error in the form (e.g. Payment Option not entered) $order->calculateOrderAttributes($force = true); $newTotal = $order->Total(); if (floatval($newTotal) != floatval($oldTotal)) { $form->sessionMessage(_t('OrderForm.PRICEUPDATED', 'The order price has been updated, please review the order and submit again.'), 'warning'); $this->controller->redirectBack(); return false; } //saving into order $form->saveInto($order); $order->write(); //saving into member, in case we add additional fields for the member //e.g. newslettersignup if ($member = Member::currentUser()) { $form->saveInto($member); $password = ShopAccountForm_PasswordValidator::clean_password($data); if ($password) { $member->changePassword($password); } if ($member->validate()) { $member->write(); } else { $form->sessionMessage(_t('OrderForm.ACCOUNTERROR', 'There was an error saving your account details.'), 'warning'); $this->controller->redirectBack(); return false; } } //----------------- CLEAR OLD DATA ------------------------------ $this->clearSessionData(); //clears the stored session form data that might have been needed if validation failed //----------------- VALIDATE PAYMENT ------------------------------ $paymentIsValid = EcommercePayment::validate_payment($order, $form, $data); if (!$paymentIsValid) { $this->controller->redirectBack(); return false; } //-------------- NOW SUBMIT ------------- $this->extend("OrderFormBeforeSubmit", $order); // this should be done before paying, as only submitted orders can be paid! ShoppingCart::singleton()->submit(); $this->extend("OrderFormAfterSubmit", $order); //-------------- ACTION PAYMENT ------------- $payment = EcommercePayment::process_payment_form_and_return_next_step($order, $form, $data); //-------------- DO WE HAVE ANY PROGRESS NOW ------------- $order->tryToFinaliseOrder(); //any changes to the order at this point can be taken care by ordsteps. //------------- WHAT DO WE DO NEXT? ----------------- if ($payment) { //redirection is taken care of by EcommercePayment return $payment; } else { //there is an error with payment if (!Controller::curr()->redirectedTo()) { $this->controller->redirect($order->Link()); } return false; } //------------------------------ }