views:

51

answers:

2

I'm doing some research for my project where I'm gone have a shopping cart. I been reading some and one way that shopping cart seem to be handled in mvc is to save it to the Profile and later on save it in the db after order is complete, and [Serializable] on the class.

My question is do you see any downside doing it like this with the profile?

EDIT
I think I found a downside saving the cart to profile and that is the migration from anonymous to authenticated user. I'm currently working on Web Application Project so The migration solutions I found don't work (in the global with Profile Common). I found some useful information recently but I want to ask here one thing tho.

The info I found is I can get and set the properties in the profile, but the migration part is still unsolved. Anybody got any tips on this or solution that can point me in the right direction?

A: 

This is the classic it depends.

Size is the biggest draw back I can see.

It depends on the size of your object. You could have a very large object when really all you need a list of ProductIds that is in the user cart. Could be allot of bytes compared just a few.

If I was doing something like this I would just save a list of the Products in the shopping cart. There might be more information needed (like qty), but I would try to save the bare minimum to keep the read/write as small as possible.

When you Seialize a class it if you use Xml you get an element for each property. Binary is a little more compact (which is what I would choose).

David Basarab
Would it be to much with 2 classes ShoppingCart and ShoppingCartItem. the shoppingCartItem would be just quantity and product id. I thought in my web.config I would do serializeAs="Binary", is that what you mean?
Dejan.S
When I was implementing this, I just used `Dictionary<int, int>` (key = product id, value = quantity) stored in `Session` and had a wrapper class `ShoppingCart` with static methods like `Add()`, `Remove()` etc.
Necros
A: 

An additional downside is session length. If session times out, how do you want to handle the cart?

NickLarsen
can I set the session time some how? U know I would rather save the shopping cart to db rightaway and handle it with cookies. But unfortunaly I have not found a good example with cookies with mvc
Dejan.S