Shopping cart with asp

akohl's picture

They have: 117 posts

Joined: Feb 2001

I'm about to start work on a shopping cart for an online store.How does one store shopping cart information in a session variable? I thought of three possibilities (er.. now four)and I have no idea which ones if any are good or work at all. Let me know if any of these will work or make another suggestion.

please advise. And keep in mind, I like to keep things simple, even if I don't always know how!

1)
A session array, each cell containing the product id, the quantity (seperted by a comma) and a flag indicating that the customer did or didn't decide to drop the product from the cart rather than take it to check out.

2)
a single string containing product id number,quantity;drop_flag: of all prodcuts in one long string that can be uglued, perhaps with great difficulty for the light hearted, when changes have to be made or the customer takes it to check out.

3)
seperate session variables for each product containing all date in a string as above

4)
seperate session arrays for each product holding each detail about the purchase in a seperate array cell.

Andy Kohlenberg
Jerusalem, Israel

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

Sorry for the delayed answer...

How does one store shopping cart information in a session variable?
quick answer: I wouldn't

longer answer:
Only need one sessoin variable: UserID
Then keep all the shopping cart info in a DB table. It's a lot easier to keep track of all your vars if you only have one Wink. Also, you can allow the user to window shop now, and buy latter. The next time they log into your site, you grab their UserID, and can query for any item in their shopping cart. Make sense?

Good Luck,

Mark Hensler
If there is no answer on Google, then there is no question.

akohl's picture

They have: 117 posts

Joined: Feb 2001

Makes sense, I suppose.

What then, if not shopping cart, would be a good use for session variable in on online shop.

I'm doing this as a course project and I need to get some practice working with the session object.

Andy Kohlenberg
Jerusalem, Israel

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

Secured areas are a great use for sessions objects.

User logs in, you store at least UserName, UserID, and AuthLevel. And maybe a UserGroup.

On EVERY page in the secured area you will need to include a page, I'll call it AuthLevel1.asp. In this file, you will check to see if the session exists. If the session is null or empty, kick them out, perhaps to a login screen. If the session is there, check to see if the AuthLevel is high enough for this area. If not kick them out (Response.Redirect()) Wink.

Some areas may lock out everyone but certain people. If this is the case, include a different file, such as AuthGroup1.asp. In this file, you will check the UserName or UserGroup to see if they are authorized for that area.

When the user logs out. Remember to kill the session (Session.Abandon). This will allow someone else to login using the same browser.

Mark Hensler
If there is no answer on Google, then there is no question.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.