• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Simple Shopping Cart

New Here ,
May 20, 2006 May 20, 2006

Copy link to clipboard

Copied

I am trying to develop a simple shopping cart.
I have created an array of structures for this as follows.
<cfif not Isdefined("Session.ShoppingCart")>
<cfset SESSION.shoppingcart = ArrayNEW(1)>
</cfif>

<cfset additem = StructNew()>
<cfset additem.id = FORM.id>
<cfset additem.name = FORM.name>
<cfset additem.color = FORM.color>

<cfset arrayappend(session.shoppingcart, additem)>

I would like to delete a given entry in the array given a particular FORM.id, say id = 220
Here is my code to try and delete the item
<cfloop from="1" to="#ArrayLen(SESSION.shoppingcart)#" index="i">
<cfif SESSION.shoppingcart .id eq FORM.id>
<cfset foo = structdelete(SESSION.shoppingcart
, id)>
<cfelse>
</cfif>
</cfloop>

This is not working. I guess perhaps I should delete the array entry, but I can't figure out how to do this. Thanks in advance. -Noah
TOPICS
Advanced techniques

Views

225

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 20, 2006 May 20, 2006

Copy link to clipboard

Copied

LATEST
Duh, I figured it out.
<cfset bar = arraydeleteat(SESSION.shoppingcart, i)>
I am having a problem when looping not sure why. I think because I'm deleting an item in the array it tries to loop to that index in the array. It will say "The element at position 3 cannot be found". I guess I normally wouldn't have to delete multiple positions in the array with a normal shopping cart unless they selected two different id's. I'll work on a more advanced shopping cart and post again.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation