Shopping cart advice needed

Hi guys… and gals,

I’m currently working on a project that requires a shopping cart. I have not designed or coded a bespoke solution to the extent of something similar to paypal or another shopping cart provider before but I’m a confident PHP programmer although no expert and learning all the time.

What I would like to ask is: Should the cart contents be managed by session id or is it viable to use a database to store the customer’s cart contents?

I have previously created an internal admin area where employees can enter products into a cart and the details were stored in a table. Is this a system that would work for an online store open to the public? Otherwise, could you point me in the direction of any helpful articles or tutorials that can help me produce what I need?

The cart will not be making payments but a third-party payment system will be used to handle the transactions. Hence why I ask about storing the cart contents in a table rather than in sessions.

Looking through a tutorial using sessions brings up another question, sessions and rewritten urls. I intend to rewrite the urls, for SEO and was wondering if its possible to mask the session id in the url?

Appreciated as always.

It depends on how persistent you want cart data to be, whether you’re happy for it to persist only for the duration of a customer visit, or if you want it to be resurrected for subsequent visits, and whether you want to tie cart contents to a user profile.

You can store cart data in a session or cookie, and then validate it/ write it to a database on arriving at your checkout first stage (e.g cart summary) then once your payment system has successfully processed the order, mark the database entry as paid via the payment gateway callback, and have it available for further processing and administration. You can also use the callback to provide sufficient data to create a user profile if the data is supplied.

Not sure why you feel the need to have an id in the url, this doesn’t need to be visible at all?

Thanks for the comments EastCoast. I’ve been looking via Google and found a few tutorials on creating the cart. The reason I asked about session ids in the URL was based on the example I initially found used the session id in the url. However, I’ve found another tutorial which uses javascript to pass the session data reducing the need for the session id in the url. I think I will go with using Sessions and Cookies and validate before entering the data in the database and using that data for reference.

Again, thanks for the reply

I have my own customised shopping cart php class and store it in a session using serialize(). The class has methods to add/delete/output the items in the cart.

In the checkout page, I get all the contents from the shopping cart class and enter them into the orders and order_items tables. I also create the form to send the shopping cart contents to PayPal to handle the online payment.

If the user selects credit card as the payment option, the cart contents is sent to PayPal. I use PP’s IPN (Instant Payment Notification) to tell me if the shopper actually went through and completed the payment using their credit card. If they did, then I mark the order as paid in the orders table and the goods and/or services are then delivered to the shopper.

You shouldn’t need the session ID in the url at all, even without javascript and I wouldn’t use javascript at all to handle the cart or payment process because it won’t work in devices that do not support javascript. Why risk losing shoppers unnecessarily !! :headbang: