I did my shopping basket using a combination of request scope variables and client variables.


<!--- Add this item to the basket --->
<CFSCRIPT>
index = ArrayLen(request.session["#request.appname#-#request.cartid#"]["basket"]) + 1;
ArrayAppend(request.session["#request.appname#-#request.cartid#"]["basket"],StructNew());
StructInsert(request.session["#request.appname#-#request.cartid#"]["basket"][index],"itemid",qryitem.itemid);
StructInsert(request.session["#request.appname#-#request.cartid#"]["basket"][index],"itemcode",qryitem.itemcode);
StructInsert(request.session["#request.appname#-#request.cartid#"]["basket"][index],"qty",Attributes.qty);
StructInsert(request.session["#request.appname#-#request.cartid#"]["basket"][index],"itemname",qryitem.itemname);
StructInsert(request.session["#request.appname#-#request.cartid#"]["basket"][index],"price",Trim(newprice));
StructInsert(request.session["#request.appname#-#request.cartid#"]["basket"][index],"weight",qryitem.weight);
StructInsert(request.session["#request.appname#-#request.cartid#"]["basket"][index],"discounted",qryitem.discounted);
StructInsert(request.session["#request.appname#-#request.cartid#"]["basket"][index],"modifiers",modifierstr);
StructInsert(request.session["#request.appname#-#request.cartid#"]["basket"][index],"nontaxstates",ValueList(qrynontaxstates.state));
StructInsert(request.session["#request.appname#-#request.cartid#"]["basket"][index],"categoryid",qryitem.categoryid);
</CFSCRIPT>

Then in OnRequestEnd.cfm I put:
<CFWDDX ACTION="" INPUT="#request.session#" OUTPUT="Client.sessionpkt">


And in Application.cfm I have:
<CFIF Not IsDefined("Client.sessionpkt") OR DateDiff("s", Client.Lastvisit, Now()) GT 86400>
    <CFSET request.session = StructNew()>
<CFELSE>
    <!--- else a packet does exist, we just need to de-serialize the session out of it
    (into the request scope so even custom tags can access if they need to ) --->
    <CFWDDX ACTION="" INPUT="#Client.sessionpkt#" OUTPUT="request.session">
</CFIF>


Works good for us.


-Ryan

-----Original Message-----
From: Paul Black [mailto:[EMAIL PROTECTED]
Sent: Saturday, October 18, 2003 7:19 PM
To: CF-Linux
Subject: Improving My Shopping Basket

I have been using a fairly simple shopping basket which is created as
follows:

<cfif not isDefined("session.basket")>
        <cfset session.basket = queryNew("product_id, cost, gst,
quantity, saleDate")>

It has worked well for my first couple of customers until I come across
a customer who sells candles, candles have a product id and a colour, so
now I've added colour and my shopping basket looks like:

<cfif not isDefined("session.basket")>
        <cfset session.basket = queryNew("product_id, cost, gst,
quantity, saleDate, colour")>

On the page that shows what has been purchased,  I need to see a
summary,  something like,

5 large candles red       $5
7 large candles green   $7

The code that adds the purchases to the shopping basket only checks
product id not product id and colour, using the listFind function.  Is
there any way I can make listFind check for a product id and a colour?

I dont think that there is a way to make the listFind code check for a
specific productId and a specific colour, so perhaps  I will have to
recode to make my shopping basket a SQL table, then i will be able to do
nice relational queries, may be a bit of work in recoding, but i will do
it if i have to.

If I add a MySQL table called basket. This new basket table would
contain product_id, cost, gst, quantity, saleDate, colour, pluss
sessionId. Now I can use Session.SessionID to set the sessionId in my
new basket table. Next I'm wondering how I can handle the case where the
customer puts a few products into the shopping cart and then times out.
How can I detect the timeout and remove the selected items from the
basket table?

Trying to think this issue through, I wonder if I'm not reinventing the
wheel with my proposed basket table??

I'd be very happy to hear from the good people on the list about what is
the best way to approach this problem.

Cheers.   Paul

  _____  


[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

Reply via email to