I have this code that I've used to build several shopping carts ... now, on a new site, just two days before launch ... it's not working right.
I've been pulling my hair out for five hours trying to figure what the hell is going on. I can add one item to the cart fine. I can add two items fine. But on the third item, I suddenly start getting duplicate items in the cart, like up to three copies of the last item added. I've never come across this problem before with this code. The code is below ... if anybody can see what the hell is going on, I would certainly appreciate the help. <!--- first, find the details on the item being added to the cart ---> <!--- select ---> <cfquery name="FindItem" datasource="#DSN#" blockfactor="100"> SELECT store.ITEM_ID, store.ITEM_NAME, store.DESCRIPTION, store.PRICE, store.CASE_PRICE, store.IMAGE, store.MERCHANTS_ID, store.CASE_INVENTORY, store.INVENTORY, merchants.MERCHANTS_ID, merchants.COMPANY_NAME FROM store LEFT OUTER JOIN merchants ON store.MERCHANTS_ID = merchants.MERCHANTS_ID WHERE store.ITEM_ID = #URL.ITEM_ID# </cfquery> <!--- for the remove from cart to work, we need to count the total number of items ---> <cfset client.totalitems = 0> <cfparam name="FORM.TOTAL_BOTTLES" default="0"> <cfparam name="FORM.TOTAL_CASES" default="0"> <!--- set a param to determine whether we're adding to the cart for the first time or not ---> <cfif IsDefined('client.cartItems')> <cfset client.newcart="Yes"> <cfelse> <cfset client.newcart="No"> </cfif> <!--- if this is not a new cart, let's add our first item ---> <cfif client.newcart is "NO"> <!--- script to add item to cart ---> <CFSCRIPT> cart = ArrayNew(1); item = StructNew(); item.ITEM_ID = "#FindItem.ITEM_ID#"; item.ITEM_NAME = "#FindItem.ITEM_NAME#"; item.DESCRIPTION = "#FindItem.DESCRIPTION#"; item.MERCHANTS_ID = #FindItem.MERCHANTS_ID#; item.COMPANY_NAME = #FindItem.COMPANY_NAME#; item.ITEMTOTAL = "0"; if (attributes.action IS 'buy_bottle') { item.PRICE = #FindItem.PRICE#; item.BASE_PRICE = #FindItem.PRICE#; item.CONTAINER = 'bottle'; item.QUANTITY = '1'; item.AVAILABLE = #FindItem.INVENTORY#; } else { item.PRICE = #FindItem.CASE_PRICE#; item.BASE_PRICE = #FindItem.CASE_PRICE#; item.CONTAINER = 'caseof'; item.QUANTITY = '1'; item.AVAILABLE = #FindItem.CASE_INVENTORY#; } CartItems = ArrayAppend(cart, item); client.newcart = 'Yes'; </CFSCRIPT> <cfwddx action="CFML2WDDX" input="#cart#" output="client.cartItems" usetimezoneinfo="No"> <cfelse> <cfwddx action="WDDX2CFML" input="#client.cartItems#" output="Cart"> <CFSCRIPT> // loop through the current cart to check for duplicates for (x=1; x lte arrayLen(cart); x=x+1){ if (cart[x].item_id is FindItem.ITEM_ID) { temp = 1; } else { item = StructNew(); item.ITEM_ID = "#FindItem.ITEM_ID#"; item.ITEM_NAME = "#FindItem.ITEM_NAME#"; item.DESCRIPTION = "#FindItem.DESCRIPTION#"; item.MERCHANTS_ID = #FindItem.MERCHANTS_ID#; item.COMPANY_NAME = #FindItem.COMPANY_NAME#; item.ITEMTOTAL = "0"; if (attributes.action IS 'buy_bottle') { item.PRICE = #FindItem.PRICE#; item.BASE_PRICE = #FindItem.PRICE#; item.CONTAINER = 'bottle'; item.QUANTITY = '1'; item.AVAILABLE = #FindItem.INVENTORY#; } else { item.PRICE = #FindItem.CASE_PRICE#; item.BASE_PRICE = #FindItem.CASE_PRICE#; item.CONTAINER = 'caseof'; item.QUANTITY = '1'; item.AVAILABLE = #FindItem.CASE_INVENTORY#; } CartItems = ArrayAppend(cart, item); } } </CFSCRIPT> <cfwddx action="CFML2WDDX" input="#cart#" output="client.cartItems" usetimezoneinfo="No"> </cfif> <!--- update the total items count for the remove code ---> <cfset client.totalitems=client.totalitems+1> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Howard Owens Internet Operations Coordinator InsideVC.com/Ventura County Star [EMAIL PROTECTED] AIM: GoCatGo1956 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4 Subscription: http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4 FAQ: http://www.thenetprofits.co.uk/coldfusion/faq Get the mailserver that powers this list at http://www.coolfusion.com Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4