Using the ArrayDeleteAt function is causing some grief.
I have a shopping cart based on a 2D array. If I have two or more items in the shopping cart and try to delete the first item, I get an error. But deleting 2nd, 3rd, etc items first causes no problems.
I am not sure if the array needs to be resized or something like that.
Here's the code I have for both update and deleting the cart.
<CFSET #NumberOfItems# = 0>
<CFLOOP index="NewQty" from="1" to="#ListLen(FORM.Qty)#">
<CFSET #Session.sShoppingCart[NewQty][2]# = #ListGetAt(FORM.Qty, NewQty)#>
<CFSET #NumberOfItems# = #NumberOfItems# + 1>
</CFLOOP>
<CFLOOP index="NewQty" from="1" to="#arrayLen(Session.sShoppingCart)#">
<CFIF #Session.sShoppingCart[NewQty][2]# EQ 0>
<CFSET #DeleteItem# = #arrayDeleteAt(Session.sShoppingCart, NewQty)#>
<CFSET #NumberOfItems# = #NumberOfItems# - 1>
</CFIF>
</CFLOOP>
<CFSET #ShoppingCartResize# = #arrayResize(Session.sShoppingCart, NumberOfItems)#>
I have a shopping cart based on a 2D array. If I have two or more items in the shopping cart and try to delete the first item, I get an error. But deleting 2nd, 3rd, etc items first causes no problems.
I am not sure if the array needs to be resized or something like that.
Here's the code I have for both update and deleting the cart.
<CFSET #NumberOfItems# = 0>
<CFLOOP index="NewQty" from="1" to="#ListLen(FORM.Qty)#">
<CFSET #Session.sShoppingCart[NewQty][2]# = #ListGetAt(FORM.Qty, NewQty)#>
<CFSET #NumberOfItems# = #NumberOfItems# + 1>
</CFLOOP>
<CFLOOP index="NewQty" from="1" to="#arrayLen(Session.sShoppingCart)#">
<CFIF #Session.sShoppingCart[NewQty][2]# EQ 0>
<CFSET #DeleteItem# = #arrayDeleteAt(Session.sShoppingCart, NewQty)#>
<CFSET #NumberOfItems# = #NumberOfItems# - 1>
</CFIF>
</CFLOOP>
<CFSET #ShoppingCartResize# = #arrayResize(Session.sShoppingCart, NumberOfItems)#>