Mindwise logo. Click to return to the Mindwise home pageMindwise logo. Click to return to the Mindwise home page

Workshops

<% '******************************************************* '* ASP 101 Sample Code - http://www.asp101.com * '******************************************************* %> <% ' ***** Begin the functions to be called by the runtime script ***** ' To find the actual runtime code scroll WAY DOWN.... ' This function is written to enable the adding of multiples of an item ' but this sample always just adds one. If you wish to add different ' quantities simply replace the value of the Querystring parameter count. ' We didn't do this because we wanted to keep the whole thing simple and ' not get into using forms so it stayed relatively readable. Sub AddItemToCart(iItemID, iItemCount) If dictCart.Exists(iItemID) Then dictCart(iItemID) = dictCart(iItemID) + iItemCount Else dictCart.Add iItemID, iItemCount End If Response.Write "

" & iItemCount & " of item #" & iItemID & " added to your trolley.

" & vbCrLf End Sub Sub RemoveItemFromCart(iItemID, iItemCount) If dictCart.Exists(iItemID) Then If dictCart(iItemID) <= iItemCount Then dictCart.Remove iItemID Else dictCart(iItemID) = dictCart(iItemID) - iItemCount End If Response.Write "

" & iItemCount & " of item # " & iItemID & " removed from your trolley.

" & vbCrLf Else Response.Write "

Couldn't find any of that item your trolley.

" & vbCrLf End If End Sub ' #################################### SHOW ITEMS IN CART ############################## Sub ShowItemsInCart() Dim Key Dim aParameters ' as Variant (Array) Dim sTotal, sShipping %>

Your shopping trolley

<% sTotal = 0 For Each Key in dictCart aParameters = GetItemParameters(Key) %> <% sTotal = sTotal + (dictCart(Key) * CSng(aParameters(2))) Next 'Calculate shipping - you might want to pull this out into a function if your shipping ' calculations are more complicated then ours. ;) If sTotal <> 0 Then sShipping = 0 ' ############ add special postage costs here Else sShipping = 0 End If 'sTotal = sTotal + sShipping %>

Item #

Description

Quantity

Remove item from trolley

Price

Totals

<%= Key %>

<%= aParameters(1) %>

<%= dictCart(Key) %>

Remove
One

Remove
All

$<%= aParameters(2) %>

$<%= FormatNumber(dictCart(Key) * CSng(aParameters(2)),2) %>

Total:

$<%= FormatNumber(sTotal,2) %>

<% End Sub ' #################################### end SHOW IEMS IN CART ############################## ' ######################### SHOPPING CART FIRST PAGE ######################################## Sub ShowFullCatalog() Dim aParameters ' as Variant (Array) Dim I Dim iItemCount ' Number of items we sell ' If you are really going to use this sample this should probably be pulled from a DB iItemCount = 3 ' ########### update number of items ############ %>

Choose a workshop

<% For I = 1 to iItemCount aParameters = GetItemParameters(I) %> <% Next 'I %>

 

Description

Price (including GST)

Shopping trolley

Photo of <%= aParameters(1) %>

<%= aParameters(1) %>

$<%= aParameters(2) %>

Add this to my trolley!

<% End Sub ' ######################### end SHOPPING CART FIRST PAGE ######################################## ' ############################# place order ################################## Sub PlaceOrder() Dim Key Dim aParameters ' as Variant (Array) Dim sTotal, sShipping %>

Place Order

<% sTotal = 0 For Each Key in dictCart aParameters = GetItemParameters(Key) %> <% sTotal = sTotal + (dictCart(Key) * CSng(aParameters(2))) Next 'Calculate shipping - you might want to pull this out into a function if your shipping ' calculations are more complicated then ours. ;) If sTotal <> 0 Then sShipping = 0 ' ######## postage charge goes here if needed ########### Else sShipping = 0 End If 'sTotal = sTotal + sShipping %>

Item #

Description

Quantity

Price

Totals

<%= Key %>

<%= aParameters(1) %>

<%= dictCart(Key) %>

$<%= aParameters(2) %>

$<%= FormatNumber(dictCart(Key) * CSng(aParameters(2)),2) %>

total:

$<%= FormatNumber(sTotal,2) %>

Enter your details here:

<%=request.querystring("reqd")%>

<%=request.querystring("mname")%>Name:

">

<%=request.querystring("maddress")%>Address:

">

<%=request.querystring("msuburb")%>Suburb:

">

<%=request.querystring("mpostcode")%>Postcode:

">

<%=request.querystring("mstate")%>State:

">

<%=request.querystring("memail")%>Email:

">

<%=request.querystring("mtelephone")%>Telephone: 

">

Fax:

">
Credit Card: Visa Mastercard Bankcard Amex Diners
Number:
Expiry:

 

Note: This order form is not secure or encrypted; if you do not wish to transmit your Credit Card number over the internet, we can contact you by telephone for the number and expiry date. Alternatively you can fax your credit card details to us. Print this order form and fax it to:
Mindwise, Level 2, 156 Collins Street, Melbourne, Victoria 3000
Fax: (03) 9528 1184
<% ' ############## shipping cost ############# %> <% ' ############## total cost ############# %> <% ' ############## item number ############# %>

<% End Sub ' We implemented this this way so if you attach it to a database you'd only need one call per item Function GetItemParameters(iItemID) Dim aParameters ' Will contain 3 string values : image path, description, price ' However we need to keep price so it can be converted to a ' single for computation hence no currency symbol. This array ' can also be expanded to contain any other information about the ' product that you might want to pull from the DB. Select Case iItemID Case 1 aParameters = Array("images/products_workshop2-sm.jpg", "Emotional Intelligence in the Workplace, full day workshop, 12 March 2003", "295.00") Case 2 aParameters = Array("images/products_workshop2-sm.jpg", "Emotional Intelligence for Leaders, full day workshop, 13 March 2003", "295.00") Case 3 aParameters = Array("images/products_workshop2-sm.jpg", "Emotional Intelligence for Couples, full day workshop, March 14 2003; ($395.00 per couple)", "395.00") End Select ' Return array containing product info. GetItemParameters = aParameters End Function %> <% ' ########################## ####################################### ' ***** Begin the infamous runtime script ***** ' Declare our Vars Dim dictCart ' as dictionary Dim sAction ' as string Dim iItemID ' as integer Dim iItemCount ' as integer ' Get a reference to the cart if it exists otherwise create it If IsObject(Session("cart")) Then Set dictCart = Session("cart") Else ' We use a dictionary so we can name our keys to correspond to our ' item numbers and then use their value to hold the quantity. An ' array would also work, but would be a little more complex and ' probably not as easy for readers to follow. Set dictCart = Server.CreateObject("Scripting.Dictionary") End If ' Get all the parameters passed to the script sAction = CStr(Request.QueryString("action")) iItemID = CInt(Request.QueryString("item")) iItemCount = CInt(Request.QueryString("count")) %>

<% ' Select action based on user input Select Case sAction Case "add" AddItemToCart iItemID, iItemCount ShowItemsInCart %>

Continue Looking | Arrange purchase
<% Case "del" RemoveItemFromCart iItemID, iItemCount ShowItemsInCart %>

Continue Looking | Arrange purchase
<% Case "viewcart" ShowItemsInCart %>

Continue Looking | Arrange purchase
<% Case "checkout" PlaceOrder %>

<% Case Else ' Shop ShowFullCatalog %>

View my shopping trolley contents <% End Select ' Return cart to Session for storage Set Session("cart") = dictCart %>