ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreColdFusion Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 5th, 2005, 10:17 PM
erikd erikd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Location: NYC
Posts: 81 erikd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 h 19 sec
Reputation Power: 5
Shopping Cart--Trouble Deleting Item

I am creating a shopping cart and having trouble deleting an item from it.

Here is the code to start the cart and add items. I am able to add items and display them just fine.

<!--- If the Add To Cart Button has been submitted, invoke the cart code. --->
<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);
Session.Cart.on0=ArrayNew(1);
Session.Cart.os0=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>
<cfif Session.Cart.os0[ThisItem] EQ FORM.os0></cfif>
<cfif Session.Cart.os0[ThisItem] NEQ FORM.os0>
<cfset Session.Cart.os0[ThisItem]=Session.Cart.os0[ThisItem] & " " & FORM.os0></cfif>
</cflock>

<cfelse>
<!--- If the Item doesn’t exist in the Cart Session, add it. --->
<br>
<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>
<cfset Session.Cart.on0[ThisItem]=FORM.on0>
<cfset Session.Cart.os0[ThisItem]=FORM.os0>
</cflock>

</cfif>

</cfif>

However when I try to delete an item with a remove checkbox and a hidden itemid field from a form that calls the same page
with the following code which is at the top of the page in which the cart is displayed(this page works fine except when you try to delete the item), it deletes the entire session and I receive an error that CART.ITEMID is undefined in SESSION, because it is looking at the code which displays the cart. How do I get it to just delete the specified item and not the whole array or cart session. Thanks in advance.


<cfif IsDefined("FORM.remove")>
<cfloop from="1" to="#ArrayLen(Session.Cart.ItemID)#" index="ThisItem">

<cfif Session.Cart.ItemID[ThisItem] eq form.itemid>

<cfset session.cart = arrayDeleteAt( session.cart.ItemID, ThisItem )>
</cfif></cfloop>



<cflocation url="http://www.fishdogco.com/Checkout.cfm" addtoken="no">


</cfif>

Reply With Quote
  #2  
Old January 6th, 2005, 08:07 AM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,689 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 16 h 33 m 51 sec
Reputation Power: 53
I'd start with the fact that you seem to be using the wrong array syntax...you have this:

<cfif Session.Cart.ItemID[ThisItem] eq form.itemid>

which, if "session.cart" is an array, is incorrect. It should be:

<cfif Session.Cart[ThisItem].itemID eq form.itemid>

From your code it looks like you are making this mistake everywhere you reference the array.
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian.
How to Post a Question in the Forums

Reply With Quote
  #3  
Old January 6th, 2005, 08:13 AM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,689 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 16 h 33 m 51 sec
Reputation Power: 53
In fact here is the root of the problem I think...
<cfscript>
Session.Cart=StructNew();
Session.Cart.ItemID=ArrayNew(1);
Session.Cart.Qty=ArrayNew(1);
Session.Cart.on0=ArrayNew(1);
Session.Cart.os0=ArrayNew(1);
</cfscript>

This isn't doing what you think it is I suspect. This is creating a new structure with keys for ItemID, Qty, on0, and os0, and setting each of those keys to be separate arrays. I think what you want it this:

<cfscript>
Session.Cart=ArrayNew(1);
</cfscript>

And then when you add to the array for example, you'd do:

<!--- If the Item doesn’t exist in the Cart Session, add it. --->
<br>
<cfset ThisItem=ArrayLen(Session.Cart.ItemID) +1 >
<!--- === [ Add to cart ] === // --->
<cflock timeout="5" throwontimeout="No" type="EXCLUSIVE" scope="SESSION">
<!--- Add a new array element which is a struct. --->
<cfset arrayAppend( session.cart, structNew() ) />
<!--- Now set the keys for the new struct to hold the form data --->
<cfset Session.Cart[arrayLen( session.cart )].ItemID=FORM.ItemID>
<cfset Session.Cart[arrayLen( session.cart )].Qty=FORM.Qty>
<cfset Session.Cart[arrayLen( session.cart )].on0=FORM.on0>
<cfset Session.Cart[arrayLen( session.cart )].os0=FORM.os0>
</cflock>

Reply With Quote
  #4  
Old January 6th, 2005, 09:11 PM
erikd erikd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Location: NYC
Posts: 81 erikd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 h 19 sec
Reputation Power: 5
Thanks for the help. So now I have the following code which adds the first item correctly. However when you try to add this item again or add another item I get an error stating: Complex object types cannot be converted to simple values.
The code that gives the error is highlighted in green
<cfif ListFind(ArrayToList(Session.Cart), FORM.ItemID) NEQ 0>
I googled this, but don't understand how this is viewed by later versions of Coldfusion as a simple value structure. I am using ColdFusion MX.
Here is the code.


<!--- If the Add To Cart Button has been submitted, invoke the cart code. --->
<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=ArrayNew(1);
</cfscript>
</cfif>
</cflock>

<!--- //If Item exists, Update Quantity // --->
<cfif ListFind(ArrayToList(Session.Cart),FORM.ItemID) NEQ 0>

<cfset ThisItem=ListFind(ArrayToList(Session.Cart),FORM.ItemID)>
<!--- //Set Quantity // --->
<cflock timeout="5" throwontimeout="No" type="EXCLUSIVE" scope="SESSION">
<cfset Session.Cart[arrayLen( Session.Cart )].Qty=Session.Cart[arrayLen( Session.Cart )].Qty + FORM.Qty>
<cfif Session.Cart[arrayLen( Session.Cart )].os0 EQ FORM.os0></cfif>
<cfif Session.Cart[arrayLen( Session.Cart )].os0 NEQ FORM.os0>
<cfset Session.Cart[arrayLen( Session.Cart )].os0=Session.Cart[arrayLen( Session.Cart )].os0 & " " & FORM.os0></cfif>
</cflock>

<cfelse>
<!--- If the Item doesn’t exist in the Cart Session, add it. --->
<br>
<cfset ThisItem=ArrayLen(Session.Cart) +1 >
<!--- === [ Add to cart ] === // --->
<cflock timeout="5" throwontimeout="No" type="EXCLUSIVE" scope="SESSION">
<!--- Add a new array element which is a struct. --->
<cfset arrayAppend(Session.Cart, structNew() )/>
<!--- Now set the keys for the new struct to hold the form data --->
<cfset Session.Cart[arrayLen( Session.Cart )].ItemID=FORM.ItemID>
<cfset Session.Cart[arrayLen( Session.Cart )].Qty=FORM.Qty>
<cfset Session.Cart[arrayLen( Session.Cart )].on0=FORM.on0>
<cfset Session.Cart[arrayLen( Session.Cart )].os0=FORM.os0>
</cflock>

</cfif>

</cfif>

Reply With Quote
  #5  
Old January 6th, 2005, 10:50 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,689 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 16 h 33 m 51 sec
Reputation Power: 53
<cfif ListFind(ArrayToList(Session.Cart),FORM.ItemID) NEQ 0>

...is not valid. You can only convert session.cart to a list if session.cart hold simple values. Remember, session.cart is an array of structures. These are complex types and can't be converted to simple values. What you need to do is loop through the session.cart array and for each element check to see if it is matching the form.itemID.

Reply With Quote
  #6  
Old January 9th, 2005, 02:57 PM
erikd erikd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Location: NYC
Posts: 81 erikd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 h 19 sec
Reputation Power: 5
So I have it set up now as follows below. However I think something is wrong with the loop. I don't get an error, but nothing gets added to the cart. I can remove the loop and throw in a bunch of <cfif> statements and it works, but I would rather do this correctly with a loop, can you take a look at my syntax to see what is going on, once again I am not getting an error message, but nothing seems to be added to the cart. The session.cart gets started, but that is all. Thanks for your help

Code:


<!--- If the Add To Cart Button has been submitted, invoke the cart code. --->
<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=ArrayNew(1);
</cfscript>
</cfif>
</cflock>


<cfloop from="1" to="#ArrayLen(Session.Cart)#" index="ThisItem">

<cfif Session.Cart[ThisItem].ItemID eq form.itemid>
<cfset ThisItem=ListFind(ArrayToList(Session.Cart),FORM.ItemID)>
<!--- //Set Quantity // --->
<cflock timeout="5" throwontimeout="No" type="EXCLUSIVE" scope="SESSION">
<cfset Session.Cart[arrayLen( Session.Cart )].Qty=Session.Cart[arrayLen( Session.Cart )].Qty + FORM.Qty>
<cfif Session.Cart[arrayLen( Session.Cart )].os0 EQ FORM.os0></cfif>
<cfif Session.Cart[arrayLen( Session.Cart )].os0 NEQ FORM.os0>
<cfset Session.Cart[arrayLen( Session.Cart )].os0=Session.Cart[arrayLen( Session.Cart )].os0 & " " & FORM.os0></cfif>
</cflock>

<cfelse>
<!--- If the Item doesn’t exist in the Cart Session, add it. --->

<cfset ThisItem=ArrayLen(Session.Cart) +1 >
<!--- === [ Add to cart ] === // --->
<cflock timeout="5" throwontimeout="No" type="EXCLUSIVE" scope="SESSION">
<!--- Add a new array element which is a struct. --->
<cfset arrayAppend(Session.Cart, structNew() )/>
<!--- Now set the keys for the new struct to hold the form data --->
<cfset Session.Cart[arrayLen( Session.Cart )].ItemID=FORM.ItemID>
<cfset Session.Cart[arrayLen( Session.Cart )].Qty=FORM.Qty>
<cfset Session.Cart[arrayLen( Session.Cart )].on0=FORM.on0>
<cfset Session.Cart[arrayLen( Session.Cart )].os0=FORM.os0>
</cflock>

</cfif></cfloop>

</cfif>

Reply With Quote
  #7  
Old January 9th, 2005, 03:37 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,689 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 16 h 33 m 51 sec
Reputation Power: 53
Yes the loop is not correct. First, you're looping regardless of whether you're adding a new item or not. And you're not updating the correct array element, you're using arrayLen( session.cart ) which will always be updating the last element in the array. Try something like this:

<cfset isNewCartItem = true />

<cflock timeout="5" throwontimeout="No" type="EXCLUSIVE" scope="SESSION">

<!--- // Loop through the cart items... // --->
<cfloop from="1" to="#ArrayLen(Session.Cart)#" index="ThisItem">
<!--- // If the current cart item's ID matches the form itemID, update this item's quantity. // --->
<cfif Session.Cart[ThisItem].ItemID eq form.itemid>
<!--- //Set Quantity // --->
<cfset Session.Cart[ThisItem].Qty=Session.Cart[thisItem].Qty + FORM.Qty>
<cfset isNewCartItem = false />
<cfbreak>
</cfif>
</cfloop>

<cfif isNewCartItem>
<!--- === [ Add to cart ] === // --->
<!--- Add a new array element which is a struct. --->
<cfset arrayAppend(Session.Cart, structNew() )/>
<!--- Now set the keys for the new struct to hold the form data --->
<cfset Session.Cart[arrayLen( Session.Cart )].ItemID=FORM.ItemID>
<cfset Session.Cart[arrayLen( Session.Cart )].Qty=FORM.Qty>
<cfset Session.Cart[arrayLen( Session.Cart )].on0=FORM.on0>
<cfset Session.Cart[arrayLen( Session.Cart )].os0=FORM.os0>
</cfif>
</cflock>

Reply With Quote
  #8  
Old January 10th, 2005, 11:40 AM
erikd erikd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Location: NYC
Posts: 81 erikd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 h 19 sec
Reputation Power: 5
Thanks for the help that worked perfectly.
My check out page calls itself when a user wants to delete or update an item in their cart. If there is only one item added to the cart, and I delete that item with this code

<cfif IsDefined("FORM.delete")>
<cfloop from="1" to="#ArrayLen(Session.Cart)#" index="ThisItem">
<cfif Session.Cart[ThisItem].ItemID eq form.itemid>
<!---<cflocation url="http://www.google.com" addtoken="no">--->
<cfset Session.Cart = arrayDeleteAt( Session.Cart , ThisItem )>
</cfif>
</cfloop>
<cflocation url="http://www.domain.com/Checkout.cfm" addtoken="no">
</cfif>

I receive the following error, because it is trying to reference later code on that same page. Object of type class java.lang.Boolean cannot be used as an array. I think it is deleting the array or something. Do I have to put in some kind of check to see if there are no items in the cart and if so then go to a different page?
However, when there are two different items in the cart the <cfif> check <cfif Session.Cart[ThisItem].ItemID eq form.itemid> doesn't go through(its not true), so I wanted to see why, and when I did, it showed the value as ThisItem1,ThisItem2 or (9001,9002) which are the item numbers. Any idea why this would take place. By the way kiteless, you have helped me become a much better programmer and I thank you for teaching me the ways of ColdFusion.

Reply With Quote
  #9  
Old January 10th, 2005, 11:59 AM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,689 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 16 h 33 m 51 sec
Reputation Power: 53
Yes, arrayDeleteAt() returns true or false, it does not return the modified array. You just want this:

<cfset arrayDeleteAt( Session.Cart , ThisItem ) />

Reply With Quote
  #10  
Old January 15th, 2005, 10:40 PM
erikd erikd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Location: NYC
Posts: 81 erikd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 h 19 sec
Reputation Power: 5
That works great if there is only one item in the cart. However, when I add another item with a different ID, it doesn't do anything. I can update and delete items from the cart just fine if there is only one item, but not multiple. I have played around with it for the last couple of days and can't seem to figure it out. Here is the code to update and delete an item:

<cfif IsDefined("Form.submit")>
<cfloop from="1" to="#ArrayLen(Session.Cart)#" index="ThisItem">
<cfif Session.Cart[ThisItem].ItemID eq form.itemid><cfif Form.submit IS "delete">
<cfset arrayDeleteAt( Session.Cart , ThisItem )>
</cfif><cfif Form.submit IS "update"><cfset session.cart[ThisItem].Qty = form.quantity></cfif></cfif>
</cfloop>
<cflocation url="http://www.domain.com/Checkout.cfm" addtoken="no">
</cfif>

Reply With Quote
  #11  
Old January 16th, 2005, 11:23 AM
erikd erikd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Location: NYC
Posts: 81 erikd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 h 19 sec
Reputation Power: 5
Could it be that when there are multiple items in the cart it doesn't know which id it was passed. Here is the code that displays the shopping cart. I had it output the ID, just for the time being so that I could make sure that it this would not be the problem, but as I keep looking at this and trying different ways to fix it, I realized that this could be it.

<cfif IsDefined ('Session.Cart')>
<form method="post" action="Checkoutdisplay.cfm">
<table width="100%" border="0" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF" bgcolor="#b9d6ec">
<tr align="center">
<td width="154%" colspan="6"><div align="left">

<table width="100%" border="1" cellpadding="3" cellspacing="1" bordercolor="#FFFFFF">
<tr>
<td background="titlebg.jpg"> <div align="center"><font color="#FFFFFF">Remove
Item </font></div></td>
<td background="titlebg.jpg"><div align="center"><font color="#FFFFFF">Update
Item </font></div></td>
<td background="titlebg.jpg"> <div align="center"><font color="#FFFFFF">Quantity</font></div></td>
<td background="titlebg.jpg"> <div align="center"><font color="#FFFFFF"><span class="txt-bold">Item
Name</span></font></div></td>
<td background="titlebg.jpg"> <div align="center"><font color="#FFFFFF">Options</font></div></td>
<td background="titlebg.jpg"> <div align="center"><font color="#FFFFFF"><span class="txt-bold">Total</span></font></div></td>
</tr>
<cfset ordertotal = 0>
<cfloop from="1" to="#ArrayLen(Session.Cart)#" index="ThisItem">
<tr bgcolor="EEEEEE">
<td height="42"> <div align="center"> <span class="txt-bold"><font size="-1" face="Century Gothic">
<input name="submit" value="delete" type="submit">
</font></span> </div></td>
<td><div align="center"><span class="txt-bold"><font size="-1" face="Century Gothic">
<input name="submit" type="submit" value="update">
</font></span></div></td>
<td> <div align="center">
<cfquery name="geItem" datasource="datasource">
SELECT item_price,itemid,item_name FROM items WHERE
itemid = #Session.Cart[ThisItem].ItemID#
</cfquery>
<cfset total = 0>
<cfset total = total + (geItem.item_price * Session.Cart[ThisItem].Qty)><cfoutput>
<input type="text" name="itemid" value="#Session.Cart[ThisItem].ItemID#">
<input type="text" name="quantity" size="1" value="#Session.Cart[ThisItem].Qty#">
</div></td>
<td> <div align="center"><font size="-1" face="Century Gothic">#geItem.item_name#</font></div></td>
<td> <div align="center"><font size="-1" face="Century Gothic">#Session.Cart[ThisItem].on0#:
#Session.Cart[ThisItem].os0#</font></div></td>
<td> <div align="center"><font size="-1" face="Century Gothic">#LSCurrencyFormat(total,'local')#</font></cfoutput></div></td>
</tr>
<cfset ordertotal = ordertotal + total>
</cfloop>

<cfset Variables.noitems = ordertotal>
</table>
<cfif Variables.noitems IS "0"><cfoutput>
<br><div align="center">
There are currently no items in your cart</div><br>

</cfoutput></cfif><cfif Variables.noitems IS NOT "0">
<span class="txt-bold"><font size="-1" face="Century Gothic"><br>
<br>
Order Total: $<cfoutput>#ordertotal#</cfoutput></font></span>
</div></td></cfif>
</tr>
</table>
</form>

Reply With Quote
  #12  
Old January 18th, 2005, 03:01 PM
erikd erikd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Location: NYC
Posts: 81 erikd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 h 19 sec
Reputation Power: 5
does anyone have any ideas on this? What I am I missing. I have gone over the code 100 times and made changes and nothing fixes this problem. I am using <cfset arrayDeleteAt( Session.Cart , ThisItem )>. Should this not delete the item in the session.cart array where the position is "ThisItem". I know it does, because it works with one item in the array, so why does it not work with multiple items? Thanks in advance.

Reply With Quote
  #13  
Old January 19th, 2005, 09:09 PM
erikd erikd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Location: NYC
Posts: 81 erikd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 h 19 sec
Reputation Power: 5
I found out that my <cfif Session.Cart[ThisItem].ItemID eq form.itemid> check wasn't going through which is why when I had more than one item in my cart, it wasn't doing anything when i requested a delete or update. I don't understand why this check would fail. So I proceeded to remove this check to see what was going on.
And I got the following error.
Cannot insert/delete at position 3.
The array passed has 1 indexes. Valid positions are from 1 to 1.

So when I send the third item in my cart which is the structure at position 3 in the Session.Cart array, I get the above error. Why is it only looping from 1 to 1 and not 1 to 3

<cfloop from="1" to="#ArrayLen(Session.Cart)#" index="ThisItem">
<cfif Form.submit IS "delete">
<cfset arrayDeleteAt( Session.Cart , ThisItem )>
</cfif><cfif Form.submit IS "update"><cfset session.cart[ThisItem].Qty = form.quantity></cfif>
</cfloop>

Thanks for the help

Reply With Quote
  #14