ASP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingASP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old December 12th, 2003, 01:27 PM
DexterDavis DexterDavis is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: Fargo, ND
Posts: 5 DexterDavis User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to DexterDavis Send a message via Yahoo to DexterDavis
Question Help with ASP Shopping Cart

I am building a shopping cart and I have a viewCart and a checkOut page, both are the same, except that the checkout page has "contact" information in it.

I'm working on the viewCart page and for some reason my Item Price is 9.99, but when I multiply it by the quantity, it registers at 9.00, like it is rounding down. Could someone help me find the error or find a way to fix it?

Here is the code:
Code:
<table border="1" cellpadding="3" cellspacing="1">

  <tr>
<td>ItemID</td>
<td>Name</td>
<td>Episodes</td>
<td>Unit Price</td>
<td>Quantity</td>
<td>Total</td>
<td>Remove One </td>
  </tr>
  
  
<%
Dim objDictionary, strKey, intValue, key, objConn, objRS, Price, Total, SubTotal, GrandTotal, strFind, adOpenStatic
adOpenStatic = 3

'Creates an ADO Connection object
Set objConn = Server.CreateObject("ADODB.Connection") 
Set objRS   = Server.CreateObject("ADODB.Recordset")

'Builds the connection to the datastore
objConn.Open strConnect

objRS.Open "Movies", objConn, adOpenStatic
If IsObject(Session("cart")) Then
Set objDictionary = Session("cart")
Else
Set objDictionary = CreateObject("Scripting.Dictionary")
End If

For Each key in objDictionary
strKey   = key
intValue = objDictionary.Item(strKey)
strFind = "movieID = '" & strKey & "'"
objRS.Find strFind
If Int("0" & objDictionary(strKey)) <= intValue Then
Total = Int(objRS("itemPrice")) * intValue
Response.Write "<tr>"
Response.Write "<td>" & strKey & "</td>"
Response.Write "<td>" & objRS("itemName") & "</td>"
Response.Write "<td>" & objRS("Description") & "</td>"
Response.Write "<td>" & objRS("itemPrice") & "</td>" 
Response.Write "<td>" & intValue & "</td>"
Response.Write "<td>" & FormatCurrency(Total) & "</td>"
Response.Write "<td><a href=""modifyCart.asp?action=remove&movieID=" & strKey & "&quantity=1"">Remove one!</a></td>"
Response.Write "</tr>"
SubTotal = SubTotal + Total
End If
Next
%>
</table>
</center>
<BR>

<table border="1" cellpadding="3" cellspacing="1" align="right">
  <tr>
    <td>
    <p align="right">SubTotal: </td>
<td><%= SubTotal %>&nbsp;</td>
  </tr>
  <tr>
   <td>
    <p align="right">Shipping: </td>
   <td>
    <p align="right">$5.00</td>
  </tr>
<% GrandTotal = subTotal + 5 %>
  <tr>
   <td>
    <p align="right">Grand Total: </td>
   <td><%= GrandTotal %>&nbsp;</td>
  </tr>
</table> 

Reply With Quote
  #2  
Old December 12th, 2003, 03:40 PM
admcdona admcdona is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 20 admcdona User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
It looks like you are throwing the item price into an Int datatype...this gets rid of all decimals. Try using a Double instead.

Reply With Quote
  #3  
Old December 12th, 2003, 03:52 PM
admcdona admcdona is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 20 admcdona User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Sorry...I just got to thinking that I should have been more precise in my response. You are currently using Int which basically just chops of the fractional part of your number (IE - 9.99 goes to 9). You should change all of your Int() calls to CDbl(). ...And if need be you can use Round() or FormatNumber() to round out the number to 2 digits after the decimal.

Reply With Quote
  #4  
Old December 12th, 2003, 06:14 PM
DexterDavis DexterDavis is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: Fargo, ND
Posts: 5 DexterDavis User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to DexterDavis Send a message via Yahoo to DexterDavis
Talking Thank you so much

I can't believe easy of a fix that was. Maybe you could help me on my next problem.


When I click on Remove 1 from the cart, it works great. This morning if the quantity was at 1 and I clicked on remove 1, it would remove the whole row out of the table, but now it doesn't work anymore, it changes the quantity to zero.

viewCart
Code:
<%
	Dim objDictionary, strKey, intValue, key, objConn, objRS, Price, Total, SubTotal, GrandTotal, strFind, adOpenStatic
	adOpenStatic = 3

	'Creates an ADO Connection object
	Set objConn = Server.CreateObject("ADODB.Connection")	
	Set objRS   = Server.CreateObject("ADODB.Recordset")

	'Builds the connection to the datastore
	objConn.Open strConnect

	objRS.Open "Movies", objConn, adOpenStatic
	If IsObject(Session("cart")) Then
		Set objDictionary = Session("cart")
	Else
		Set objDictionary = CreateObject("Scripting.Dictionary")
	End If

For Each key in objDictionary
	strKey   = key
	intValue = CDbl(objDictionary.Item(strKey))
strFind = "movieID = '" & strKey & "'"
objRS.Find strFind
If CDbl("0" & objDictionary(strKey)) <= intValue Then
Total = CDbl(objRS("itemPrice")) * intValue
	Response.Write "<tr>"
	Response.Write "<td>" & strKey & "</td>"
	Response.Write "<td>" & objRS("itemName") & "</td>"
	Response.Write "<td>" & objRS("Description") & "</td>"
	Response.Write "<td>" & FormatCurrency(objRS("itemPrice")) & "</td>"	
	Response.Write "<td>" & intValue & "</td>"
	Response.Write "<td>" & FormatCurrency(Total) & "</td>"
	Response.Write "<td><a href=""modifyCart.asp?action=remove&movieID=" & strKey & "&quantity=1"">Remove one!</a></td>"
	Response.Write "</tr>"
SubTotal = SubTotal + Total
End If
Next
%>

modifyCart
Code:
<%
	Dim objDictionary, strAction, strKey, intValue

	If IsObject(Session("cart")) Then
		Set objDictionary = Session("cart")
	Else
		Set objDictionary = Server.CreateObject("Scripting.Dictionary")
	End If

	strAction = Request.QueryString("action")
	strKey    = Request.QueryString("movieID")
	intValue  = Int(Request.QueryString("quantity"))

Select Case strAction
	Case "add"
		AddItemToCart strKey, intValue
	Case "remove"
		RemoveItemFromCart strKey, intValue
End Select

	intValue = objDictionary(strKey)
	Set Session("cart") = objDictionary
	
Response.Redirect ("viewCart.asp")
%>

<%
	Sub AddItemToCart(strKey, intValue)
	 	If objDictionary.Exists(strKey) Then
			objDictionary(strKey) = Int(objDictionary(strKey)) + intValue
		Else
			objDictionary.Add strKey, intValue
		End If
		Response.Write intValue
	End Sub
%>

<%
	Sub RemoveItemFromCart(strKey, intValue)
		If objDictionary.Exists(strKey) Then
			If Int(objDictionary(strKey)) <= 0 Then
				objDictionary.Remove strKey
			Else
				objDictionary(strKey) = objDictionary(strKey) - 1
			End If
		End If
	End Sub
%>

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingASP Development > Help with ASP Shopping Cart


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
Create the Optimal Architecture for your Critical Applications
Warburton's the largest independently owned bakery in the UK faced a number of difficult challenges in providing the most robust yet efficient IT infrastructure for their organization's success. IBM's services combined with their xSeries servers created the perfect platform for their SAP environment with sufficient flexibility, and did so in very time effective fashion.

Request Your Free Technology Downloads!
 
Five Best Practices for Deploying a Successful Service-Oriented Architecture
This white paper describes the benefits you can expect with SOA, and how IBM can help take your business there.

Request Your Free Technology Downloads!
 
Gartner Magic Quadrant for Application Delivery Controllers
Gartner summarizes its view on Application Delivery Controllers, evaluates strengths and weaknesses of solutions, and provides Magic Quadrant reporting for a quick comparison across all vendors. Learn from Gartner how you can benefit from an all-in-one device like Citrix NetScaler that delivers the highest levels of availability, performance and security.

Request Your Free Technology Downloads!
 
Knowledge is Power
What you don't know can hurt you, and is likely costing you money and increasing your security risks during an era of scarce resources. This white paper proposes six key strategies that enterprise security managers can use to improve their network defense posture.

Request Your Free Technology Downloads!
 
Rationalizing the Multi-Tool Environment
The rationalized multi-tool approach is flexible, scalable and cost effective. It provides the necessary input to the IT service management business processes. It preserves prior investments in monitoring tools, empowers technologists to select the best tools with which to do their jobs, and enhances effective response to incidents.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2010 by Developer Shed. All rights reserved. DS Cluster 8 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek