Ask a Question related to Macromedia ColdFusion, Design and Development.
-
timrande #1
delete item from cart
Has anyone seen this error?
Object of type class coldfusion.runtime.Struct cannot be used as an array
I get this when trying to delete an Item from a shopping cart.
Here's the code for the cart:
<cflock timeout="5" throwontimeout="No" type="EXCLUSIVE" scope="SESSION">
<!--- Check to see if a Cart Session exists, if it doesn't create one. --->
<cfif IsDefined('Session.Cart') is "NO">
<cfscript>
Session.Cart=StructNew();
Session.Cart.ItemID=ArrayNew(1);
Session.Cart.Qty=ArrayNew(1);
Session.Cart.Price=ArrayNew(1);
Session.Cart.EachPrice=ArrayNew(1);
Session.Cart.Description=ArrayNew(1);
Session.Cart.ExtPrice=ArrayNew(1);
Session.Cart.Brand=ArrayNew(1);
Session.Cart.Pack=ArrayNew(1);
Session.Cart.Broken=ArrayNew(1);
Session.Cart.Brokenx=ArrayNew(1);
Session.Cart.Cost=ArrayNew(1);
Session.Cart.Markup=ArrayNew(1);
</cfscript>
</cfif>
</cflock>
here's the code to delete an item:
<<cfif IsDefined('Recalculate')>
<cfloop from="1" to="#ArrayLen(Session.Cart.ItemID)#" index="ThisItem">
<cfif #session.cart.ItemId[ThisItem]# eq #form.itemID#>
<cfif #form.Qty# GT 0>
<cfset session.cart.Qty[ThisItem] = #form.Qty#>
<cfif IsDefined('FORM.Broken')>
<cfset Session.Cart.Broken[ThisItem]=1> <!--- 1=on
(checked) --->
<cfset Session.Cart.Brokenx[ThisItem]="X">
<cfset PriceN = FORM.EachPrice>
<cfelse>
<cfset Session.Cart.Broken[ThisItem]=0> <!--- 0=off
(unchecked) --->
<cfset Session.Cart.Brokenx[ThisItem]="">
<cfset PriceN = DecimalFormat(FORM.Price)>
</cfif>
<cfset Session.Cart.ExtPrice[ThisItem]=(#Form.Qty# *
#PriceN#)>
<cfelse>
<cfset session.cart =
arrayDeleteAt(session.cart,ThisItem)>
</cfif>
</cfif>
</cfloop>
</cfif>
This line fails: <cfset session.cart = arrayDeleteAt(session.cart,ThisItem)>
timrande Guest
-
Datagrid item renderer delete button
I have a datagrid with an item renderer. In the item renderer is a delete button img. Onclick it will remove the item from the datagrid with the... -
How to delete a list-item with Contribute 4
I use Contribute for a lot of my client for years and a few weeks ago i installed Contribute 4 for the first time for a new client .We dicovered... -
can only add one item to the cart
Hi ho - Have got a situation where users can add an item to a cart - then go back to the list and browse for more items - actually in this case its... -
help please with Delete item in CF7
hi, I have a basic application with a list of items, users can update or delete thier items, update works fine it takes them to the update page,... -
Checking to see if an item is in shopping cart
Hi all, I'm trying to query a table to see if an item has already been added. If it hasn't, then add the item to the table and display all the... -
mxstu #2
Re: delete item from cart
.... Session.Cart=StructNew(); ...
Session.Cart is a structure not an array. You can't use an array funciton on a "structure". Use a structure function, like StructDelete(), etc..
mxstu Guest
-
timrande #3
Re: delete item from cart
yes I see that thank you. But i guess what i need to do is delete the array record inside of the structure. I'm not sure how to do this.
timrande Guest
-
mxstu #4
Re: delete item from cart
If you're trying to delete a single element from one of the arrays, you would
need to do something like this
<cfset status = ArrayDeleteAt(Session.Cart.ItemID, thisItem)>
where "thisItem" is an array index. It looks like the arrays are related, so
you probably need to delete the element from the other arrays as well.
mxstu Guest
-
timrande #5
Re: delete item from cart
yes thank you. That was exactly what I needed to do.
timrande Guest



Reply With Quote

