Showing posts with label ecommerce. Show all posts
Showing posts with label ecommerce. Show all posts

Tuesday, March 13, 2012

Stuck

im building a ecommerce site (still)
any way i need to work out the shipping fee depending on the combined weight off the products.
each product has a column in the database called weight and at moment is an integer??

heres the sql statment

ALTER PROCEDURE GetTotalWeight
(@dotnet.itags.org.CartID varchar(50))
AS

DECLARE @dotnet.itags.org.Amount int

SELECT @dotnet.itags.org.Amount = SUM(Product.[Weight]*ShoppingCart.Quantity)
FROM ShoppingCart
INNER JOIN Product
ON ShoppingCart.ProductID = Product.ProductID
WHERE ShoppingCart.CartID = @dotnet.itags.org.CartID

IF @dotnet.itags.org.Amount IS NULL
SELECT 0
ELSE
SELECT @dotnet.itags.org.Amount
RETURN

heres the procedure!
Public Function GetTotalWeight() As Decimal
' Create the connection object
Dim connection As New SqlConnection(connectionString)

' Create and initialize the command object
Dim command As SqlCommand = New SqlCommand("GetTotalWeight", connection)
command.CommandType = CommandType.StoredProcedure

' Add an input parameter and supply a value for it
command.Parameters.Add("@dotnet.itags.org.CartID", SqlDbType.VarChar, 50)
command.Parameters("@dotnet.itags.org.CartID").Value = shoppingCartId

' Save the total amount to a variable
Dim amount As Decimal
connection.Open()
amount = command.ExecuteScalar()

' Close the connection
connection.Close()

' Return the amount
Return amount

If amount <= 1000 Then
amount = 3.46
ElseIf amount > 1000 < 1500 Then
amount = 4.45
ElseIf amount > 1500 <= 2000 Then
amount = 4.78
ElseIf amount > 2000 <= 4000 Then
amount = 7.2
ElseIf amount > 4000 <= 6000 Then
amount = 7.86
ElseIf amount > 6000 <= 8000 Then
amount = 8.96
ElseIf amount > 8000 <= 10000 Then
amount = 9.62
ElseIf amount > 10000 Then
amount = 11.21
End If

End Function

heres it setting it to the label
ShippingCostLabel.Text = String.Format("{0:c}", cart.GetTotalWeight())

obviousley this is wrong as the returned vale is always the combined weight so it obviousley bypasses the if statment!

can sum 1 plz help me on this as im baffled!
and if u really want to help out is there away to store the prices in a database so they can be modified?? but just getting an if stament like that 2 work would be great!

Thx in advance!First question is, what is shoppingCartId? Are you sure that is set to a valid shopping cart id?

Second, if you run the query in Query Analyzer, do you get the proper result there?

Regarding your final question about storing prices in a database so they can be modified, yes there is. Any data in a database can be modified, assuming that you have permissions to do so. You can use an UPDATE statement to change them.

Is that what you meant?

Don
Yep the sql statement works it calculates the weight and passes it on!

however its not useing the if statment after

return amount its just bypassing that big if statment how do u get it so it recaculates the amount varible using that big ass if statment??

what i meant with the database editing is how would u go about it cos u would have 2 compare the weight against a column in the databse?

say the column in the database

(weight int 4) (price money)
1000 £3.50
2000 £6

and the combined weight off the product was say 1500 so that would be the price for the 2000 row so how would u do that?? in the sql statemmnet i assume but i only now how to recive stuff if its precise.

Is that clearer??
can any1 help?? dont care about the database bit but how do i get that if statment working? thx!

Stuck working on ecommerce carthelp plz?

I'm working on an ecommerce site with asp.net and I am currently focusing on the cart page. I have an incoming prodId and Qnty (quantity). These values are stored to an array (the reason for this is so that I can leave the cart page and come back and have all the cart items still available).

Then I set up a table for design elements. And in this table I add an inner-table. This inner table is where I assemble the Product Information. Since the array can have 1 to many items in it, this has proven tricky.

I made a loop to run as long as the array provides prodId's and in this loop I create a new Row on this inner-table. These rows have the product info for each product. There is the product name, price, quantity, removal box.

I add the controls to the table and it all works great with one entry in the array.
If there are multiple entries in the array, its no go. I am figuring this is because there is only one of each product info variable...and the loop creates rows with reference to these variables.

I am kinda stuck and wondering if anyone has any suggestions or other ways of going about this.

One idea that I have been wondering is the possibility of creating a variable whose name includes another variable?

In other words, create:

Dim prodLink0 as new hyperlink
(WHERE the 0 is the value of a variable, such as Y)

Dim prodLink1 as new hyperlink
(WHERE the 1 is the value of a variable, such as Y)

Dim prodLink2 as new hyperlink
(WHERE the 2 is the value of a variable, such as Y)

If I could do this...then I'de be able to make individual variables for each table row.

Any help would be so helpful.
Thanks a ton in advance.i recommend visiting these websites for better info on shopping carts:

1- http://www.quantumsoftware.com.au/OnlineLearning/Programming/DotNet/ASP/ShoppingCart.aspx

2-
http://www.codeproject.com/useritems/shopcart.asp

3-
http://www.sitepoint.com/article/1055

best of luck.