public function authorization() { //-----------------------------------------------\\ // This is the MIDDLE checkout page where the \\ // user info that was received is processed \\ // and inserted/updated in the DB before \\ // sending the user along to the payment segment \\ //-----------------------------------------------\\ // $db=new Database; // In Kohana, all views are loaded and treated as objects. $this->template->content = new View('authorization'); // Meta Description and Meta Keywords for individual pages are, at this point, hard coded. $this->template->metaDescription = $this->description; $this->template->metaKeywords = $this->keywords; $this->template->metaTitle = $this->title; $this->template->title = $this->title; $formFields = User_Model::getFormFields(); //USER if (User_Model::logged_in()) { $user = User_Model::logged_user(); } else { $user = ORM::factory('user'); $user->email = $_POST['userEmail']; $user->password = $_POST['userPassword']; foreach ($formFields['billing'] as $field) { $user->{$field->db_name} = $_POST[$field->formName]; } $user->site_id = self::getCurrentSite()->id; $user->save(); $user->forceLogin(); Autoresponder::sendEmail('user.registration', $user->email, $user, array('new_pass' => $_POST['userPassword'])); } $user->newsletter = isset($_POST["email-updates"]) ? 1 : 0; $user->save(); $user_billing_info = ORM::factory('user_billing_info'); $user_billing_info->user_id = $user->id; foreach ($formFields['billing'] as $field) { if (isset($_POST[$field->formName])) { $user_billing_info->{$field->db_name} = $_POST[$field->formName]; } } $user_billing_info->save(); $user_shipping_info = ORM::factory('user_shipping_info'); $user_shipping_info->user_id = $user->id; foreach ($formFields['shipping'] as $field) { if (isset($_POST[$field->formName])) { $user_shipping_info->{$field->db_name} = $_POST[$field->formName]; } } if (isset($_POST[$field->formName])) { $_SESSION["shipping" . "{$field->formName}"] = $_POST[$field->formName]; } $user_shipping_info->save(); //like the ->reload() function doesn't have into account the relations, this refresh the object and will load the new shipping and billing in case they are needed. $user = ORM::factory('user', $user->id); //ORDER $order = ORM::factory('order')->getCurrentOrder(); $order->can_share = isset($_POST["share"]) ? 1 : 0; //shipping $shippingMethod = ORM::factory('shipping_method')->find($_POST['shippingMethod']); $shippingcost = $shippingMethod->getRateForPrice($order->subtotal)->price; if ($_POST['shippingCountry'] == "CA") { $shippingcost += 30; } $order->shipping_method_id = $shippingMethod->id; $order->shipping_total = $shippingcost; //user into order $order->user_id = $user->id; $order->shippingID = $user->user_shipping_info->id; $order->billingID = $user->user_billing_info->id; //last details and save $order->order_delivery_date = $_POST["requesteddate"]; $order->date_modified = time(); $order->save(); //total and subtotal $order->refreshTotals(); //like the ->reload() function doesn't have into account the relations, this refresh the object and will load the new shipping and billing in case they are needed. $order = ORM::factory('order', $order->id); //FOR NEXT FORM $this->template->content->user = $user; $this->template->content->order = $order; // Send final few pieces of data as variables to the template $this->template->content->requesteddate = $order->order_delivery_date; // After all the alterations and everything have been made, select the basket and pass on the this of items to the template $db = new Database(); $resultall = $db->query(' SELECT orders_baskets.*, orders_baskets.id as orders_basket_id, products.name as productname, products_descriptions.image as productimage, products_descriptions.image_alt FROM orders_baskets LEFT JOIN products ON orders_baskets.product_id = products.id LEFT JOIN products_descriptions ON products.products_description_id = products_descriptions.id WHERE orders_baskets.order_id = ' . $order->id); $this->template->content->itemsresults = $resultall; }
public function register() { if (User_Model::logged_in()) { url::redirect('/customers/my_account'); } $this->template->content = new View('customers/register'); $this->template->metaDescription = $this->description; $this->template->metaKeywords = $this->keywords; $this->template->metaTitle = $this->title; $this->template->title = $this->title; $formFields = User_Model::getFormFields(); if (User_Model::logged_in()) { $user = User_Model::logged_user(); $this->template->content->user = $user; foreach ($formFields as $section => &$fields) { if ($section == 'user') { continue; } foreach ($fields as &$field) { switch ($field->form) { case 'billing': $field->value = $user->user_billing_info->{$field->db_name}; break; case 'shipping': $field->value = $user->user_shipping_info->{$field->db_name}; break; } } } } $this->template->content->formFields = $formFields; $this->template->content->countries = ORM::factory('country')->find_all(); $this->template->content->states = ORM::factory('state')->find_all(); if (request::method() === 'post') { $post = new Validation($_POST); $post->add_rules('email', 'email'); $post->add_rules('password', 'required'); $post->add_rules('first_name', 'required'); $post->add_rules('last_name', 'required'); $post->add_rules('address_1', 'required'); $post->add_rules('city', 'required'); $post->add_rules('state', 'required'); $post->add_rules('zip', 'required'); $post->add_rules('country', 'required'); $post->add_rules('phone', 'required'); if ($post->validate()) { $db = new Database(); //$auth = _Auth::factory(); $user = ORM::factory('user'); $user->email = $post->email; $user->password = $post->password; $user->firstname = $post->first_name; $user->lastname = $post->last_name; $user->company = $post->company; $user->address1 = $post->address_1; $user->address2 = $post->address_2; $user->city = $post->city; $user->state = $post->state; $user->zip = $post->zip; $user->country = $post->country; $user->phone1 = $post->phone; $user->phone2 = $post->second_phone; $user->save(); unset($user); $id = $db->query("SELECT id\n\t\t\t\t\t\t\t\t FROM users\n\t\t\t\t\t\t\t\t WHERE email = '{$post->email}'"); //print_r(mysql_fetch); foreach ($id as $keys => $value) { // echo 'Key: '. $keys."<br>"; if (is_object($value)) { foreach ($value as $vkeys => $vvalue) { // echo 'VKeys: '.$vkeys."<br>"; // echo 'VValue: '.$vvalue."<br>"; if ($vkeys == 'id') { $id = $vvalue; } } } else { // echo 'Value: '.$value."<br>"; } } //die(); if (!$post->address_2) { $post->address_2 = "none"; } if (!$post->second_phone) { $post->second_phone = "none"; } $billing = $db->query("INSERT into user_billing_infos\n\t\t\t\t\t\t\tSET user_id = '{$id}', \n\t\t\t\t\t\t\tfirstname = '{$post->first_name}',\n\t\t\t\t\t\t\tlastname = '{$post->last_name}',\n\t\t\t\t\t\t\tcompany = '{$post->company}',\n\t\t\t\t\t\t\taddress1 = '{$post->address_1}',\n\t\t\t\t\t\t\taddress2 = '{$post->address_2}',\n\t\t\t\t\t\t\tcity = '{$post->city}',\n\t\t\t\t\t\t\tstate = '{$post->state}',\n\t\t\t\t\t\t\tzip = '{$post->zip}',\n\t\t\t\t\t\t\tcountry = '{$post->country}',\n\t\t\t\t\t\t\tphone1 = '{$post->phone}',\n\t\t\t\t\t\t\tphone2 = '{$post->second_phone}'\n\t\t\t\t\t\t\t"); //$results = $db->excute(); // $user = ORM::factory('user_billing_infos'); // $user->email = $post->email; // $user->password = md5($post->password); // $user->firstname = $post->first_name; // $user->lastname = $post->last_name; // $user->company = $post->company; // $user->address1 = $post->address_1; // $user->address2 = $post->address_2; // $user->city = $post->city; // $user->state = $post->state; // $user->zip = $post->zip; // $user->country = $post->country; // $user->phone1 = $post->phone; // $user->phone2 = $post->second_phone; // $user->save(); // unset($user); // print_r($post->s_billing) if (isset($post->s_billing) === '1' && isset($post->s_billing) != "") { $shipping = $db->query("INSERT INTO user_shipping_infos\n\t\t\t\t\t\t\tSET user_id = '{$id}',\n\t\t\t\t\t\t\tfirstname = '{$post->first_name}',\n\t\t\t\t\t\t\tlastname = '{$post->last_name}',\n\t\t\t\t\t\t\tcompany = '{$post->company}',\n\t\t\t\t\t\t\taddress1 = '{$post->address_1}',\n\t\t\t\t\t\t\taddress2 = '{$post->address_2}',\n\t\t\t\t\t\t\tcity = '{$post->city}',\n\t\t\t\t\t\t\tstate = '{$post->state}',\n\t\t\t\t\t\t\tzip = '{$post->zip}',\n\t\t\t\t\t\t\tcountry = '{$post->country}',\n\t\t\t\t\t\t\tphone1 = '{$post->phone}',\n\t\t\t\t\t\t\tphone2 = '{$post->second_phone}'\n\t\t\t\t\t\t\t"); //$results2 = $db->excute(); // $user = ORM::factory('user_shipping_infos'); // $user->firstname = $post->s_first_name; // $user->lastname = $post->s_last_name; // $user->company = $post->s_company; // $user->address1 = $post->s_address_1; // $user->address2 = $post->s_address_2; // $user->city = $post->s_city; // $user->state = $post->s_state; // $user->zip = $post->s_zip; // $user->country = $post->s_country; } url::redirect('/customers/login'); } } }