Implement online shopping carts in InterDev

Source: Internet
Author: User
Tags filter array expression implement modify access
InterDev This article will introduce the way to implement the online store shopping cart function in InterDev, the following steps are as follows:

First, the database structure:

Product Data Sheet (Products): Store product Information

Product Name ProductName
Product number ProductID
Price Price
Category number CategoryID

Cart: Cart datasheet, temporary storage of customer orders

Product number ProductID
Product Name ProductName
Price Price
Customer Session Marking SessionID
Order Quantity Quantity

Orders: Order, when the user confirms the order, the order data will be transferred from the CART table to this table

Product number ProductID
Customer Session Number SessionID
Order Quantity Quantity

Customers: Customer, the table will be used when the customer logs in

Second, establish a database connection:

1. Add data Source: In Control Panel select: admin tools/odbc Data Source, click Add, select Database driver for Microsoft Access Driver, click Finish, name the data source "Store" in the pop-up dialog box, click Select, Locate the established. mdb file, and then click OK

2, establish the connection: in InterDev in the project Exlporer in the Select Add Data Connection, select the data source, named Con, the connection after the establishment of all data access will be based on this connection.

Third, the shopping cart to realize the basic function and the corresponding file:

Product Browsing and purchase Products.asp
Put in the shopping cart Addtocart.asp
Browse Shopping Cart Viewcart.asp
Delete a product Deleteitem.asp
Update Shopping Cart Updatecart.asp
Confirm Order Saveorder.asp
Four, products.asp

This page shows all the items in the product category selected by the customer, with a "Add to Cart" button at the back of each item, pointing to Addtocart.asp.

1, add Prodrec control, set record source for Products table.

2, add the grid control, set its data source for Prodrec

3, add "buy this Product" link

Click Add Unbound Column in the grid's property page and enter in header: "Buy this Product", enter in field/expression: = "<a Href=addtocart.asp?" Productid= "+[productid]+" "+" "</A>". The purpose of this statement is to store the product number of the currently selected product in the variable ProductID and pass it to addtocart.asp, which will be added to the shopping cart according to the product number in addtocart.asp.

Five, addtocart.asp

This page provides detailed information about the user's selected item, and the user can modify the order quantity on this page.

1, add a recordset, named Prodrec, set record source for SQL statement, input: SELECT * FROM products. Enter the following code in the <Head> area:


This code is executed before the recordset is opened, filtering the recordset to obtain the user's selected product based on the ProductID parameters passed by products.asp.

2, and then add a recordset, named Cartrec, the recordset's role is to determine whether the selected item is already in the shopping cart based on the user's session number and the selected product number, and if it is already in the shopping cart, extract the record from the cart table, prompting the user that the product has been purchased, And let users change the number of purchases:


3, the code in <Body>:

The product you selected is:
<%=prodrecorset.fields.getvalue ("ProductNAME")%>
<%if incart=true then%>
Your shopping cart already has
<%=QtyinCart%> this item, please update the quantity you purchase:
<%Else%>
Please enter your purchase quantity:
<%end if%>
""
Use a hidden edit box to store the user's selected product number for updatecart.asp use.
""
""
Use three suppressed edit boxes to pass the product number, name, and price to the updatacart.asp.

VI. updatecart.asp

Receive addtocart.asp pass ProdID, ProdName, Prodprice and OrderQty, plus the customer's session number, into the cart table.

1. Add recordset Cartrec, set data source to select * from Cart

2, add code to update data:

{
Newsql= "Select * from Cart";
} Not in the shopping cart, remove all data
Else
{
newsql= "select * from Cart Where sessionid=" +session.sessionid
} Already in the shopping cart, take out the unique data and prepare to modify the data
Cartrec.setsqltext (newsql);

Function Cartrec_ondatasetcomplete () {
if (Request ("Incart") ==0)//If not in the shopping cart, add a new record
{
Fields=new Array (" ProductID "," ProductName "Quantity", "SessionID");
Values=new Array (Request ("ProdID"), Request ("ProdName"), Request ("OrderQty"), Session.SessionID);
Cartrec.addimmeidate (fields,values);
}
else//if already in the shopping cart, update the purchase quantity
{
CartRec.fields.setValue ("Quantity", Request ("OrderQty"));
}
Response.Redirect ("viewcart.asp");


Seven, viewcart.asp

1, add the recordset, named Cartrec, set the data source for select * from Cart

2, add Grid control, set the data source for Cartrec, display three fields: ProductName, Quantity, price. Add two unbounded Column:

1) showing the total price, field/expression: =[quantity]*[price].

2 Edit/Delete button, field/expression: = "/ . The two hyperlinks pass the ProductID to addtocart.asp and deleteitem.asp, respectively.

3, add links to saveorder.asp

confirm order

Viii. deleteitem.asp Deletes a user-selected shopping cart record

1. Add recordset Cartrec, set data source to select * from Cart

2, add code:


Saveorder.asp save temporary data in the shopping cart to order table

1. Add recordset Cartrec, set data source to select * from cart, filter in Onbeforeopen () with select * FROM Cart wher sessionid= Session.SessionID filter the recordset to get all unsaved shopping cart records for the current user

2, add a recordset Orderrec, set the data source for the table order

3, Capture Cartrec ondatasetcomplete () event, enter the code:

function Cartrec_ondatasetcomplete ()
{
while (!cartrec.eof)

Fields=new Array ("ProductID", "SessionID", "Quantity");
Values=new Array (CartRec.fields.getValue ("ProductID"),
CarRec.fields.getValue ("SessionID"),
CarRec.fields.getValue ("Quantity"));
Orderrec.addimediate (fields,values);//Add new record to order table
Cartrec.deleterecord ()//delete a record in the shopping cart
Cartrec.movenext ()//Continue processing the next record

Response.Redirect ("viewcart.asp");
}



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.