# This page is the main part of a simple, cookie based shopping cart system. # When adding items to the page, either write a static link of the form # to add one of healbook from # the item array, or a form like: # #
# # #
# # The information is sent to the basketview page, which reads the information # and emits cookie tags at the top of the page for any changes. # This will result in the browser machine having an array of cookies for # your site, with the name of the item you want, and the quantity you # were ordering. Said cookies have a duration of one day. Once an order # is placed, the cookies are deleted as part of the process. There is another # page basketedit.nhtml that allows full editing of cart, rather than adding an # item at a time. # First, we load the response array and the cookie array. load_response load_cookies load_file basketcfg.txt # This if statement determines what kind of cookies are emitted at the beginning of # the web page # the first branch is to determine whether or not the information is coming from the basketedit.nhtml # page. if so, there will be an item in the response array called update. if {[catch {set updatevar $response(update)}] == 0 } { # this for statement goes through each item in the response array foreach responseitem [array names response] { # now, for each item, it checks through each member of the item array foreach catalogitem [array names item] { # this if is only called when the response key matches the catalog key. if {$responseitem == $catalogitem} { # this branch is only called if the amount is 0 or less if {$response($responseitem) <= 0} { # if amount 0 or less, this checks to see if there is a cookie already set for the item in # if so, this emits html setting the cookie value to 0, with a lifespan of 1 minute before # the cookie vanishes, and removes the information from the cookies array if {[catch {set iscookie $cookies($responseitem)}] == 0} { html [neo_make_cookie $responseitem 0 -minutes 1] unset cookies($responseitem) } # if amount is greater than 0, this emits html setting the cookie for the item, with a # lifespan of one day } else { html [neo_make_cookie $responseitem $response($responseitem) -days 1] set cookies($responseitem) $response($responseitem) } } } } # this else branch is active if the page was called from anything but the update page. } else { # this for statement goes through each item in the response array foreach responseitem [array names response] { # now, for each item, it checks through each member of the item array foreach catalogitem [array names item] { # this if is only called when the response key matches the catalog key. if {$responseitem == $catalogitem} { # this if tests to see if the new entry is in addition to an existing amount. If # so, it adds the two together if {[catch {set quantity [eval expr $cookies($responseitem) + \ $response($responseitem)]} notthere] != 0 } { # if amount 0 or less, this emits html setting the cookie value to 0, with a lifespan of 1 minute before # the cookie vanishes, and removes the information from the cookies array if {$response($responseitem) <= 0} { html [neo_make_cookie $responseitem 0 -minutes 1] unset cookies($responseitem) # if amount is greater than 0, this emits html setting the cookie for the item, with a # lifespan of one day } else { html [neo_make_cookie $responseitem $response($responseitem) -days 1] set cookies($responseitem) $response($responseitem) } # this else takes effect if there is no existing amount } else { # if amount 0 or less, this emits html setting the cookie value to 0, with a lifespan of 1 minute if {$response($responseitem) <= 0} { html [neo_make_cookie $responseitem 0 -minutes 1] # if amount is greater than 0, this emits html setting the cookie for the item, with a # lifespan of one day, and adds to cookie array } else { html [neo_make_cookie $responseitem $quantity -days 1] set cookies($responseitem) $quantity } } } } } } # this foreach is a sanity/usefulness check of existing cookies, that goes through # each cookie, and if it's value is 0 or less, it sets the value to zero with a lifespan # of one minute. foreach cookieitem [array names cookies] { if {$cookies($cookieitem) <= 0} { html [neo_make_cookie $cookieitem 0 -minutes 1] unset cookies($cookieitem) } }
Shopping Basket

Shopping Basket Main Page html [backlink "Go Back" " "] Edit Basket

Please review your order and fill out the following shipping information. When finished, use the button at the bottom to send the order, or print the order and send via mail or fax to the address shown.

# table that outputs information from cookie array. html " \n \n \n \n \n \n \n" set subtotal 0 # this foreach goes through each item in the list, checks the cookies array # to see if present, and if so, outputs the appropiate information from the # item array, with the quantity from the cookie. It also multiplies the # quantity by the price to get the line total, and adds the value to the # subtotal variable foreach catalogitem $itemorder { if {[catch {set quantity $cookies($catalogitem)} isthere] == 0} { html " \n \n \n " set subtotal [expr $subtotal + [expr [lindex $item($catalogitem) 0] * $quantity]] } } # this section emits the final part of the result table html " \n \n \n \n \n \n \n \n \n \n \n \n " html "
DescriptionPriceAmt.Item Total
[lindex $item($catalogitem) 1][lindex $item($catalogitem) 2]$[format "%.2f" [lindex $item($catalogitem) 0]] $quantity $[format "%.2f" [expr [lindex $item($catalogitem) 0] * $quantity]]
Sub Total $[format "%.2f" [set subtotal]]
Texas Residents add 8% sales tax
Total
"

Please fill out the following information.
Full Name:
Email (required):
Address 1:
Address 2:
City: State/Province:
ZIP/Postal Code: Country:
Day Phone: Night Phone:

Please fill out your credit card information.
Card Type:
Card Number:
Expiration Date:

Signature:
(For fax/mail orders.)

Some Bogus Company
Some Bogus Address
Houston, TX 77254
Fax (713) 666-6666
Voice (713) 777-7777
Email: bogus@bogus.bogus

To order by fax or phone, print this page with the requested information and send it to us. Orders are usually shipped the following day.

For purposes of testing, enter email address to send form to
html $subtotal>