Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with shopping cart

Status
Not open for further replies.

shawntbanks

Programmer
Oct 29, 2003
48
CA
Looking for some help. When I use this code to add to a shopping cart, the first item goes fine, but when I go to add a second and third, the first one and the second disappear. I am puzzled. Any body got a suggestion



<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;>

<html>
<head>
<title>View Shopping Cart</title>
<cfquery name=&quot;get_SubCategories&quot; datasource=&quot;Market&quot;>
SELECT Category, categoryid, subcategory, subcategoryid
FROM subandcat
</cfquery>
<cfparam name=&quot;form.select_Ad_Subcategory&quot; default=&quot;1&quot;>
<cfquery name=&quot;Fees&quot; datasource=&quot;market&quot;>
select *
from Private_Prices
Where category_ID = #form.select_Ad_Subcategory#
</cfquery>
<cfquery name=&quot;GST&quot; datasource=&quot;market&quot;>
select *
from taxes
Where tax = 'gst'
</cfquery>
<cfquery name=&quot;PST&quot; datasource=&quot;market&quot;>
select *
from taxes
Where tax = 'pst'
</cfquery>
<cfset WF = 5>
<cfset MF = 10>
<cfinclude template=&quot;../Templates/Header_&_Sidebar_for_Place_Ad_Folder_Subcat_Select.cfm&quot;>
<td width=&quot;600&quot; rowspan=&quot;2&quot; valign=&quot;top&quot; bgcolor=&quot;#FFFFFF&quot;>
<table align=&quot;center&quot;>
<!--- did the user get here from the ad confirmation page? --->
<CFIF IsDefined(&quot;FORM&quot;) AND IsStruct(FORM) AND NOT StructIsEmpty(FORM) AND IsDefined(&quot;FORM.submitid&quot;)>
<CFSET bValidSubmit = true>
<!--- lock the session scope and check the submitID against the list of previously submitted ads... again --->
<CFLOCK timeout=&quot;30&quot; throwontimeout=&quot;No&quot; type=&quot;READONLY&quot; scope=&quot;SESSION&quot;>
<CFIF IsDefined(&quot;session.submittedIDs&quot;) AND ListFind(&quot;#session.submittedIDs#&quot;,FORM.submitID) GT 0>
<CFSET bValidSubmit = false>
</CFIF>
</CFLOCK>
<CFIF bValidSubmit>
<!--- <cfquery name=&quot;Fees&quot; datasource=&quot;market&quot;>
select * from Private_Prices Where category_ID = #form.select_Ad_Subcategory#
</cfquery>
<cfset WF = 5>
<cfset MF = 10>
if it's a new submitID, create the temporary structure (NOT in the session scope --->
<CFSET strTempItem = StructNew()>

<cfset strtempitem.submitID = form.submitID>
<cfset strtempitem.categoryid = #form.select_Ad_Subcategory#>
<cfset strtempitem.subcategoryid = #form.selectLocal#>
<cfset strtempitem.subcategory = #form.sub#>
<cfset strtempitem.location = #form.location#>
<cfset strtempitem.itemname = #form.Itemname#>
<cfset strtempitem.Short_Description = #form.Short_Description#>
<cfset strtempitem.long_description = #form.long_description#>
<cfset strtempitem.itemprice = #form.itemprice#>
<cfset strtempitem.featured = #form.featured#>
<cfset strtempitem.begindate = form.begindate>
<cfset strtempitem.Enddate = (#form.begindate# + #form.Enddate#)>
<CFSET strTempItem.picture1 = &quot;&quot;>
<CFSET strTempItem.picture2 = &quot;&quot;>
<CFSET strTempItem.picture3 = &quot;&quot;>
<CFSET strTempItem.picture4 = &quot;&quot;>
<CFIF IsDefined(&quot;FORM.picture1filename&quot;) AND Len(Trim(FORM.picture1filename)) GT 0>
<CFSET strTempItem.picture1 = FORM.picture1filename>
</CFIF>
<CFIF IsDefined(&quot;FORM.picture2filename&quot;) AND Len(Trim(FORM.picture2filename)) GT 0>
<CFSET strTempItem.picture2 = FORM.picture2filename>
</CFIF>
<CFIF IsDefined(&quot;FORM.picture3filename&quot;) AND Len(Trim(FORM.picture3filename)) GT 0>
<CFSET strTempItem.picture3 = FORM.picture3filename>
</CFIF>
<CFIF IsDefined(&quot;FORM.picture4filename&quot;) AND Len(Trim(FORM.picture4filename)) GT 0>
<CFSET strTempItem.picture4 = FORM.picture4filename>
</CFIF>
<!--- then lock the session scope and append the new ad to the shopping cart and update the list of previously submitted IDs with the current submitID --->
<CFLOCK timeout=&quot;30&quot; throwontimeout=&quot;No&quot; type=&quot;EXCLUSIVE&quot; scope=&quot;SESSION&quot;>
<CFIF NOT IsDefined(&quot;session.auth&quot;) or NOT IsArray(session.auth)>
<CFSET session.auth = arraynew(1)>
</CFIF>
<CFSET ArrayAppend(session.auth,strTempItem)>
<CFIF NOT IsDefined(&quot;session.submittedIDs&quot;)>
<CFSET session.submittedIDs = &quot;&quot;>
</CFIF>
<CFSET session.submittedIDs = ListAppend(&quot;#session.submittedIDs#&quot;,FORM.submitID)>
</CFLOCK>
<CFELSE>
<!--- the submitID already exists in the list of previously submitted IDs, so this submission is not valid --->
<tr>
<td><font color=&quot;#FF0000&quot; size=&quot;2&quot; face=&quot;Georgia, Times New Roman, Times, serif&quot;>You've
already added this item to your cart.</font></td>
</tr>
</CFIF>
</CFIF>
<!--- regardless of any of the above, display the current cart --->
<tr>
<td><div align=&quot;center&quot;><font size=&quot;2&quot; face=&quot;Georgia, Times New Roman, Times, serif&quot;>Here's
your shopping cart:</font></div></td>
</tr>
<CFSET aryLocalArray = ArrayNew(1)>
<!--- readonly lock on the session scope, and copy out the session array to a local array... since we really don't want to keep the lock open while we're looping --->
<CFLOCK timeout=&quot;30&quot; throwontimeout=&quot;No&quot; type=&quot;READONLY&quot; scope=&quot;SESSION&quot;>
<CFIF IsDefined(&quot;session.auth&quot;) AND IsArray(session.auth)>
<CFSET aryLocalArray = session.auth>
</CFIF>
</CFLOCK>

</table>
<!--- output the cart contents using the local (NOT session scope) array --->
<table border=&quot;0&quot; cellpadding=&quot;5&quot; align=&quot;center&quot;>
<tr bgcolor=&quot;#009933&quot; style=&quot;color: #FFFFFF;&quot;>
<td><font size=&quot;2&quot; face=&quot;Georgia, Times New Roman, Times, serif&quot;>Item
#</font></td>
<td><font size=&quot;2&quot; face=&quot;Georgia, Times New Roman, Times, serif&quot;>Item
Name</font></td>
<td><font size=&quot;2&quot; face=&quot;Georgia, Times New Roman, Times, serif&quot;>Category</font></td>
<td><font size=&quot;2&quot; face=&quot;Georgia, Times New Roman, Times, serif&quot;>Listing
Fee</font></td>
<td><font size=&quot;2&quot; face=&quot;Georgia, Times New Roman, Times, serif&quot;>Featured</font></td>
</tr>
<CFIF ArrayLen(aryLocalArray) GT 0>
<cfset variables.totalListing_fee = 0>
<cfset variables.totalFeatured_fee = 0>
<CFLOOP from=&quot;1&quot; to=&quot;#ArrayLen(aryLocalArray)#&quot; index=&quot;whichItem&quot;>
<cfquery name=&quot;Get_Cat&quot; datasource=&quot;market&quot;>
select Subcategory
from subcategory
Where subcategoryID = #aryLocalArray[whichItem].subcategoryid#
</cfquery>
<cfset enddate = aryLocalArray[whichItem].enddate - aryLocalArray[whichItem].Begindate>
<cfif enddate EQ 7>
<cfquery name=&quot;Fees&quot; datasource=&quot;market&quot;>
select * from Private_Prices
Where category_ID = #aryLocalArray[whichItem].categoryid# and listing_code = 'W'
</cfquery><cfelse>
<cfquery name=&quot;Fees&quot; datasource=&quot;market&quot;>
select * from Private_Prices
Where category_ID = #aryLocalArray[whichItem].categoryid# and listing_code = 'M'
</cfquery>
</cfif>
<cfif enddate EQ 7>
<cfquery name=&quot;FFEEs&quot; datasource=&quot;market&quot;>
select Price * 0.40 as feat_total
from Private_Prices
Where category_ID = #aryLocalArray[whichItem].categoryid# and listing_code = 'W'
</cfquery>
<cfelse>
<cfquery name=&quot;FFEEs&quot; datasource=&quot;market&quot;>
select Price * 0.40 as feat_total
from Private_Prices
Where category_ID = #aryLocalArray[whichItem].categoryid# and listing_code = 'M'
</cfquery></cfif>

<CFOUTPUT>
<tr>
<td><font size=&quot;2&quot; face=&quot;Georgia, Times New Roman, Times, serif&quot;>#whichItem#</font></td>
<td><font size=&quot;2&quot; face=&quot;Georgia, Times New Roman, Times, serif&quot;><a href=&quot;Review.cfm?itemnum=#whichItem#&quot;>#aryLocalArray[whichItem].itemname#</a></font></td>
<td><font size=&quot;2&quot; face=&quot;Georgia, Times New Roman, Times, serif&quot;>#get_cat.subcategory#</font></td>
<td><font size=&quot;2&quot; face=&quot;Georgia, Times New Roman, Times, serif&quot;>#dollarformat(fees.price)#</font></td>
<td><font size=&quot;2&quot; face=&quot;Georgia, Times New Roman, Times, serif&quot;><cfif aryLocalArray[whichItem].Featured EQ 1>#dollarformat(ffees.feat_total)#</font></cfif></td>
<TD><a href=&quot;edit_item.cfm?itemnum=#whichItem#&quot;><font size=&quot;2&quot; face=&quot;Georgia, Times New Roman, Times, serif&quot;>|Modify|</font></a>&nbsp;&nbsp;<a href=&quot;delete_item.cfm?itemnum=#whichItem#&quot;><font size=&quot;2&quot; face=&quot;Georgia, Times New Roman, Times, serif&quot;>|Delete|</font></a></TD>
</tr>

<cfset totalListing_fee = totalListing_fee + fees.price>
<cfif aryLocalArray[whichItem].Featured EQ 1>
<cfset totalFeatured_fee = totalFeatured_fee + FFEEs.feat_total></cfif>
</CFOUTPUT>
</CFLOOP>
<cfset Grand_Subtotal = totalListing_fee + totalFeatured_fee>
<cfset Total_GST = Grand_Subtotal * #gst.amount#>
<cfset Total_PST = (Grand_Subtotal + Total_GST) * #PST.amount#>
<cfset Total_taxes = Total_GST + Total_PST>
<cfset Grand_Total = Total_taxes + Grand_Subtotal>
<tr>
<td colspan=&quot;6&quot;><hr></td>
</tr>
<tr>
<td></td>
<td></td>
<td><font face=&quot;Georgia, Times New Roman, Times, serif&quot;>SubTotal
Listing Fees</font></td>
<td><font face=&quot;Georgia, Times New Roman, Times, serif&quot;><cfoutput>#Dollarformat(totalListing_fee)#</cfoutput> </font></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td><font face=&quot;Georgia, Times New Roman, Times, serif&quot;>SubTotal
Featured</font></td>
<td><font face=&quot;Georgia, Times New Roman, Times, serif&quot;><u><cfoutput>#Dollarformat(totalFeatured_fee)#</cfoutput>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</u> </font></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td><font face=&quot;Georgia, Times New Roman, Times, serif&quot;>Grand
SubTotal </font></td>
<td><font face=&quot;Georgia, Times New Roman, Times, serif&quot;><cfoutput>#Dollarformat(Grand_Subtotal)#</cfoutput> </font></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td><font face=&quot;Georgia, Times New Roman, Times, serif&quot;>Taxes</font></td>
<td><font face=&quot;Georgia, Times New Roman, Times, serif&quot;><u><cfoutput>#Dollarformat(Total_Taxes)#</cfoutput>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</u> </font></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td><font face=&quot;Georgia, Times New Roman, Times, serif&quot;>Total</font></td>
<td><font face=&quot;Georgia, Times New Roman, Times, serif&quot;><strong><cfoutput>#Dollarformat(Grand_total)#</cfoutput></strong> </font></td>
<td></td>
</tr>
<CFELSE>
<tr>
<td colspan=&quot;3&quot;>No items currently in cart</td>
</tr>
</CFIF>
</table>
<table align=&quot;center&quot; border=&quot;0&quot;>
<tr><td colspan=&quot;2&quot;><hr></td></tr>
<tr>
<td width=&quot;200&quot;><div align=&quot;center&quot;><a href=&quot;page1.cfm&quot;><img src=&quot;../images/new_item.gif&quot; border=&quot;0&quot;></a></div></td>
<td width=&quot;200&quot;><div align=&quot;center&quot;><a href=&quot;Checkout.cfm&quot;><img src=&quot;../images/checkout.gif&quot; border=&quot;0&quot;></a></div></td>
</tr>
</table>



<tr>
<td background=&quot;../images/top_space2.gif&quot;><img src=&quot;../images/top_space2.gif&quot;></td>
</tr>
</table>
</td></tr>
</table>

</body>
</html>
 
I don't notice anything immediately that would cause the issue you describe.

But you'd need to nail down whether the cart array is actually getting cleared, or whether it's just that your display code doesn't show the entire cart for some reason.

The best way to do that would be to add a
Code:
   <CFDUMP var=&quot;#session.auth#&quot;>
right after the line that does the ArrayAppend():
Code:
   <CFSET ArrayAppend(session.auth,strTempItem)>

This will give you a dump of what's actually in the cart after you add an item. If the cart array is being appended to properly, and all items are actually getting added, then that means somethings just wrong with your cart display (one or more of your CFIF conditions are not being evaluated properly). If the array is getting reset, then something is definitely amiss with the appending code.


-Carl
 
Thanks carl, I actually figured it out, I adjusted the session variables on the server and that fixed it, I didn't know that the server had to be restarted to have the settings take effect
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top