/** * CONTROLLER ACTION /place * Start the order process using the current basket. */ public function place(SS_HTTPRequest $request) { /** * If the basket is empty there is no order to process, * so redirect the user to their basket. */ if (!Store_BasketController::is_basket_full()) { return $this->redirect(Store_BasketController::get_link()); } /** * If no-body is currently signed in, redirect them to the login/register forms. */ if (!Customer::currentUser() && $request->param("ID") !== "one") { return $this->redirect($this->link() . "/place/one", 403); } /** * If the signed in user is not part of the 'Customers' group * then they are not permitted to make an order so render an * order error page that informs them of such. */ if (Customer::currentUser()) { if (DB::Query("\n\t\t\t\tSELECT COUNT(*) FROM group_members\n\t\t\t\tWHERE (`GroupID`='" . DataObject::get_one("Group", "(`Title`='Customers')")->ID . "' \n\t\t\t\tAND `MemberID`='" . Customer::currentUserID() . "')\n\t\t\t")->value() < 1) { return $this->customise(array("Title" => "An unexpected error occurred."))->renderWith(array("Store_Order_Error_MemberGroup", "Page")); } } /** * If customer is signed in, but no ID is set in the URL, redirect to /two. */ if (Customer::currentUser() && !$request->param("ID")) { return $this->redirect($this->link() . "/place/two", 403); } /** * Use switch() on $request->param("ID") to determine * the stage of the order process. */ switch ($request->param("ID")) { /** * ORDER PROCESS STEP ONE * Prompt the user to login or create an account. * If the user is already signed in, redirect to stage two. */ case "one": if (!Customer::currentUser()) { Session::set('BackURL', $this->link() . "/place/two"); return $this->customise(array("Title" => "Login/Register"))->renderWith(array("Store_Order_Step1", "Page")); } else { return $this->redirect($this->link() . "/place/two"); } break; /** * ORDER PROCESS STEP TWO * Prompt the user to select their billing address from their * Customer_AddressBook. Also provide forms for the customer to complete * should they wish to enter new address. */ /** * ORDER PROCESS STEP TWO * Prompt the user to select their billing address from their * Customer_AddressBook. Also provide forms for the customer to complete * should they wish to enter new address. */ case "two": return $this->customise(array("Title" => "Select Billing Address"))->renderWith(array("Store_Order_Step2", "Page")); break; /** * ORDER PROCESS STEP THREE * Prompt the user to select their shipping address from their * Customer_AddressBook. Also provide forms for the customer to complete * should they wish to enter new address. */ /** * ORDER PROCESS STEP THREE * Prompt the user to select their shipping address from their * Customer_AddressBook. Also provide forms for the customer to complete * should they wish to enter new address. */ case "three": return $this->customise(array("Title" => "Select Delivery Address"))->renderWith(array("Store_Order_Step3", "Page")); break; /** * ORDER PROCESS STEP FOUR * Prompt the user to select their preferred courier * should more than one be available. */ /** * ORDER PROCESS STEP FOUR * Prompt the user to select their preferred courier * should more than one be available. */ case "four": return $this->customise(array("Title" => "Select Courier"))->renderWith(array("Store_Order_Step4", "Page")); break; /** * ORDER PROCESS STEP FIVE * Based on all of the information entered show the final order summary * including tax with a choice of payment method. */ /** * ORDER PROCESS STEP FIVE * Based on all of the information entered show the final order summary * including tax with a choice of payment method. */ case "five": return $this->customise(array("Title" => "Order Summary & Payment"))->renderWith(array("Store_Order_Step5", "Page")); break; /** * ORDER PROCESS ERRORS * If this switch statement is used then the order process hasn't followed * the correct process or has encountered an error. Render an appropriate error. */ /** * ORDER PROCESS ERRORS * If this switch statement is used then the order process hasn't followed * the correct process or has encountered an error. Render an appropriate error. */ default: switch ($request->param("ID")) { /* There doesn't appear to enough stock to satisfy your order at this time. */ case "order-stock": return $this->customise(array("Title" => "An unexpected error occurred."))->renderWith(array("Store_Order_Error_Stock", "Page")); break; /* Default Error Message */ /* Default Error Message */ default: return $this->customise(array("Title" => "An unexpected error occurred."))->renderWith(array("Store_Order_Error", "Page")); break; } break; } }