PDA

View Full Version : pseudo add to cart with coldfusion



mat
10-06-2002, 12:06 PM
On a result page i have listing the matching 'albums' it basically outputs a few things for each result (each matching album)

-Artist
-Album
-Price
-link to detail page
-add to cart link


this is a fake little project just for learning and the add to cart button does not yet do anything but i would like it to.

How can i make it so that when that 'add to cart' link is clicked a session / cookie is set containing that particular albumname or albumid.

Then later after you when you go to the fake checkout page the albums you previously 'added to cart' are listed.

:confused:


It is after all just fake and for playing with, i figure there is a simple way to do it right?

on the checkout page all i have to do is something like:

SELECT albumName artistName etc
FROM tables
WHERE albumID = '#session.albumid#' ?


the question here is wether i use a session (dont know much about it) and how to get it to set the session when i click add to cart?

raf
10-07-2002, 01:29 PM
i'm not sure i completely undersand your problem.

i think it comes down to this : you want to store some data (an ID for the selected albums) somewhere, without writing it to a database + you want to retrieve the ID and use them as selectioncriteria to build the checkoutpage.

How to do it depends on your app, the used language, servercapacity, etc.

I use a lot of ASP lately, and I would store the ID's in session-variables.

How ?
- create/modify your global.asa (each time a user starts the application, a session for this user is created and space is reserved for the session-variables. )
- create/modify your session_on start sub like this
Sub Session_OnStart

session("albumID")=0

-when an album is selected, post the form to an ASP page where you store the ID in the sessionvariables like this

session("albumID")=request.form("albumID")

- to retrieve the ifno and use it in a selectquery:

sql="SELECT albumName artistName etc FROM tables WHERE albumID = anID"
sql=replace(sql,"anID",session("albumID")


If the user needs to be aible to order more then one album, you can use a string variable and create a 'comma separated string' by adding the ID's each time an album was chosen (+ create an array with it and then use a loop for the select-querys)

Or you could use multiple session-variables (ad them to the global.asa)

session("numberordered")=0
session("albumID1")=0
session("albumID2")=0
session("albumID3")=0
session("albumID4")=0
session("albumID5")=0
session("albumID6")=0

and store each ID in a new variable + keep track of the numer of albums ordered (to know witch session-variable to use to write the next album ID. probably best with a "select case" structure.)

Does this makes any sense to you ?

mat
10-08-2002, 10:09 PM
what is 'global.asa' ? is it a asp file or something? sort of like coldfusions application.cfm for specifying global app settings and variables.

well i think it makes sense :) but i am still a bit of a newbie especially to CF so i don't fully understand. you are correct in terms of understanding what i'm trying to do though. perhaps i'll take it one bit at a time starting with the application file settings (i'm assumung that's what you mean by 'global.asa')

/ goes off to read up on CF application / session variable syntax

raf
10-09-2002, 08:20 AM
mat,

you'll find more info about the global.asa at the folliwing adresses:

http://www.w3schools.com/asp/asp_globalasa.asp
http://www.asp101.com/resources/apps_sessions_gasa.asp
http://www.haneng.com/Lessons_19.asp

or

http://search.megaspider.com/XP.html?global.asa+help

for some other sites my search engine came up with

whammy
10-15-2002, 02:32 AM
It sounds like he's using ColdFusion (not ASP), but it also sounds like he's on the right track. ;)

CFMX RULES
04-08-2003, 11:30 PM
<cfset session.YourVariable = YourValue>

thats it

But if your not using cfmx lock your session vars !! <cflock>