Home arrow Ruby-on-Rails arrow Page 4 - Checkout and Order Processing: the Administrative Side

Checkout and Order Processing: the Administrative Side

In this fourth part of a five-part series that shows you how to add checkout and order processing capabilities to an ecommerce application based on Ruby-on-Rails, you'll learn how to integrate a PayPal alternative, build the administrative user interface, and more. This article is excerpted from chapter nine of the book Practical Rails Projects, written by Eldon Alameda (Apress; ISBN: 1590597818).

Author Info:
By: Apress Publishing
Rating: 5 stars5 stars5 stars5 stars5 stars / 5
July 16, 2010
  1. · Checkout and Order Processing: the Administrative Side
  2. · Using the Payment Gem
  3. · Implementing the Administrator User Stories
  4. · Implementing the View Order User Story

print this article

Checkout and Order Processing: the Administrative Side - Implementing the View Order User Story
(Page 4 of 4 )

The order details page is where George can see the information about the order. He needs to check this page before he ships the books to the customer. The page will show the customerís contact information and shipping address. Furthermore, we need to display the order detailsóin other words, the books that the customer has ordered. The credit card details are needed only by the payment gateway, and keeping them in our database would be a huge security risk.

Openapp/controllers/order_controller.rband replace the emptyshow action with the following code:

  def show
    @page_title = "Displaying order ##{params[:id]}"
    @order = Order.find(params[:id])

The action simply pulls out the specified order from the database and sets the page title.

Next, create the view by saving the following code inapp/views/admin/order/show.rhtml:

<%= render :partial => 'navigation' %>
  Order total $<%= @order.total %>
<h2>Contact Information</h2>
  <dd><%= @order.id %></dd>
  <dd><%= @order.email %></dd>
  <dt>Phone number</dt>
  <dd><%= @order.phone_number %></dd>
<h2>Shipping Address</h2>
  <dt>First name</dt>
  <dd><%= @order.ship_to_first_name %></dd>
  <dt>Last name</dt>
  <dd><%= @order.ship_to_last_name %></dd>
  <dd><%= @order.ship_to_address %></dd>
  <dd><%= @order.ship_to_city %></dd>
  <dt>Postal/Zip code</dt>
  <dd><%= @order.ship_to_postal_code %></dd>
  <dd><%= @order.ship_to_country %></dd>

<h2>Order Details</h2>
<% for item in @order.order_items %>
  <%= link_to item.book.title, :action => "show",
        :controller => "catalog", :id => item.book.id %>
  <%= pluralize(item.amount, "pc", "pcs") %>,
  $<%= item.price * item.amount %></br>
<% end %>
  <%= button_to "Close Order", :action => 'close', :id => ➥
@order unless @order.closed? %>

At the top of the page, we show the navigation and order total. Next, we show the contact information, shipping address, and order details sections. At the bottom, we display a button that allows George to close the order, but only if the order hasnít been closed already, which is checked by calling theclosed?method on theOrder model. Note that the page will generate an error until we have added the code shown here to theOrdermodel (app/models/order.rb):

  def closed?
    status == 'closed'

Letís perform an acceptance test. Click the View button from the view orders page (shown in Figures 9-13 and 9-14). You should now see the order details, as shown in Figure 9-15.

Figure 9-15.  The order details page displaying a test order

Please check back next week for the conclusion to this article.

DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

blog comments powered by Disqus

- Ruby-on-Rails Faces Second Security Flaw in ...
- Ruby 2.0 Prepped for February 2013 Release
- Why LinkedIn Switched from Ruby on Rails
- Adding Style with Action Pack
- Handling HTML in Templates with Action Pack
- Filters, Controllers and Helpers in Action P...
- Action Pack and Controller Filters
- Action Pack Categories and Events
- Logging Out, Events and Templates with Actio...
- Action Pack Sessions and Architecture
- More on Action Pack Partial Templates
- Action Pack Partial Templates
- Displaying Error Messages with the Action Pa...
- Action Pack Request Parameters
- Creating an Action Pack Registration Form

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials