Volg de onderstaande video om te zien hoe je onze site als web-app op je startscherm installeert.
Opmerking: Deze functie is mogelijk niet beschikbaar in sommige browsers.
<%
product_id = killChars(request.querystring("id"))
total_products = killChars(request.cookies("total_products" & session.SessionID))
quant = killChars(request.querystring("quant"))
if len(quant) = 0 OR not Isnumeric(quant) then
quant = 1
else
quant = cint(quant)
end if
if len(total_products) = 0 then
total_products = 0
else
total_products = cint(total_products)
end if
if IsNumeric(product_id) AND len(product_id) > 0 then
product_id = cint(product_id)
else
response.redirect("cart.asp")
end if
product_isnew = 1
if total_products > 0 then
for x = 1 to total_products
if product_isnew = 0 then exit for
cookie_product_id = cint(request.cookies("product" & x & session.SessionID)("product_id"))
if cookie_product_id = product_id then
product_isnew = 0
end if
product_cookie = x
next
else
product_cookie = 0
end if
if product_isnew = 1 then
product_cookie = product_cookie + 1
total_products = total_products + 1
response.cookies("product" & product_cookie & session.SessionID)("product_id") = product_id
response.cookies("product" & product_cookie & session.SessionID)("product_ordered") = quant
response.cookies("total_products" & session.SessionID) = total_products
else
response.cookies("product" & product_cookie & session.SessionID)("product_ordered") = cint(request.cookies("product" & product_cookie & session.SessionID)("product_ordered")) + quant
end if
response.redirect("cart.asp")
%>
moet je dan niet met een dll werken (ik ken hier dus niks van héSquall-sX- zei:Is het niet makkelijker een object te maken voor je winkelkarretje, en dit in de sessie op te slaan? Je weet trouwens niet of cookies ondersteunt worden op de client.
)Ramm zei:Dit is mijn code:
Als je dit bijvoorbeeld in een bestand cart_add.asp plaatst, dan volstaat de volgende link om een product toe te voegen in de winkelwagen:Code:<% product_id = killChars(request.querystring("id")) total_products = killChars(request.cookies("total_products" & session.SessionID)) quant = killChars(request.querystring("quant")) if len(quant) = 0 OR not Isnumeric(quant) then quant = 1 else quant = cint(quant) end if if len(total_products) = 0 then total_products = 0 else total_products = cint(total_products) end if if IsNumeric(product_id) AND len(product_id) > 0 then product_id = cint(product_id) else response.redirect("cart.asp") end if product_isnew = 1 if total_products > 0 then for x = 1 to total_products if product_isnew = 0 then exit for cookie_product_id = cint(request.cookies("product" & x & session.SessionID)("product_id")) if cookie_product_id = product_id then product_isnew = 0 end if product_cookie = x next else product_cookie = 0 end if if product_isnew = 1 then product_cookie = product_cookie + 1 total_products = total_products + 1 response.cookies("product" & product_cookie & session.SessionID)("product_id") = product_id response.cookies("product" & product_cookie & session.SessionID)("product_ordered") = quant response.cookies("total_products" & session.SessionID) = total_products else response.cookies("product" & product_cookie & session.SessionID)("product_ordered") = cint(request.cookies("product" & product_cookie & session.SessionID)("product_ordered")) + quant end if response.redirect("cart.asp") %>
cart_add.asp?id=1&quant=1
Waarbij het ID het unieke ID is van uw product, en quant de hoeveelheid je wenst toe te voegen (als je niks meegeeft zal hij een standaardwaarde van 1 ingeven).
De waarden worden dan bijgehouden in een cookie die je dan in je cart.asp gemakkelijk kan uitlezen
totaal aantal producten: request.cookies("total_products" & session.sessionID)