Jim:

Thanks for responding (and thank you to all who responded).

I appreciate the pointer on CFLock timeouts. Also I like the more simplified
code.

I've implemented a version of your simplified code.  The only thing I had to
do different than you was retain the conditional with the CFElse for whether
it's a new cart or not.  I was getting an error without the either/or
option.

I was hopeful that changing 

session.cartItem= "etc"

to

session.cart="etc" 

would fix my problem.

But I get an error if I do that.

For example:

An error occurred while evaluating the expression: 
  FindItem.RecordCount+1 IS ArrayLen(session.cart)
Error near line 90, column 30.
Parameter 1 of function ArrayLen which is now "YES" must be an indexed
object such as an array or a query column


That line part of a conditional that makes sure duplicate items are not
added to the shopping cart if user hits the reload/refresh button.

If you want to see my code in working action, go to
http://recordoutlet.com.onemerchant.com/  This is a site still under
development, but the shopping cart works (it's not the site that I'm
currently having trouble with).  I initially developed this shopping cart
code for this site and the copied it pretty much verbatim (except for
changing variable names) for the newer site I'm working on.

H.



Howard Owens
Internet Operations Coordinator
www.insidevc.com
[EMAIL PROTECTED]
AIM: GoCatGo1956


> -----Original Message-----
> From: Jim McAtee [SMTP:[EMAIL PROTECTED]]
> Sent: Wednesday, December 26, 2001 5:22 PM
> To:   CF-Talk
> Subject:      Re: Pulling My Hair Out (a shopping cart question)
> 
> ----- Original Message -----
> From: "Owens, Howard" <[EMAIL PROTECTED]>
> To: "CF-Talk" <[EMAIL PROTECTED]>
> Sent: Wednesday, December 26, 2001 5:36 PM
> Subject: Pulling My Hair Out (a shopping cart question)
> 
> 
> > <cflock timeout="#createtimespan(0,0,30,0)#"
> > name="#session.sessionID#"
> >         type="EXCLUSIVE">
> 
> A cflock timeout value is specified in seconds.  Using CreateTimeSpan()
> with
> 30 minutes gives you a CF date/time object of 1/48th, or 0.625.  Just
> specify a whole number of seconds.  I've never really seen a guide to
> determining intelligent cflock timeout values, so I just use something
> like
> 5 or 10 seconds.
> 
> > session.cart = ArrayNew(1);
> > session.item = StructNew();
> > session.item.PRODUCT_ID = 0;
> > session.item.NAME = "#FindItem.SONG_TITLE#";
> > session.item.DESCRIPTION = "#FindItem.ARTIST_FIRST_NAME#
> > #FindItem.ARTIST_LAST_NAME#";
> > session.item.QUANTITY = 1;
> > session.item.PRICE = "#request.songprice#";
> > session.item.ITEMTOTAL = "3";
> > session.item.SONG_ID = "#FindItem.SONG_ID#";
> 
> In this block of code, session.item is just used as a temporary variable,
> so
> create it in the variables (or the request) scope.  As a rule, you should
> minimize the amount of code encapsulated by a cflock, so this would help
> toward that goal, since you can create and define the struct outside of
> the
> lock.
> 
> >
> > session.CartItems = ArrayAppend(session.cart, session.item);
> >
> 
> Could this be the source of the problems you're having?  Did you mean to
> do
> this, or do you mean:
> 
> session.cart = ArrayAppend(session.cart, session.item);
> 
> 
> Simplified, the code becomes something like:
> 
> <cfscript>
> item = StructNew();
> item.PRODUCT_ID = 0;
> item.NAME = "#FindItem.SONG_TITLE#";
> item.DESCRIPTION = "#FindItem.ARTIST_FIRST_NAME#
> #FindItem.ARTIST_LAST_NAME#";
> item.QUANTITY = 1;
> item.PRICE = "#request.songprice#";
> item.ITEMTOTAL = "3";
> item.SONG_ID = "#FindItem.SONG_ID#";
> </cfscript>
> 
> <cflock name="#session.sessionID#" type="EXCLUSIVE" timeout="5">
>   <!--- If no shopping cart exists, create one --->
>   <cfparam name="session.newcart" default="no">
>   <cfif session.newcart is "no">
>     <cfset session.cart = ArrayNew(1)>
>     <cfset session.newcart = "yes">
>   </cfif>
>   <!--- Add item to the cart --->
>   <cfset session.cart = ArrayAppend(session.cart, item)>
> </cflock>
> 
> 
> Jim
> 
______________________________________________________________________
Get Your Own Dedicated Windows 2000 Server
  PIII 800 / 256 MB RAM / 40 GB HD / 20 GB MO/XFER
  Instant Activation � $99/Month � Free Setup
  http://www.pennyhost.com/redirect.cfm?adcode=coldfusionb
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to