Ruby-on-Rails

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).

Checkout and Order Processing: the Administrative Side - Implementing the Administrator User Stories(Page 3 of 4 )

Next, we値l build the administrator interface for managing orders. After the system has sent the payment request to the payment gateway, George needs to log in to the payment gateway and verify that the transaction has been settled, meaning that the funds have been transferred from the customer to George痴 bank account. There might be a delay between the request and when the funds are actually transferred.

When George goes to the order administration interface, he wants to see a list of all orders, sorted by the date they were created. He also wants to list orders by status, so we値l create a view for listing all orders, as well as individual views for listing orders by their status:open,processed,closed, andfailed.

Implementing the View Orders User Story

The first step in implementing this View Orders user story is to generate a controller:

First, we retrieve thestatusparameter, which we値l use to filter the list of orders. If it is blank, we simply show all orders. If thestatusparameter is not blank, then we use it to build theconditionsparameter for thepaginatemethod. We also set theorderparameter so that the list is sorted.

Next, we値l create a menu that allows George to filter the list of orders easily. Save the code shown here inapp/views/admin/order/_navigation.rhtml:

At the top of page, we include the navigation. Then we loop through the orders and display them in a table. We also include a button that takes us to the order details page, which we値l implement shortly. At the very bottom of the page, we use thepagination_linkshelper method to generate a menu that is used to navigate between the pages. Each page displays ten orders, and if there are more, a menu like this will be displayed:

That was easy! We have now implemented the View Orders user story. Before moving on to the next user story, let痴 do a quick acceptance test, by openinghttp://localhost:3000/admin/order. If you (or your customers) have created some orders, you値l see something similar to Figure 9-13.

Figure 9-13.The view orders page displaying all orders

If you navigate to the page that shows processed orders (http://localhost:3000/admin/ order/processed), you値l see orders that the system has sent to the payment gateway, but which George still needs to ship to the customer and close. An example of this page is shown in Figure 9-14.

Figure 9-14.The view orders page showing only processed orders

Note For the administrator user stories, we won稚 walk through functional and integration tests. At this point, you should be familiar with developing these tests and able to write them all by yourself.