Design shopping cart with ASP

Source: Internet
Author: User
Tags vbscript class

What is a shopping cart?
You must have been to the supermarket. There you can push the cart, put your favorite items in the cart, or take the items in the cart out and put them on the shelf again, and finally you can push the cart to checkout.
Therefore, in online supermarkets, customers should also be able to put their favorite products into the "E-carts" When browsing the product catalog ". E-carts are electronic supermarkets. In online stores, this kind of electronic cart is also called "Shopping Cart.
Design objectives of shopping carts
Slave Program From the personnel's point of view, a shopping cart is an object that allows shoppers to purchase, view, and modify commodities. The shopping cart itself is a very simple program, but developers should consider connecting it to the product catalog subsystem, order subsystem, customer account subsystem, site management subsystem, and so on, to form a complete online store.
The following are the design objectives of the shopping cart:
1. Continuity: the shopping cart should remember its content from its previous session.
2. shopping carts are related to customers rather than customers' computers. Customers can access carts from other computers or browsers.
3. When a new item is added to or removed from the cart, the content of the cart can be displayed to the user.
4. carts can accommodate many or even unlimited items.
System design/Process Design
Before writing our shopping cart, let's take a look at its system architecture and processes.

If the customer selects a product from the product catalog, then we will pass the customer's request to proxy. asp and the Action variable "add product ". Proxy. asp reads this variable and determines which action the cart performs. These actions include: Increase the number of items, update the number of items, remove the items, or view the shopping carts.
Some actions are called internally. For example, before creating a cart, we need to check whether the cart already exists (checkcart ). When adding, removing, or updating a commodity and its quantity, we need to confirm whether it already exists in our cart (checkitem ). Below we will design eight methods for shopping carts:
Viewitem view stroller
Checkcart check cart
Createcart
Additem (ID, qty)
Removeitem (ID) delete item
Updateitem (ID, qty), update quantity
Removeall clear all
Checkitem (ID) item check

Design of shopping cart
The shopping cart requires three elements: a class cartkit of VBScript 5, a multi-dimensional array mudcart, and a session variable SESSION ("cart ").
This VBScript class is called cartkit and contains eight methods, as shown in the table above. In this article, we only use ID and qty to indicate the product number and quantity respectively.
In this way, we can use a two-dimensional array to express the cart, as shown below:
Item No. Number of items
ID-1 23
ID-3 10
ID-23 6
ID-2 1
Then we can save the two-dimensional array to the session variable.
Design of cartkit for shopping carts
Download: cartkit. asp
Createcart design:
See the program Code :
Class cartkit REM start class cartkit Definition
Sub createcart ()
If isarray (Session ("cart") = false then
Dim mudcart (19,1)
Session ("cart") = mudcart
End if
End sub
Session ("cart") stores the content of the cart. If the cart does not exist, we define a two-dimensional array mudcart to express the cart and save it to session ("cart.
Checkcart design:
This function checks whether cart has been created. Relatively simple.
Function checkcart ()
If isarray (Session ("cart") then
Checkcart = true
Else
Checkcart = false
End if
End Function
Checkitem design:
See the Code:
Function checkitem (ID)
If checkcart = true then
Varmudcart = SESSION ("cart ")
For I = lbound (varmudcart) to ubound (varmudcart)
If varmudcart (I, 0) = ID then
Checkitem = true
Exit Function
Elseif varmudcart (I, 0) <> ID then
Checkitem = false
End if
Next
End if
End Function
First, determine whether the cart exists. Then compare the product ID with the product ID in the cart. Returns true if there are equal values. Otherwise, it is false.
Additem (ID, qty) Design:
See the appendix cartkit. asp in this article. The functions described here are encapsulated into a class named cartkit. The following code snippet first creates a cartkit object and then checks whether the cartkit already exists. If the product does not exist, create a cart and add a product. Otherwise, check whether the product number already exists in the cart. If yes, the quantity is updated. Otherwise, the product is added.

function additem (ID, qty)
set cartobj = new cartkit
varcartstatus = cartobj. checkcart
If varcartstatus = false then
cartobj. createcart
mudcart = SESSION ("cart")
mudcart (0, 0) = ID
mudcart (0, 1) = qty
SESSION ("cart ") = mudcart
exit function
elseif varcartstatus = true then
If cartobj. checkitem (ID) = true then
cartobj. updateitem ID, qty
elseif cartobj. checkitem (ID) = false then
mudcart = SESSION ("cart")
for I = lbound (mudcart) to ubound (mudcart)
If mudcart (I, 0) = "" Then
mudcart (I, 0) = ID
mudcart (I, 1) = qty
SESSION ("cart ") = mudcart
exit function
end if
next
end if
end function
updateitem design:
function updateitem (ID, qty)
mudcart = SESSION ("cart")

for I = lbound (mudcart) to ubound (mudcart)
If mudcart (I, 0) = ID then
mudcart (I, 1) = qty
SESSION ("cart") = mudcart
exit function
end if
next
end function
viewitem design:
function viewitem ()
mudcart = SESSION ("cart")
If isarray (mudcart) Then
%>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.