Updating the Shopping Basket

 

Introduction.  Now we need to develop an ASP that will be used for updating the items in a shopping basket.  The file will be called UpdateBasket.asp.  This will be presented after discussing stored procedures.

We will need two stored procedures to update the shopping basket.  Both of them have already been developed, sp_RetrieveBasketItem and sp_UpdateBasketItemsQuantity.  The following table displays the name of the stored procedures and the ASP file in which it is called.

 

Stored Procedure ASP Container

sp_RetrieveBasketItem

sp_UpdateBasketItemsQuantity

UpdateBasket.asp

 

The Basket.asp.  Since we have already created the stored procedures required for this ASP, one of the advantages of using stored procedures, we can readily make use of them.  The following UpdateBasket.asp will 
  1. use the sp_RetrieveBasketItem to retrieve the shopper's basket
  2. use the sp_UpdateBasketItemsQuantity to go through the user's shopping basket and update the quantities and pricing associated with each item in the basket.
  3. Redirect to the Basket.asp to display the shopping basket after recalculating.
<%@ Language=VBScript %>
<%
' ****************************************************
' UpdateBasket.asp - This page will read in new quantity for 
' items in the basket and set them appropriately.
' ****************************************************


' Create an ADO database connection
set dbBasketItem = server.createobject("adodb.connection")

' Create a record set
set rsBasketItem = server.CreateObject("adodb.recordset")

' Open the connection using our SQL Server DSN-less connection string
dbBasketItem.ConnectionString="Driver={SQL Server}; Server=cisdev.quinnipiac.edu;" & _
"Database=WildWillies;UID=cis; PWD=csatqu"

dbBasketItem.Open

' Retrieve the basket items
sql = "execute sp_RetrieveBasketItem " & session("idBasket")

' Execute the SQL statement
set rsBasketItem = dbBasketItem.Execute(sql)

' Create an ADO database connection
set dbUpdateItem = server.createobject("adodb.connection")

' Create a record set
set rsUpdateItem = server.CreateObject("adodb.recordset")

' Open the connection using our SQL Server DSN-less connection string
dbUpdateItem.ConnectionString="Driver={SQL Server}; Server=cisdev.quinnipiac.edu;" & _
"Database=WildWillies;UID=cis; PWD=csatqu"

dbUpdateItem.Open

' Loop through the basket items
do until rsBasketItem.EOF 

' Retrieve the quantity. We use the ID of the basket item from the database to retrieve the
' data from the correct input box.

intQuantity = request(cstr(rsBasketItem("idProduct")))

' Call the stored procedure to update the quantity
sql = "execute sp_UpdateBasketItemsQuantity " & _
session("idBasket") & ", " & intQuantity & ", " & _
rsBasketItem("idProduct")

' Execute the SQL statement
set rsUpdateItem = dbUpdateItem.Execute(sql)

' Move to the next item
rsBasketItem.MoveNext 

loop

' Send the user to the basket page
Response.Redirect "basket.asp"

%>

 

Notice that this ASP is essentially purely a processing script.  There isn't any HTML associated with the display.  After the results are developed, the Basket.asp is called to display them.

You should also notice that this ASP page updates only the order quantities.  It could also be worthwhile to enhance this feature to allow modification of other things in the order.