Home arrow Ruby-on-Rails arrow Checkout and Order Processing: the User Side

Checkout and Order Processing: the User Side

In this conclusion to a five-part article series on adding checkout and order processing capabilities to an ecommerce website with Ruby on Rails, you will learn how to add the close order user story, which involves adding the ability to calculate shipping costs and other details. 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 22, 2010
  1. · Checkout and Order Processing: the User Side
  2. · Calculating Shipping Costs and Taxes
  3. · Calculating Taxes

print this article

Checkout and Order Processing: the User Side
(Page 1 of 3 )

Implementing the Close Order User Story

The Close Order user story is the last one we’ll implement in this sprint. It is used by George (after he has shipped the order) to set the order status to closed. The user story requires that we change thecloseaction inorder_controller.rbas follows: 

  def close
    order = Order.find(params[:id])
flash[:notice] = "Order #{order.id} has been closed"
    redirect_to :action => 'index', :id => 'closed'

The code finds the specified order and calls theclosemethod on theOrdermodel (app/models/order.rb):

  def close
self.status = 'closed'

This method sets the status toclosedand saves the order. After this, the action sets a flash message and redirects to the Closed section of the view orders page.

Test the Close Order user story by closing an order. View the details of a processed order (click the View button for the transaction on the view orders page), and you should see the Close Order button at the bottom of the order details page, as shown in Figure 9-16.

Click the Close Order button, and you are redirected to the page shown in Figure 9-17.

This ends our implementation of the checkout and order-processing functionality. However, you still need to take into account two other items when processing orders: shipping costs and taxes. We’ll take a brief look at those calculations next.

Figure 9-16.  The order details page displaying the Close Order button

Figure 9-17.  The view orders page displaying a message after closing an order

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-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials