Completing Checkout

 Introduction.  Finally, we are at the end of our ecommerce ordeal.  Now we need to complete the order processing by doing the following. compute the shipping costs compute the taxes compute the appropriate totals and subtotals display these values and the order number write these and other overall values to the basket table for this id_basket display what has been ordered (left for you in homework) display the billing information (left for you in homework) display the shipping information (left for you in homework) Most of this processing is quite sequential and it is more an issue of being organized than being clever.  This page should be called checkout_completed.php.

 Completing the Checkoutder = \$row[lower_limit]) && (\$total_weight <= \$row[upper_limit])) { \$in_table = "found"; \$shipping_cost = \$row[shipping_cost]; } } // if the weight is too large to be contained in the table we need to // compute the shipping using the formula if (\$in_table == "not_found") { \$shipping_cost = 5.00 + (0.5 * \$total_weight); } \$shipping_cost = round(\$shipping_cost,2); // now we need to determine if there are any taxes to be charged // based on the \$ship_state // first we need to develop another query to access the state tax rate \$tax_query_string = "SELECT * FROM taxes_state WHERE state_name = '\$ship_state'"; // now we need to create the resultset \$tax_result_set = mysql_db_query(\$db_name, \$tax_query_string, \$link); // looping through the entries in the resultset to determine taxes while (\$row_tax = mysql_fetch_array(\$tax_result_set)) { \$tax = \$row_tax[tax_rate] * \$sub_total; \$tax = round(\$tax,2); \$sub_total = round(\$sub_total,2); \$overall_cost = \$sub_total + \$tax + \$shipping_cost; \$overall_cost = round(\$overall_cost,2); } // now we want to update our values in the basket \$update_query_string = "UPDATE basket SET order_placed = \$order_placed, sub_total = \$sub_total, total =\$overall_cost, cost_shipping = \$shipping_cost, tax =\$tax WHERE (id_basket = \$id_basket)"; // performing the update mysql_db_query(\$db_name, \$update_query_string, \$link); // now we want to retrive the order_number for the order // get the id_order_data from the session variable // put it into a local variable for display \$order_number = \$_SESSION["id_order_data"]; ?>

The subtotal is: \$
The tax is: \$
The shipping costs: \$

The total cost is: \$

 A typical page should look like the following.

 A general code description follows. we start by developing some mnemonic local variables based on the \$_SESSION variables then we connect to the database the first query selects everything from the shipping table in order to compute the shipping costs based on the total weight we loop through the resultset to see if the weight fits between any given pairs of lower_limit and upper_limit if they do then we pull the cost of shipping form the table if they don't then we compute the shipping based on the formula we round the cost of shipping to two decimal places so that we can update out basket table later next we create a query to access the tax rate from the taxes_state table based on where the order will be shipped we compute the taxes we accumulate our subtotals and totals and round them to two decimal places so that we can update our basket table later next we perform the update to the basket table based on the id_basket next we retrieve the order number for the order from the order_data table based on the id_basket finally, we display these results in a table using appropriate formatting That's all folks!  Though I may get back to developing the store management side of this.