Jordan
12-03-2004, 08:56 AM
Hi I'm new to CF and I downloaded a tutorial for a shopping cart.
When a user adds an item to the shopping cart the ItemID is displayed which means nothing to the user. Like I said, I'm really new to this and I can't figure out what exactly to change in the code to get it to display a meaniful title to the user rather than the ItemID.
In the Database ItemID is the Primary key and Album attribute I want to be displayed to the user.
Here is the code:
DisplayCart.cfm
<cfif IsDefined ('Session.Cart')>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="5" bgcolor="#FFFFFF">
<tr>
<td colspan="2"><hr></td>
</tr>
<tr align="center">
<td><strong>Now in your cart:</strong></td>
<td> </td>
</tr>
<tr align="center">
<td width="50%"><strong>
<cfloop from="1" to="#ArrayLen(Session.Cart.ItemID)#" index="ThisItem">
<cfoutput>
ItemID: #Session.Cart.ItemID[ThisItem]# | Quantity: #Session.Cart.Qty[ThisItem]# </cfoutput><br>
</cfloop>
</strong><br>
</td>
<td width="50%">[<a href="Checkout.cfm">Checkout</a>]</td>
</tr>
</table>
<hr>
</cfif>
Cart.cfm
<cfif IsDefined('FORM.Submit')>
<cflock timeout="5" throwontimeout="No" type="EXCLUSIVE" scope="SESSION">
<!--- Check to see if a Cart Session exists, if it dosent create one. --->
<cfif IsDefined('Session.Cart') is "NO">
<cfscript>
Session.Cart=StructNew();
Session.Cart.ItemID=ArrayNew(1);
Session.Cart.Qty=ArrayNew(1);
</cfscript>
</cfif>
</cflock>
<!--- //If Item exists, Update Quantity // --->
<cfif ListFind(ArrayToList(Session.Cart.ItemID),FORM.ItemID) NEQ 0>
<cfset ThisItem=ListFind(ArrayToList(Session.Cart.ItemID),FORM.ItemID)>
<!--- //Set Quantity // --->
<cflock timeout="2" throwontimeout="No" type="EXCLUSIVE" scope="SESSION">
<cfset Session.Cart.Qty[ThisItem]=Session.Cart.Qty[ThisItem] + FORM.Qty>
</cflock>
<cfelse>
<!--- If the Item doesn’t exist in the Cart Session, add it. --->
<cfset ThisItem=ArrayLen(Session.Cart.ItemID) +1 >
<!--- === [ Add to cart ] === // --->
<cflock timeout="5" throwontimeout="No" type="EXCLUSIVE" scope="SESSION">
<cfset Session.Cart.ItemID[ThisItem]=FORM.ItemID>
<cfset Session.Cart.Qty[ThisItem]=FORM.Qty>
</cflock>
</cfif>
</cfif>
Thanks to anyone who can help me!
When a user adds an item to the shopping cart the ItemID is displayed which means nothing to the user. Like I said, I'm really new to this and I can't figure out what exactly to change in the code to get it to display a meaniful title to the user rather than the ItemID.
In the Database ItemID is the Primary key and Album attribute I want to be displayed to the user.
Here is the code:
DisplayCart.cfm
<cfif IsDefined ('Session.Cart')>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="5" bgcolor="#FFFFFF">
<tr>
<td colspan="2"><hr></td>
</tr>
<tr align="center">
<td><strong>Now in your cart:</strong></td>
<td> </td>
</tr>
<tr align="center">
<td width="50%"><strong>
<cfloop from="1" to="#ArrayLen(Session.Cart.ItemID)#" index="ThisItem">
<cfoutput>
ItemID: #Session.Cart.ItemID[ThisItem]# | Quantity: #Session.Cart.Qty[ThisItem]# </cfoutput><br>
</cfloop>
</strong><br>
</td>
<td width="50%">[<a href="Checkout.cfm">Checkout</a>]</td>
</tr>
</table>
<hr>
</cfif>
Cart.cfm
<cfif IsDefined('FORM.Submit')>
<cflock timeout="5" throwontimeout="No" type="EXCLUSIVE" scope="SESSION">
<!--- Check to see if a Cart Session exists, if it dosent create one. --->
<cfif IsDefined('Session.Cart') is "NO">
<cfscript>
Session.Cart=StructNew();
Session.Cart.ItemID=ArrayNew(1);
Session.Cart.Qty=ArrayNew(1);
</cfscript>
</cfif>
</cflock>
<!--- //If Item exists, Update Quantity // --->
<cfif ListFind(ArrayToList(Session.Cart.ItemID),FORM.ItemID) NEQ 0>
<cfset ThisItem=ListFind(ArrayToList(Session.Cart.ItemID),FORM.ItemID)>
<!--- //Set Quantity // --->
<cflock timeout="2" throwontimeout="No" type="EXCLUSIVE" scope="SESSION">
<cfset Session.Cart.Qty[ThisItem]=Session.Cart.Qty[ThisItem] + FORM.Qty>
</cflock>
<cfelse>
<!--- If the Item doesn’t exist in the Cart Session, add it. --->
<cfset ThisItem=ArrayLen(Session.Cart.ItemID) +1 >
<!--- === [ Add to cart ] === // --->
<cflock timeout="5" throwontimeout="No" type="EXCLUSIVE" scope="SESSION">
<cfset Session.Cart.ItemID[ThisItem]=FORM.ItemID>
<cfset Session.Cart.Qty[ThisItem]=FORM.Qty>
</cflock>
</cfif>
</cfif>
Thanks to anyone who can help me!



