## ## Document History ## ## Created (peeje01) ## 27-Apr-1999 (peeje01) ## Change include file name from -h.html to _h.html ## 02-Apr-2004 (fanra01) ## Bug 112091 ## Editorial changes from griel02. ## Add Item to Bag and Confirm

Add Item to Bag and Confirm

There are three main sections in this document: The first section adds the order to the order table. The second section confirms that the item has been added. In the final section the user can return to the shop (OK) or view the contents of their shopping bag (View Contents of Shopping Bag).

The first section inserts the required item into the order table, play_order, along with the user's login id and the order number. A status of 1 is included.

The meaning of the status column is as follows:

StatusMeaning
1Item placed in bag
2Item ordered
3Order passed to warehouse
4Order in dispatch
5Courier confirms delivery
This exercise set uses the first two. For others, see the further exercise at the end of this page.

The first section adds the order to the order table. The second section confirms that the item has been added and in the final section the user can return to the shop (OK) or view the contents of their shopping bag (View Contents of Shopping Bag).

File: play_shopDescribe.html


<html>
<head>
<title>Add to Bag: Confirmation</title>
</head>
<body>
<h1>Add to Bag: Confirmation</h1>

<!-- #ICE
    DATABASE=`icetutor`
    SQL=`insert into play_order
    (order_nr, user_id, product_id, status)
    values (:e_orderNumber, ':ii_userid', :id, 1)`
    TRANSACTION=`t_shopAdd`
-->
<!-- Flag the transaction as open; we have now added something to the bag -->
<!-- #ICE DECLARE=`session.e_shopTxn=OPEN` -->
<table border=0>
<tr>
<td bgcolor="lime">
The item, 
<!-- #ICE REPEAT
    DATABASE=`icetutor`
    SQL=`
	set lockmode session where readlock = nolock;
	select name, cost
	from play_item
	where id = 
	    (select product_id from play_order
	    where order_nr = :e_orderNumber 
	    and user_id = ':ii_userid'
	    and product_id = :id)`
    TRANSACTION=`t_shopAddConfirm`
    TYPE=`UNFORMATTED`
    HTML=`<b>:name</b> @<i>:cost Silver Crown<!-- #ICE IF ( ``1`` != ``:cost``)
                      THEN=``s`` -->
        </i>`
-->
<!-- #ICE COMMIT=`t_shopAddConfirm` -->
has been added to your shopping bag.
<!-- Standard Shop Action: enable View -->
<!-- #ICE REPEAT INCLUDE=`plays[play_shopAction_h.html]?View=Yes` -->
<!-- Standard Session Control -->
<!-- #ICE REPEAT INCLUDE=`plays[play_SessionControl_h.html]` -->


</body>
</html>

Adding the ordered item to the play_order table is accomplished with an SQL insert statement:

    SQL=`insert into play_order
    (order_nr, user_id, product_id, status)
    values (:e_orderNumber, ':ii_userid', :id, 1)`
    TRANSACTION=`t_shopAdd`

We do not commit this transaction yet because the user may want to add other items to the order. Furthermore, the user may log out or time out before completing their purchases, at which point the ICE server will automatically rollback any open transactions on our behalf. What we do instead is to set the session variable e_shopTxn OPEN with the statement:

    SQL=`insert into play_order
<!-- #ICE DECLARE=`session.e_shopTxn=OPEN` -->

This is a dummy though meaningful value. Remember that when its value is COMPLETE then the shop home page will generate a new order number. We defer committing the transaction until later (on the order confirmation page).

In the second section of the document, we select the same record from play_order and display it in a table with a green background. We place the select statement inside a table cell (<td>). Note that we use readlock = nolock to avoid any locks that may be taken on the table. The transaction, t_shopAddConfirm, is committed immediately -in fact within the HTML table element. Here is the table element in its entirety:

<table border=0>
<tr>
<td bgcolor="lime">
The item, 
<!-- #ICE REPEAT
    DATABASE=`icetutor`
    SQL=`
	set lockmode session where readlock = nolock;
	select name, cost
	from play_item
	where id = 
	    (select product_id from play_order
	    where order_nr = :e_orderNumber 
	    and user_id = ':ii_userid'
	    and product_id = :id)`
    TRANSACTION=`t_shopAddConfirm`
    TYPE=`UNFORMATTED`
    HTML=`<b>:name</b> @<i>:cost Silver Crown<!-- #ICE IF ( ``1`` != ``:cost``)
                      THEN=``s`` -->
        </i>`
-->
<!-- #ICE COMMIT=`t_shopAddConfirm` -->
has been added to your shopping bag.
</table>

The same technique from the previous example has been used to add an "s" to the Silver Crown if the cost is other than one Silver Crown.

In the third section, we enable the View option for the standard set of shop action links.

<!-- #ICE REPEAT INCLUDE=`plays[play_shopAction_h.html]?View=Yes` -->

and

Further exercise

Using the status values 3 through 5, extend the web site so that the user, specifying their order number, can track the order through the system. Hint: At each stage, increment the status, orders of status 5 can be purged from the current order table.

We have already examined the shop home page. We now move on to the view shopping bag page.