Mark Rae said:
[please don't top-post]
That's what I do, though I tend to use a generic e.g. Dictionary<int,
int> to store the ID of the purchased product along with the number of
items purchased...
Would using a generic list (of these objects) be the best way to handle
this in your opinion? Store that to a session variable?
No it wouldn't, otherwise that's what I'd be doing. I've never found any
need to persist anything other than the ID of the item bought together
with the number of items purchased.
I would disagree... (as a guy who has some experience in a-commerce, my
site
www.mspiercing.com )
Here are some thoughts (from 3 years experience of having web site).
1. Items might have options ( and sometimes more than one option). Id of
the item will be the same but color different.
So if you want to keep them in memory then create clsItem object which
goes into shopping cart (generic list is perfect). So it will have
ItemId, Options selected, Quantity, Price and who knows what else...
2. Why to have a price... In real word you will change a price... and you
do not want to get a mad customer who added "green tv" to the shopping
cart for 5.95 and suddenly when he checked out that "green tv" became
10.45. Simply because you and people who work in the E-commerce store work
during the day and changing prices right in a middle of the day when
people are shopping.. Keep that in mind.
3. It's generally bad idea to keep shopping cart in memory. Simply because
you want to see how many attempts were made to buy staff from you..
Believe it or not but 50% people do not complete purchase. They add staff
to shopping cart but never proceed all the way to complete the order. And
you want to see what people were looking at... So keep it in DB so you
could look/analyze at it later... Or help out some customer who calls you
and says that he wanted to buy "green tv" from you and added it to the
shopping cart but his computer/internet died and he can not complete the
order.
4. Order table must have all information about items (price, name,
...).... So it becomes frozen in time. Person might want to look at his
previous order (especially if its business customer and he needs to print
out invoice for IRS) and he needs to se price he ordered this item for 6
month ago and not new price... Or if item was discontinued and removed
from inventory... Still you need to show complete info... like name,
picture....
George.