I have been working on making an ASP.net site that has a shopping cart for candles. When you select the jar type, fragrance, and dye from the DDL's and hit the submit to cart button it adds them into the cart and updates the price. We are having two main issues...
1) When we select the first candle and submit it to the cart it updates the price. However when we attempt to add another candle to the cart it does not update the price.
2) When we hit the remove item button after selecting an item from the cart it messes up the price and if we remove everything it sets the total to a negative number.
Below is our code any help would be really appreciated guys I have scoured the web and asked multiple friends to no avail.
This is the Add Item To Cart button. When adding more than one candle, the cart Total Price does not update:
Protected Sub btnCart_Click(sender As Object, e As EventArgs) Handles btnCart.Click
'jar
If ddlJar.SelectedIndex = 0 Then
decSubtotal += 11.99D
End If
If ddlJar.SelectedIndex = 1 Then
decSubtotal += 11.99D
End If
If ddlJar.SelectedIndex = 2 Then
decSubtotal += 7.99D
End If
If ddlJar.SelectedIndex = 3 Then
decSubtotal += 8.99D
End If
If ddlJar.SelectedIndex = 4 Then
decSubtotal += 3.99D
End If
If ddlJar.SelectedIndex = 5 Then
decSubtotal += 7.99D
End If
'Fragrance
If ddlFrag.SelectedIndex = 0 Then
decSubtotal += 5.99D
End If
If ddlFrag.SelectedIndex = 1 Then
decSubtotal += 5.99D
End If
If ddlFrag.SelectedIndex = 2 Then
decSubtotal += 5.99D
End If
If ddlFrag.SelectedIndex = 3 Then
decSubtotal += 5.99D
End If
If ddlFrag.SelectedIndex = 4 Then
decSubtotal += 5.99D
End If
If ddlFrag.SelectedIndex = 5 Then
decSubtotal += 5.99D
End If
If ddlFrag.SelectedIndex = 6 Then
decSubtotal += 5.99D
End If
If ddlFrag.SelectedIndex = 7 Then
decSubtotal += 5.99D
End If
If ddlJar.SelectedIndex = 8 Then
decSubtotal += 5.99D
End If
If ddlFrag.SelectedIndex = 9 Then
decSubtotal += 5.99D
End If
If ddlFrag.SelectedIndex = 10 Then
decSubtotal += 5.99D
End If
'Calc Tax, Total, discount
decTax = decSubtotal * decTAX_RATE
decTotal = decSubtotal + decTax + decShipping
decShipping = decShipping_Rate * 1
lblSubtotal.Text = decSubtotal.ToString("c")
lblTax.Text = decTax.ToString("c")
lblShipping.Text = decShipping.ToString("c")
lblTotal.Text = decTotal.ToString("c")
lstCart.Items.Add(ddlJar.SelectedItem)
lstCart.Items.Add(ddlDye.SelectedItem)
lstCart.Items.Add(ddlFrag.SelectedItem)
End Sub
Removes item from cart. Doesn't correctly update price:
Protected Sub btnRemove_Click(sender As Object, e As EventArgs) Handles btnRemove.Click
If lstCart.SelectedIndex = -1 Then
Response.Write("<script type=""text/javascript"">alert(""You must have items in your cart."");</script")
Else
'jar
If lstCart.SelectedItem.ToString = "12 Status" Then
decSubtotal -= 11.99D
End If
If lstCart.SelectedItem.ToString = "12 Hex" Then
decSubtotal -= 11.99D
End If
If lstCart.SelectedItem.ToString = "8 Tin" Then
decSubtotal -= 7.99D
End If
If lstCart.SelectedItem.ToString = "9 Hex" Then
decSubtotal -= 8.99D
End If
If lstCart.SelectedItem.ToString = "4 Hex" Then
decSubtotal -= 3.99D
End If
If lstCart.SelectedItem.ToString = "8 Jelly" Then
decSubtotal -= 7.99D
End If
'Fragrance
If lstCart.SelectedItem.ToString = "Monkey Farts" Then
decSubtotal -= 5.99D
End If
If lstCart.SelectedItem.ToString = "Grapefruit" Then
decSubtotal -= 5.99D
End If
If lstCart.SelectedItem.ToString = "Stress Relief" Then
decSubtotal -= 5.99D
End If
If lstCart.SelectedItem.ToString = "Beachwood" Then
decSubtotal -= 5.99D
End If
If lstCart.SelectedItem.ToString = "Blueberry Cobbler" Then
decSubtotal -= 5.99D
End If
If lstCart.SelectedItem.ToString = "Black Ice" Then
decSubtotal -= 5.99D
End If
If lstCart.SelectedItem.ToString = "Beautiful Day" Then
decSubtotal -= 5.99D
End If
If lstCart.SelectedItem.ToString = "Polo Black" Then
decSubtotal -= 5.99D
End If
If lstCart.SelectedItem.ToString = "Lime Basil" Then
decSubtotal -= 5.99D
End If
If lstCart.SelectedItem.ToString = "VS LoveSpell" Then
decSubtotal -= 5.99D
End If
If lstCart.SelectedItem.ToString = "Georgia Peach" Then
decSubtotal -= 5.99D
End If
'Calc Tax, Total, discount
decTax = decSubtotal * decTAX_RATE
decTotal = decSubtotal + decTax + decShipping
decShipping = decShipping_Rate * 1
lblSubtotal.Text = decSubtotal.ToString("c")
lblTax.Text = decTax.ToString("c")
lblShipping.Text = decShipping.ToString("c")
lblTotal.Text = decTotal.ToString("c")
lstCart.Items.RemoveAt(lstCart.SelectedIndex)
End If
End Sub