Cart quantity

Asked

Viewed 51 times

-4

Good afternoon,

I would like to know how I can take the amount I enter in my cart view and save it even giving refresh.. For example: customer added 8 amounts of pasta but after page refresh that amount goes back to normal that is quantity 1;

my actionresult on DAO:

public ActionResult RecarregaItensCarrinho(int id)
    {
        ProdutosDAO dao = new ProdutosDAO();
        Produto produto = dao.BuscaPorId(id);
        if (produto != null)
        {
            return Json(new { sucesso = false, resposta = "Nao tem o que atualizar" }, JsonRequestBehavior.AllowGet);
        }
        else
        {
            return Json(new {  sucesso = true, produto.Quantidade }, JsonRequestBehavior.AllowGet);
        }


    }

My function in js in cart:

function RecarregaItensCarrinho() {
        var itens = $("#codItens").val();
        var todosItens = @qtdTotal;
        $.ajax({
            type: 'POST',
            url: 'RecarregaItens',
            data: {
                itens
            },
            success: function (data) {
                if (data.sucesso == true) {
                    $(".qtdProduto").text(@qtdTotal);






                } else {
                    alert(data.resposta);
                }

            }



        })

    }
  • Each time the user enters or removes an item from the cart, this information persists on the server...

1 answer

-4


The ideal is each time the client adds you put this item in an array in the session, so when the client changes pages the data will remain.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.