delete item from cart

Ask a Question related to Macromedia ColdFusion, Design and Development.

  1. #1

    Default 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

  2. Similar Questions and Discussions

    1. 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...
    2. 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...
    3. 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...
    4. 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,...
    5. 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...
  3. #2

    Default 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

  4. #3

    Default 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

  5. #4

    Default 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

  6. #5

    Default Re: delete item from cart

    yes thank you. That was exactly what I needed to do.

    timrande Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139