I'm trying to build a "simple" sales system, however, I do not have any knowledge in e-commerce. What I want is the following:
The user chooses the products he wants, assembles a cart, and completes the order. Then my question starts: the cart is half finished, I can add the items and the quantity desired, but I do not know how to do the calculation to display the total value.
Follow my Action :
public ActionResult AdicionarCarrinho(int id)
{
List<ItemDesign> carrinho = Session["Carrinho"] != null ? (List<ItemDesign>)Session["Carrinho"] : new List<ItemDesign>();
Design d = db.Design.Find(id);
if (d != null)
{
ItemDesign i = new ItemDesign();
i.Design = d;
i.Qtd = 1;
i.IdDesign = d.IdDesign;
if (carrinho.Where(x => x.IdDesign == d.IdDesign).FirstOrDefault() != null)
{
carrinho.Where(x => x.IdDesign == d.IdDesign).FirstOrDefault().Qtd += 1;
}
else
{
carrinho.Add(i);
}
Session["Carrinho"] = carrinho;
}
return RedirectToAction("Carrinho");
}
public ActionResult Carrinho()
{
List<ItemDesign> carrinho = Session["Carrinho"] != null ? (List<ItemDesign>)Session["Carrinho"] : new List<ItemDesign>();
return View(carrinho);
}
My first question is: How can I do to calculate total value according to cart items?
Second question: What to do after finishing the cart? What I was trying to do was more or less the following:
The user ends the order, and opens a payment screen (ticket only). He would type his data (name and cpf, I do not know) and the system would generate a "pseudo-ticket" with the buyer's data and the items he requested. It does not have to be a real ticket, because I do not really want to implement it.
Here are my tables:
Design:
IdDesign
Servico
Preco
ItemDesign:
Id
IdDesign
IdPedido
Pedido:
IdPedido
DtPedido
StatusPedido
IdUsuario
DtPagamento
ValorTotal
I accept suggestion of any tutorial / book on E-commerce.
Edit: View of Cart
@model List<AllFiction.Models.ItemDesign>
@{
ViewBag.Title = "Carrinho";
}
<h2>Carrinho</h2>
@foreach (var item in Model)
{
<li>
@item.IdDesign - @item.Design.Servico
<input type="text" value="@item.Qtd" readonly="readonly"/>
<input type="submit" value="alterar" />
@Html.ActionLink("Remover", "Remover", "Shop", new {id=item.IdDesign}, null)
</li>
}
@Html.ActionLink("Retornar", "Servicos", "Shop")