sir_arcturua — 2014-07-02T13:57:19-04:00 — #1
We have an online bookstore. We are interested in having a shopping cart, where customer can select items and then pay for the total.
My question is about variable and tables definition.
These are the tables we have so far:
Products: books details
Customers: customers information
Cart: books selected by the customers
Orders: to consolidate orders
The idea of the website is as any other:
When a customer enters and selects a book, information is stored in a Cart table in MySQL, creating one new line in the table per each new book selected.
After selections are ready, customer makes checkout process and enter personal information.
My question is how can I store books selected from each customer if I do not have her/his personal information yet?
I mean, only when the customer makes checkout process I am able to get personal information, store in DB and get a CustomerID to identify him/her.
thanks a lot!!!
wolfshade — 2014-07-02T14:14:53-04:00 — #2
Session variables. Give the session a LONG timeout (like an hour instead of 20 minutes) and store all items the customer selects in the session scope (it will stay with the user from page to page.)
At checkout, grab all items from the session scope, calculate, etc.
sir_arcturua — 2014-07-02T14:42:12-04:00 — #3
Fantastic, thanks a lot!!
wolfshade — 2014-07-02T15:28:37-04:00 — #4
Don't forget to clear out the session after checkout. I've been bit in the undercarriage by forgetting that part.
Not sure if PHP can do it, but in ColdFusion you can create scopes within the session scope like so:
<cfset session.shcart = "" />
<cfset session.shcart.cart1 = "" />
<cfset session.shcart.cart1.item1 = "A book" />
<cfset session.shcart.cart1.item2 = "Another book" />
That way it's easier to clear out one portion of the session when the checkout is done.
<cfset StructDelete(session,"shcart.cart1") /> Will destroy ONLY cart1; if there is a cart2 or cart3, they will be left alone.
sir_arcturua — 2014-07-02T16:18:31-04:00 — #5
I'm sorry, I am not familiar with ColdFusion.
I will try to do it using PHP.
mittineague — 2014-07-02T19:14:36-04:00 — #6
It's been many, many years since I've worked with ColdFusion, but it looks like in PHP it would be something like