close ad
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues


I need to create a shopping cart sort of thing

Thread began 11/11/2018 3:23 pm by mrs | Last modified 11/12/2018 3:29 pm by Ray Borduin | 235 views | 1 replies |


I need to create a shopping cart sort of thing

There's a number of questions in this one, so bear with me...

I need to allow users to add products to a cart, but the cart doesn't take payment. It just submits content for a quote. I was thinking of doing it something like this:

- The user visits the site
- I create a session that has a random generated number. Something like: if session isn't set, then generate a random number.
- When the user adds the product to the cart, the product ID and the random number get stored together in a database table via an insert.
- If the user wants to save the cart contents and return at a later date on a different device, then they to save their email address to a different database table. At the same time as entering the email address, the site inserts the random number into the same record.
- When the user returns, the session will create a new random number because the user hasn't identified themselves yet. When the user signs in using their email address the original stored random number overwrites and repopulates the session ID in order to retrieve cart contents. This allows the user to continue shopping or submit the cart for a quote.

Is this feasible?

Is this a lot of work that could be achieved in a simpler way? Are there any issues that you can foresee that I can't?

Would you store as a DB record or rather use something like a cookie? (I'm not quite sure how to work with cookies and how I might retain more than one product... there be dragons!).

The only problem I can see with the above is if the user is returning and they've added more products to the cart before signing in to retrieve previous cart contents, then any new products added to the cart after logging in might be lost or overwritten, which doesn't make for a very good UX! So (final question), how might I combine the newly added products to those already saved without losing either?


Sign in to reply to this post

Ray BorduinWebAssist

session_id() is a random number that is always unique, so you wouldn't have to generate one.

A cookie wouldn't work for your use case since it wouldn't be available from another device, it would just persist on the original device.

I wouldn't bother saving the cart contents with a session_id() since they wouldn't be able to retrieve the cart unless they log in anyway. Just tell them to log in to save their cart contents, and save it based on their userid in the database only when they are logged in. You don't need the random id... it doesn't really give you anything.

Then when someone logs in you can automatically retrieve the cart from the database into a recordset and use "Get Cart Contents from Recordset" to populate the cart. It won't remove the existing items from the cart, you would have to add the Clear Cart server behavior manually if you wanted to do that.

Sign in to reply to this post
Did this help? Tips are appreciated...

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question





Ease of use


security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...