Title: Qualifying a loop with first shopping cart

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

Reply via email to