-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I'm building my first shopping cart type app, using the webmonkey
tutorial
(http://hotwired.lycos.com/webmonkey/99/49/index4a.html?tw=programming
), and have a question about the code below. My question is, doesn't
storing the items in the cart keyed to the name lead to a problem if
items have the same name? Wouldn't using an ID, which is presumably
unique be better? Or am I misunderstanding the way structures work?:

<cfscript>
   if (not(isdefined("session.cart"))) {session.cart = structnew(); }

   // The item structure we are going to use to store the items in
the cart
   // is going to have four parts...
   //   1.  The item id
   //   2.  The item name
   //   3.  The price per unit
   //   4.  The quantity

   tempvalue =
listtoarray('#attributes.id#,#attributes.name#,#attributes.price#,#att
ributes.quantity#');

   // if the item is not yet in the cart, simply add it to the cart
   if (not(structKeyExists(session.cart, attributes.name))) {
    StructInsert(session.cart,attributes.name,tempvalue);
   }

   // if the item is already in the cart, update the item quantity
   else {
   
tempvalue[4]=session.cart[attributes.name][4]+attributes.quantity;
    StructUpdate(session.cart,attributes.name,tempvalue);
   }   
  </cfscript>

c
- --
Chris Lott


-----BEGIN PGP SIGNATURE-----
Version: PGP Personal Privacy 6.5.3
Comment: KeyID: 0x51046CFD

iQA/AwUBOaCsYdaLYehRBGz9EQKeggCghl95BMpX3HPxDLM2BZ4PrShc7jQAn3Z3
ZyOjxz3QlNzUQYciW+oyUgYw
=7zyq
-----END PGP SIGNATURE-----


------------------------------------------------------------------------------
Archives: http://www.mail-archive.com/[email protected]/
To Unsubscribe visit 
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or send a 
message to [EMAIL PROTECTED] with 'unsubscribe' in the body.

Reply via email to