Skip to main content
Participant
Aug 16, 2007 12:16 AM UTC
Question

Shopping Cart

Hi,

I have a shopping cart where everything works fine when you order just one product, but if you try to order two products, the total only adds up for the one product and completely ignores the other.

How do I get the cart to add the total cart contents, and not just the total for one product?

Thanks,

Eric

This topic is closed to new replies. Start a new post to keep the conversation going.

3 replies

Inspiring
Aug 16, 2007 12:48 AM UTC
That's because the code clears the "FinalTotal" variable on every iteration of the loop. Move the initialization statement before the loop

<cfset FinalTotal = 0>
<cfloop query="Results">
...rest of code
</cfloop>

Also you don't need any of those # signs around the variables.

Translate
emcgillAuthor
Participant
Aug 18, 2007 12:44 PM UTC
Hi,

You were exactly right once I took the FinalTotal = 0 out it it started adding up correctly.

I had to take the sales tax out of it also, so this is the final code that I came up with


It was all adding up, but it was only doing the sales tax for just one item, instead of all of them. So I took it out of the loop and added the complete total for all the items and then * it by the sales tax rate in my state, added the shipping and we are set to go.

Thanks for your help I greatly appreciate it!

Thanks,

Eric
Translate
Inspiring
Aug 18, 2007 4:52 PM UTC
Glad its working.

Btw, you don't need any those # signs in the code. For example this
<cfset TotalPrice = #UnitPrice#*#Quanity#>

Can be rewritten as
<cfset TotalPrice = UnitPrice * Quanity >

Translate