CHAPTER 14 ?– ACCEPTING CUSTOMER ORDERS 438
Implementing the Presentation Tier
Finally, you??™ll see the code you??™ve written put into action. The Place Order button is the only
addition on the visitor side of the interface for the custom checkout. Let??™s first place the button
on the cart_details template file and then implement its functionality.
Exercise: Placing Orders
1. Modify presentation/templates/cart_details.tpl by adding a new button just after the Update
button, as highlighted in the following code snippet:
2. Now, we also need to make a small change to ajax.js, to ensure that the new button isn??™t handled by
JavaScript code. If you remember, in Chapter 13, we added the onsubmit event handler to the shopping
cart form, so shopping cart actions are handled asynchronously, using AJAX, whenever possible.We don??™t
want this to happen for the Place Order button. This button must submit the form to the server, which redirects
the request to the checkout page. Modify ajax.js as highlighted:
// Holds an instance of XMLHttpRequest
var xmlHttp = createXmlHttpRequestObject();
// Display error messages (true) or degrade to non-AJAX behavior (false)
var showErrors = true;
// Contains the link or form clicked or submitted by the visitor
var actionObject = '';
// This is true when the Place Order button is clicked, false otherwise
var placingOrder = false;
// Creates an XMLHttpRequest instance
function createXmlHttpRequestObject()
CHAPTER 14 ?– ACCEPTING CUSTOMER ORDERS 439
3.
Pages:
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557