Checkout and Order Processing: the User Side
(Page 1 of 3 )
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).
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])
order.close
flash[:notice] = "Order #{order.id} has been closed"
redirect_to :action => 'index', :id => 'closed'
end
The code finds the specified order and calls theclosemethod on theOrdermodel (app/models/order.rb):
def close
self.status = 'closed'
save!
end
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
Next: Calculating Shipping Costs and Taxes >>
More Ruby-on-Rails Articles
More By Apress Publishing