Hi
I am trying my hand at a basic shopping cart
I have found an example online that uses the following code
<cfparam name="session.cart" default="arrayNew()">
<cfset session.cart = arrayAppend( session.cart, structNew() )>
<cfset thisCartItem = arraylen( session.cart )>
<cfset session.cart[thisCartItem].itemID = form.itemID>
<cfset session.cart[thisCartItem].quantity = form.quantity>
<cfset session.cart[thisCartItem].itemName = form.itemName>
However the code generates the following error message:
Object of type class java.lang.String cannot be used as an array
If someone would like to advise where the above code is causing the error message I would be grateful
Regards
Claude Raiola (B.Econ
Acc; B.Hot. Mngt)
Samaris Software
Email: in...@SAMARIS.net
Website: www.SAMARIS.net
Mobile: 0414 228 948
Hi Claude,
Run this line of code only once to remove your session variable, which is a string:
<cfset StructDelete(session,"cart") />
And here is the correct code:
<cfparam name="session.cart" type="array" default="#ArrayNew(1)#" />
<cfset ArrayAppend(session.cart,StructNew()) />
<cfset thisCartItem = ArrayLen(session.cart) />
<cfset session.cart[thisCartItem].itemID = form.itemID />
<cfset session.cart[thisCartItem].quantity = form.quantity />
<cfset session.cart[thisCartItem].itemName = form.itemName />
Best regards,
Dmitry.
---
Yakhnov Studio, www.yakhnov.info
This works for me...
<cfparam name="session.cart" default="#arrayNew(1)#">
<cfset myCartItem = structNew()>
<cfset myCartItem.itemID = form.itemID>
<cfset myCartItem.quantity = form.quantity>
<cfset myCartItem.itemName = form.itemName>
<cfset result = arrayAppend( session.cart, myCartItem )>
Cheers,
Brett
B)
rai...@ozemail.com.au wrote:
> Hi
>
>
>
> I am trying my hand at a basic shopping cart
>
>
>
> I have found an example online that uses the following code
>
>
>
> <cfparam name="session.cart" default="arrayNew()">
>
> <cfset session.cart = arrayAppend( session.cart, structNew() )>
>
> <cfset thisCartItem = arraylen( session.cart )>
>
> <cfset session.cart[thisCartItem].itemID = form.itemID>
>
> <cfset session.cart[thisCartItem].quantity = form.quantity>
>
> <cfset session.cart[thisCartItem].itemName = form.itemName>
>
>
>
>
>
> However the code generates the following error message:
>
>
>
> *Object of type class java.lang.String cannot be used as an array *
>
>
>
>
>
> If someone would like to advise where the above code is causing the
> error message I would be grateful
>
> Regards
>
> Claude Raiola (B.Econ Acc; B.Hot. Mngt)
> Samaris Software
> Email: in...@SAMARIS.net <mailto:in...@TrackingCentral.om.au>
> Website: www.SAMARIS.net <http://www.TrackingCentral.com.au>
> Mobile: 0414 228 948
>
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "cfaussie" group.
> To post to this group, send email to cfau...@googlegroups.com.
> To unsubscribe from this group, send email to
> cfaussie+u...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/cfaussie?hl=en.
--
Brett Payne-Rhodes
YourSite Web Solutions
w: http://www.yoursite.net.au
e: br...@ehc.net.au
t: +61 (0)8 9371-0471
m: +61 (0)414 371 047
Claude
1) ArrayNew() takes 1 argument being the dimension of the array so you need to say ArrayNew(1)
2)
You are setting
session.cart to the string of “arrayNew()” so you cant append the
cart item because arrayNew(0 is a string, not an array so you need
<cfparam name=”session.cart”, default=”#Arraynew(1)# />
3)
If your cart item
keys are the same as your form fields you can just do
<cfset arrayAppend(session.cart, duplicate(FORM)) />
Just saves on code but if you have lots of fields in your form you
don’t need then maybe setting them manually as you have done may be
better.
Steve
From: rai...@ozemail.com.au
[mailto:rai...@ozemail.com.au]
Sent: Monday, 21 June 2010 11:40 PM
To: cfau...@googlegroups.com; coldfusi...@yahoogroups.com
Subject: [cfaussie] Trying To Create A Basic Shopping Cart
Hi
--