In E-commerce to achieve the method of shopping cart!! Reproduced

Source: Internet
Author: User
Tags setcookie
Realization
of trolley "function

"Trolley" is an important feature in the online shopping website (retail). This paper will explore the use of ASP program to achieve the "trolley" function skills. There are several ways to implement a "trolley" feature on a Web site, such as cookies, sessions, or hidden frames. Each of these methods has its advantages and disadvantages, and it focuses on using cookies to implement the "trolley" function.


use cookies to realize the advantages and disadvantages of the "trolley" function

The
cookie is stored on the client computer via a server-side CGI, script, or client script to make it easier for the server or client to use the information again. There are some functions in JavaScript that are specifically used to manipulate cookies, such as Setcookie (Name,value) that set the cookie value, Deletecookie (name) of the cookie, and so on (see source code). The advantage of using cookies to store "trolley" information is that even when a user accidentally closes the browser window, the information in the "cart" is not lost and it takes up very little server-side resources, and the disadvantage is that the client browser must be required to support cookies and open it.


"Trolley" contains functional subkeys


1. Add the product to the "trolley", which is to order.


2. Delete the ordered goods from the "trolley".


3. Modify the quantity of a product in a "trolley".


4. Empty the "trolley".


5. Display, Statistics "trolley" in the merchandise.


Add a product to the "trolley"


is very simple, that is, the information of a product (name, price, quantity, discount, etc.) to write to the cookie. There is no need to write all the information about the product to a cookie, just write down the number or ID of the item in the database (here with CATID) and the number of items. When the "trolley" information is displayed, all specific information about the product can be queried from the commodity database according to CATID. The following methods are implemented to add items to the "trolley":


function Addcat (catid,number) {//Add the product to the "cart" function


if (number<=0) Deletecookie (″mycat″+catid); If the quantity of the product is less than or equal to 0, delete the product


Else Setcookie (″mycat″+catid,catid+″,″+number); Write the Product ID and quantity to the cookie


var cat=window.open (″showcat.asp″,″cat″,″toolbar=no,menubar=no,location=no,status=no,width=420,height=280″) ; Opens a new window to display the statistic merchandise information, namely displays "The Trolley"}


the product
from the "cart"

is to delete the product information in the cookie, call Deletecat (CATID).


function Deletecat (CATID) {


Deletecookie (″mycat″+catid); Remove
from cookies

var cat=window.open (″showcat.asp″,″cat″,″toolbar=no,menubar=no,location=no,status=no,width=420,height=280″) ; Display the statistical merchandise information in the Cat window, that is, refresh the display "cart"}


Related Article

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.