Oh goodie, word problems. :)

First, you can remove the " and # from these lines

<cfif "#session.cart[i][1]#" eq "#url.id#" and ...>

Within a CF tag, you only need # inside of quotes, and in this case, you
don't need quotes, so this should be good:

<cfif session.cart[i][1] eq url.id>

Beyond that, you're missing a <cfelse> statement between the 2 loops at the
bottom, and are probably better off with only one loop... for instance:

Put this in your application.cfm

<cflock scope="session" type="exclusive" timeout="30">
<cfparam name="session.cart" type="struct" default="#structnew()#"></cflock>

Then make your loop like this:

<cfset exists = false>
<cfloop item="i" collection="#session.cart#">
        <cfif session.cart[i][1] = url.id>
        <cfset exists = true><cfbreak></cfif>
</cfloop>
<cfif not exists><cfinclude template="addbutton.cfm"></cfif>

If you were using a query to store the shopping cart data ( you can create
them manually with the query functions in CF ) it would be even easier to do
this:

<cfif not ListFind(valuelist(session.cart.id),url.id)>
<cfinclude template="addbutton.cfm"></cfif>

I believe there's an arrayofstucturestoquery() or structureofarraystoquery()
function on www.cflib.org, however, it's probably expecting the reverse of
what you have here apparently where the cart would be an array and each item
in the cart is a structure. Which would probably also be more intuitive (and
self-documenting) since you'd be able to use something like
#session.cart[x].quantity# instead of #session.cart[x][4]#

Remember if you're using CF 5 you need to lock those session vars.

hth


s. isaac dealey                954-776-0046

new epoch                      http://www.turnkey.to

lead architect, tapestry cms   http://products.turnkey.to

tapestry api is opensource     http://www.turnkey.to/tapi

certified advanced coldfusion 5 developer
http://www.macromedia.com/v1/handlers/index.cfm?ID=21816


> I am building a shopping cart for the first time and using
> a session to
> manage the contents.

> The structure of the items in the cart array are 1.  id -
> 2.  name - 3.
> price 4.  quantity

> The catch is that unlike most carts you can only add an
> item once to
> your cart. Multiple quantities of any item are not
> allowed.

> The item detail page presents an add cart button or does
> not based on
> several things.

> But what I get is is a loop that presents the number of
> items in the
> current cart being presented. So if there are two items in
> the cart and
> one id matches the URL ID I get ITEM Exists but I also get
> an addbutton?
> See code below.

> <!--- 1. The session does not exist the button is
> presented.  --->
> <cfif not isdefined("session.cart")>
>       <cfinclude template="addButton.cfm">

> <cfelseif isdefined("session.cart")>
> <!--- 2. The session exists and an item in the loop exists
> that matches
> the ID of the ITEM thus hiding the button. --->
>       <cfloop collection="#session.cart#" item="i">
>               <cfif "#session.cart[i][1]#" eq "#url.id#" and
> "#session.cart[i][4]#" eq "1">
>               <tr><td>Item exists</td></tr>
>               </cfif>
>       </cfloop>
> <!--- 3. The session exists but the items in the loop do
> match the ID in
> the URL. --->
>       <cfloop collection="#session.cart#" item="i">
>               <cfif "#session.cart[i][1]#" neq "#url.id#">
>               <cfinclude template="addButton.cfm">
>               </cfif>
>       </cfloop>
> </cfif>



> Thanks for any help
> Monte Masters




-----------------------------------------------
To post, send email to [EMAIL PROTECTED]
To unsubscribe: 
   Send UNSUBSCRIBE to [EMAIL PROTECTED]
To subscribe / unsubscribe: http://www.dfwcfug.org

Reply via email to