Hey everyone! I am having some issues with modifying my shopping cart - - I am attempting to add Options and Choices to my product listings - Which I store as Structs in my Cart Array - I have it "mostly" working - but I am now trying to compare a products "Options" and "Choices" to verify that the customer is indeed ordering 2 of the same thing. (2 red backpacks, Large - - or 1 Red SMall and 1 Red Large...) The Stuct compare worked when I only had "Options" - but breaks when I added Choices... And I must confess - that I barely grasp how structs work...
After adding a 2nd - non-identical product - I get the error: Cannot find key 1 in struct. Thanks in advance - Nick Example Options (Dropdown) = Small, Med, Large Choice (text box) = Engraving: ENS Live Dev site: http://cf.bigfatdesigns.com/cart/store.cfm Full File: http://code-bin.homedns.org/336 Specific Function in Question: <!--- Internal GetCartPos() Method ---> <CFFUNCTION NAME="GetCartPos" RETURNTYPE="numeric" ACCESS="private"> <!--- Argument: MerchID ---> <CFARGUMENT NAME="MerchID" TYPE="numeric" REQUIRED="Yes"> <CFARGUMENT NAME="Options" TYPE="struct" REQUIRED="No" default="#StructNew()#"> <CFARGUMENT NAME="Choices" TYPE="struct" REQUIRED="No" default="#StructNew()#"> <!--- Get position, if any, of MerchID in cart query ---> <CFSET CurrentArrayPos = 0> <CFLOOP FROM="1" TO="#ArrayLen(This.CartArray)#" INDEX="i"> <cfset OptionsMatch = "TRUE"> <cfset ChoicesMatch = "TRUE"> <CFIF This.CartArray[i].MerchID EQ Arguments.MerchID> <!--- Need to compare both Options Struct AND Choice Struct ---> <cfif StructCount(Arguments.Options) GT 0> <cfset CartItemOptions = This.CartArray[i].Options> <!--- Loop over Option Items to find similar value ---> <cfloop collection="#Arguments.Options#" item="o"> <cfset PassedOptionItemID = #StructFind(Arguments.Options, o)# > <cfset CurrentOptionItemID = #StructFind(CartItemOptions, o)# > <!--- If the values match - remove from temp list ---> <cfif PassedOptionItemID EQ CurrentOptionItemID> <cfset DeleteRow = StructDelete(CartItemOptions, "#o#", "True")> <cfelse> <!--- If they don't match - set to FALSE and break loop ---> <cfset OptionsMatch = "FALSE"> <CFBREAK> </cfif> </cfloop> </cfif> <cfif StructCount(Arguments.Choices) GT 0> <cfset CartItemChoices = This.CartArray[i].Choices> <!--- Loop over Option Items to find similar value ---> <cfloop collection="#Arguments.Choices#" item="c"> <cfset PassedChoiceItemID = #StructFind(Arguments.Choices, c)# > <cfset CurrentChoiceItemID = #StructFind(CartItemChoices, c)# > <!--- If the values match - remove from temp list ---> <cfif PassedChoiceItemID EQ CurrentChoiceItemID> <cfset DeleteRow = StructDelete(CartItemChoices, "#c#", "True")> <cfelse> <!--- If they don't match - set to FALSE and break loop ---> <cfset ChoicesMatch = "FALSE"> <CFBREAK> </cfif> </cfloop> </cfif> <!--- Check size of CartItemOptions - if anything left - the two do NOT match---> <cfif OptionsMatch EQ "TRUE" AND ChoicesMatch EQ "TRUE"> <cfif StructCount(CartItemOptions) EQ 0 AND StructCount(CartItemChoices) EQ 0> <CFSET CurrentArrayPos = i> </cfif> </cfif> <CFBREAK> </CFIF> </CFLOOP> <!--- Return the position ---> <CFRETURN CurrentArrayPos> </CFFUNCTION> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Want to reach the ColdFusion community with something they want? Let them know on the House of Fusion mailing lists Archive: http://www.houseoffusion.com/groups/cf-newbie/message.cfm/messageid:4670 Subscription: http://www.houseoffusion.com/groups/cf-newbie/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.15
