(ASP)Code giỏ hàng PDF. In Email
Xem kết quả: / 15
Bình thườngTuyệt vời 
Bài viết này được đóng góp từ bạn Mạnh Tuấn. Đây là code  giỏ hàng (ASP), tuy chưa hoàn thiện nhưng có thể sẽ là tài liệu cho các bạn mới tiếp xúc với website TMDT.

Vua code duoc cai gio hang suong qua share cho moi nguoi xem va cung gop vai cho  nha
Dau tien la include cua shoppingcar : de shoppingcart su dung ma thuc hien cac cau lenh

File: include-shoppingcart:




<!--#include file="connections/config.asp"-->
<%
openconn
Public Sub themsp(pid)

   strList=Session("ProductList")
   countList=Session("ProductCount")
   if (trim (pid)<>"") then
         if (instr(strList,pid)=0)  then'neu khong co ma san pham trong list thi them
            strList=strList+pid+","
                Session("ProductList")=strList
                CountList=CountList+"1"+","
                Session("ProductCount")=CountList
         else  'co san pham do trong gio hang roi
                        arrProducts=split(Session("ProductList"),",")
                        arrCounts=split(Session("ProductCount"),",")
                For i = 0 to uBound(arrProducts)
                         if (inStr(arrProducts(i),pid))>0 and flag=false then 'lam sao de refresh k bi tang
                           arrCounts(i)=CStr(Cint(arrCounts(i))+1)
                               flag=true
                exit for
                        end if
                       Next
                         session("ProductList")=join(arrProducts,",")
                         session("ProductCount")=join(arrCounts,",")
       end if
end if
end sub

public Sub xoasp(pid)
   strList=Session("ProductList")
   countList=Session("ProductCount")

   if trim(pid)<>"" then
      if inStr(strList,pid)=0 then
          exit sub
      else

         arrProducts=split(session("ProductList"),",")
         arrCounts=split(session("ProductCount"),",")

         For i=0 To uBound(arrProducts)
                   If inStr(arrProducts(i),pid)>0 Then
                       arrCounts(i)="0"
           arrProducts(i)="0"
           Exit For
                   End If
              Next

         session("ProductList")=join(arrProducts,",")
         session("ProductCount")=join(arrCounts,",")

         'Loai bo cac product co so luong 0
         session("ProductList")=Replace(session("ProductList"), "0,", "")
         session("ProductCount")=Replace(session("ProductCount"), "0,", "")


      end if

   end if

end Sub


Public Sub xoatatca
  session("ProductList")=""
  session("ProductCount")=""
end Sub

Sub UpdateQuantity(pid,Qty)
  arrProducts=split(session("ProductList"),",")
  arrCounts=split(session("ProductCount"),",")
  For j = 0 to UBound(arrProducts)
   if inStr(arrProducts(j),pid)>0 then
                 arrCounts(j)=trim(Cstr(Qty))
         exit for
       end if
       Next
         session("ProductList")=join(arrProducts,",")
         session("ProductCount")=join( arrCounts,",")

       End Sub
closeconn
%>


con day la code cua shoppingcart



<!--#include file="include-shoppingcart.asp"-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="/css-pro1.css" media="all" rel="stylesheet" type="text/css" />
<link href="/Picture 037.png" rel="stylesheet" media="all" />
<style type="text/css" media="all">
#a:hover{
text-decoration:underline}
</style>
<title>Untitled Document</title>
</head>
<body>

<%
openconn
id = request.querystring("id")
action=request.querystring("action")
if action="add" then
       themsp id

end if
if action="update" then
 str_qty=request.form("Qty")
 Qty_arr=split(str_qty,",")
 str_id=Session("ProductList")
 id_arr=split(str_id,",")
 for i=0 to ubound(Qty_arr)
         UpdateQuantity id_arr(i),Qty_arr(i)
 Next
       strList=session("ProductList")
       strList=Left(strList,(len(strList)-1))
       strListArray=split(strList,",")

       countList=session("ProductCount")
       countListArray=split(countList,",")
end if

if(action="xoasp") then
       xoasp id
end if

if(action="xoatatca") then
       RemoveAll
end if
%>

<form name="form1" method="post"    action="shoppingcart.asp?action=update">
  <table width="100%" border="1" cellpadding="1" cellspacing="0">
  <tr style=" height:50px"><td>GIO HANG</td></tr>
  </table>
 <table width="100%" border="1" cellpadding="1" cellspacing="0">
   <tr align="center" class="tr2">
     <td>STT</td>
     <td>TEN SAN PHAM</td>
     <td>DON GIA</td>
     <td>SO LUONG</td>
     <td>THANH TIEN (VND) </td>
     <td> </td>

   </tr>
<%
dim rs
set rs=server.CreateObject("adodb.recordset")
if (session("ProductList")="") then
       response.write("<tr><td colspan=6>Ban chua dat mua mat hang nao</td></tr></table>")%>
       <br><a href="/phantrang1.asp">Tiep tuc mua hang</a>
<%
else
       strList=session("ProductList")
       strList=left(strList,len(strList)-1)
       strListArray=split(strList,",")

       countList=session("ProductCount")
       countListArray=split(countList,",")
       set rs=server.CreateObject("ADODB.RecordSet")
       totalPrice=0

       for i=0 to ubound(strListArray)
               rs.open "select * from sanpham where Madongho='"&strListArray(i)&"'",conn
               %>
                       <tr>
                       <td><%=i+1%></td>
                       <td><%=rs("Tendongho")%></td>
                       <td><%=rs("Gia")%></td>
                       <td><input type="text" name="Qty" value="<%=countListArray(i)%>" size="10" /></td>
                       <td><%=(Cint(countListArray(i))*rs("Gia"))%></td>
                       <td id="a"><a href="/shoppingcart.asp?id=<%=strListArray(i)%>&action=xoasp">Xoa</a></td>
                       </tr>

               <%

                       totalPrice=totalPrice+Cint(countListArray(i))*rs("Gia")
                       rs.close
       next
       %>
       <tr>
                 <td colspan="4">Tong tien (VND): </td>
                 <td><%=totalPrice%></td>
                 <td> </td>
               </tr>
       <tr>
         <td colspan="6">Co <strong><%=ubound(strListArray)+1%></strong> san pham trong gio hang cua ban!</td>
         </tr>
       <tr>
                 <td colspan="7" align="center">
                 <input type="submit" name="submit" value="Cap nhat gio hang"/>
                 <input type="button" value="Xoa gio hang" onclick='window.location="shoppingcart.asp?action=removeAll"'/>
                 <input type="button" value="Dat hang" onclick='window.location="Dathang.asp"'/>
                 <input type="button" value="Tiep tuc mua hang" onclick='window.location="phantrang_product.asp"'/>
                 </td>
       </tr>
         </table>
       </form>
       <%
end if
%>

</div>
</div>

</div>

</body>
</html>


Cảm ơn bạn Mạnh Tuấn

Các bài viết khác
Trả lời RSS
trì vân   |222.254.235.xxx |26-06-2009 07:22:21
umh...code kủa bạn cũng hay hay đấy!!!
both  - GOD is Love     |123.26.25.xxx |08-07-2009 01:45:58
ec.. bạn oi`, code nay` coa' 1 file config.asp & include-shoppingcart.asp la` gj` vay ban ???
both     |123.26.25.xxx |08-07-2009 01:48:53
no' co'a pai~ la` de~ lay' Data hok ban
Trịnh Thu Hoài  - re:   |123.18.30.xxx |08-07-2009 03:45:43
both wrote:
no' co'a pai~ la` de~ lay' Data hok ban

File config là file kết nối CSDL.
Còn file shoppingcart có nhúng thêm file include-shoppingcart.asp là file ở trên đó bạn. File này dùng để sử lý dữ liệu.
Vậy heng!
Both  - Thanks   |123.26.94.xxx |14-07-2009 03:58:18
Okey! thanks nhiu` nhen pan.!!
Shot  - Thanks   |123.26.205.xxx |26-07-2009 17:57:13
ban co the gui len noi dung trang hien thi san pham co nut "add to cart" duoc k0?
Nguyễn Yến  - Add to cart thì thế nào vậy bạn ?     |123.17.154.xxx |28-07-2009 18:09:31
Add to cart thì thế nào vậy bạn ? Link sang như thế này có đúng ko ?

Thêm vào giỏ hàng
Mai Trang  - re: Add to cart thì thế nào vậy bạn ?   |123.26.250.xxx |28-07-2009 22:39:02
Nguyễn Yến wrote:
Add to cart thì thế nào vậy bạn ? Link sang như thế này có đúng ko ?

Thêm vào giỏ hàng

Bạn ơi. Toàn bộ code của bạn đã bị hệ thống tự động loại bỏ vì được coi là code không hợp lệ.
Để khắc phục, bạn hãy đưa code của bạn vào thẻ \"[code ][ /code]\".
WestCoast  - anyone just show me code plz ?   |123.26.192.xxx |01-08-2009 16:35:05
link sang nhu the nao ha ban, minh dung form hay a href gui sang mai ma k0 duoc
Mạnh Hùng  - re: anyone just show me code plz ?   |118.70.119.xxx |01-08-2009 17:20:44
Ba
WestCoast wrote:
link sang nhu the nao ha ban, minh dung form hay a href gui sang mai ma k0 duoc

Bạn có thấy trang shoppingcart không? Khi bạn mua hàng, bạn bấm nút Mua Hàng thì bạn sẽ gửi các tham số như: id sản phẩm, số lượng, giá sang trang này. Trang shoppingcart sẽ nhận các tham số đó và tính toán.
WestCoast  - thanks but still wondering   |123.26.206.xxx |03-08-2009 02:00:15
Cám ơn, mình tạo được giỏ hàng rồi nhưng khi 1 sản phẩm đã có trong giỏ hàng rồi mà mình add tiếp sản phẩm đó vào giỏ hàng mà số lượng của nó không tăng lên 1
nam   |123.27.228.xxx |04-08-2009 05:32:13
Cho mình hỏi link dẫn mặt hàng vào giot hàng thế nào?
WestCoast   |123.26.216.xxx |05-08-2009 01:32:43
Bạn thêm dòng link sau vào cạnh sản phẩm
Code:

add to cart

-Nhưng nếu trường p_id trong csdl của bạn là kiểu autonumber thì trong file shoppingcart.asp > sửa lại chỗ sau:
Code:
  rs.open "select * from sanpham where Madongho="&strListArray(i),conn
213   |123.26.221.xxx |06-08-2009 15:31:47
Bạn ơi sửa như thế nào để add 1 sản phẩm đã có sẵn trong giỏ hàng thì số lượng của nó tăng lên 1
CHIP  - re:   |123.26.250.xxx |06-08-2009 16:46:14
213 wrote:
Bạn ơi sửa như thế nào để add 1 sản phẩm đã có sẵn trong giỏ hàng thì số lượng của nó tăng lên 1

Bạn có thể tham khảo bài viết của mình. Đơn giản thôi, nhưng chắc bạn có thể dựa vào để phát triển một giỏ hàng cho mình.
Tham khảo tại đây: http://hotrolaptrinh.com/share-code--project/60-asp/254-asp-code-gi-hang-n-gin
Bài viết của bạn
Name:
Email:
 
Website:
Title:
UBBCode:
<strong> <em> <span style="text-decoration:underline;"> <a target=' /> [quote] [code] <img /> 
 
:angry::0:confused::cheer:B):evil::silly::dry::lol::kiss:
:D:pinch::(:shock::X:side::):P:unsure::woohoo:
:huh::whistle:;):s:!::?::idea::arrow:
Vui lòng nhập vào mã số an toàn.
http://hotrolaptrinh.com

3.26 Copyright (C) 2008 Compojoom.com / Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved."

 
Copyright © 2009 Cộng đồng Hỗ Trợ Lập Trình.

Administrator: Đỗ Ngọc Hải & Phan Văn Vương

Validated by HTML Validator (based on Tidy)
Điều khoản sử dụng       Khước từ trách nhiệm