Skip to main content
Participant
August 16, 2007
Question

Shopping Cart

  • August 16, 2007
  • 1 reply
  • 476 views
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 has been closed for replies.

1 reply

Inspiring
August 16, 2007
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.

emcgillAuthor
Participant
August 18, 2007
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
Inspiring
August 18, 2007
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 >