What do yo mean exactly with which tables you need to create? If you're talking about tables in the database it depends of course on what kind of information you want to store and show.
But a layout can be something like this:
Product table
Id
Name
Description
Price
VAT
ImageLocation
Regards,
Yorrick
Live life loosely coupled and separated of concerns
&
Don't forget to click "Mark As Answer" on the post that helped you.
In case of the two tables you describe you should use the item table to get the details from that you want to show in your shopping cart. IF you want to show the category in the shopping cart as well you would need to use the category table as well.
Regards,
Yorrick
Live life loosely coupled and separated of concerns
&
Don't forget to click "Mark As Answer" on the post that helped you.
In principle you don't need another table to create the order list. You can do this in a Session variable. You can create an order model like this:
public class Order
{
public string Id { get; set; }
public string Name { get; set; }
public int Ammount { get; set; }
public string Price { get; set; }
public decimal SubTotal { get; set; }
}
And maintain a list of this model in a Session variable with a session class like so:
public class OrderSession
{
private OrderSession()
{
}
public static OrderSession Current
{
get
{
var orderSession = (OrderSession) HttpContext.Current.Session["__OrderSession__"];
if(orderSession == null)
{
orderSession = new OrderSession();
HttpContext.Current.Session["__OrderSession__"] = orderSession;
}
return orderSession;
}
}
public List<Order> Orders { get; set; }
}
Each time a visitor adds a product you just add an order object to the list in the session in the controler or if the product already exists add one to the ammount, in my case it is wine:
public void Add(int id)
{
WineDetails wine = m_wineService.GetWineById(id);
if (OrderSession.Current.Orders == null)
{
OrderSession.Current.Orders = new List<Order>();
}
IEnumerable<Order> existingOrders = from o in OrderSession.Current.Orders
where o.Id == wine.Id
select o;
if (existingOrders.Any())
{
existingOrders.First().Ammount += 1;
existingOrders.First().SubTotal = existingOrders.First().Ammount * existingOrders.First().Price.SafeDecimalParse().Value;
}
else
{
var order = new Order
{
Id = wine.Id,
Name = wine.Name,
Price = wine.SellingPrice,
Ammount = 1,
SubTotal = wine.SellingPrice.SafeDecimalParse().Value
};
OrderSession.Current.Orders.Add(order);
}
}
Hope this helps you on your way.
Regards,
Yorrick
P.s. the SafeDecimalParse method you see being used on the SellingPrice is an extension method I created.
Live life loosely coupled and separated of concerns
&
Don't forget to click "Mark As Answer" on the post that helped you.
DimiBy
Member
187 Points
233 Posts
Wich Tables create for shopping cart?
Mar 03, 2012 08:39 AM|LINK
Hello
I want create shopping cart for my web shop. And wich Tables i need create for my Card?
Yorrick vd V...
Participant
1674 Points
301 Posts
Re: Wich Tables create for shopping cart?
Mar 03, 2012 09:04 AM|LINK
Hi,
What do yo mean exactly with which tables you need to create? If you're talking about tables in the database it depends of course on what kind of information you want to store and show.
But a layout can be something like this:
Regards,
Yorrick
&
Don't forget to click "Mark As Answer" on the post that helped you.
DimiBy
Member
187 Points
233 Posts
Re: Wich Tables create for shopping cart?
Mar 03, 2012 10:15 AM|LINK
I have nex tables:
I have tables: Category and Item. And wich tables i need use, i i want create shopping cart?
Yorrick vd V...
Participant
1674 Points
301 Posts
Re: Wich Tables create for shopping cart?
Mar 03, 2012 11:02 AM|LINK
Hi,
In case of the two tables you describe you should use the item table to get the details from that you want to show in your shopping cart. IF you want to show the category in the shopping cart as well you would need to use the category table as well.
Regards,
Yorrick
&
Don't forget to click "Mark As Answer" on the post that helped you.
DimiBy
Member
187 Points
233 Posts
Re: Wich Tables create for shopping cart?
Mar 03, 2012 01:19 PM|LINK
I mean, what else need to create a table, that the buyer could build order?
Yorrick vd V...
Participant
1674 Points
301 Posts
Re: Wich Tables create for shopping cart?
Mar 03, 2012 05:22 PM|LINK
Hi,
In principle you don't need another table to create the order list. You can do this in a Session variable. You can create an order model like this:
public class Order { public string Id { get; set; } public string Name { get; set; } public int Ammount { get; set; } public string Price { get; set; } public decimal SubTotal { get; set; } }And maintain a list of this model in a Session variable with a session class like so:
public class OrderSession { private OrderSession() { } public static OrderSession Current { get { var orderSession = (OrderSession) HttpContext.Current.Session["__OrderSession__"]; if(orderSession == null) { orderSession = new OrderSession(); HttpContext.Current.Session["__OrderSession__"] = orderSession; } return orderSession; } } public List<Order> Orders { get; set; } }Each time a visitor adds a product you just add an order object to the list in the session in the controler or if the product already exists add one to the ammount, in my case it is wine:
public void Add(int id) { WineDetails wine = m_wineService.GetWineById(id); if (OrderSession.Current.Orders == null) { OrderSession.Current.Orders = new List<Order>(); } IEnumerable<Order> existingOrders = from o in OrderSession.Current.Orders where o.Id == wine.Id select o; if (existingOrders.Any()) { existingOrders.First().Ammount += 1; existingOrders.First().SubTotal = existingOrders.First().Ammount * existingOrders.First().Price.SafeDecimalParse().Value; } else { var order = new Order { Id = wine.Id, Name = wine.Name, Price = wine.SellingPrice, Ammount = 1, SubTotal = wine.SellingPrice.SafeDecimalParse().Value }; OrderSession.Current.Orders.Add(order); } }Hope this helps you on your way.
Regards,
Yorrick
P.s. the SafeDecimalParse method you see being used on the SellingPrice is an extension method I created.
&
Don't forget to click "Mark As Answer" on the post that helped you.
DimiBy
Member
187 Points
233 Posts
Re: Wich Tables create for shopping cart?
Mar 05, 2012 10:32 AM|LINK
Thank you!