freakystreak — 2012-07-05T05:56:44-04:00 — #1
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.
eastcoast — 2012-07-05T07:46:55-04:00 — #2
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?
freakystreak — 2012-07-05T08:00:41-04:00 — #3
Again, thanks for the reply
system — 2012-07-05T08:08:49-04:00 — #4
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.
system — 2012-07-05T08:12:21-04:00 — #5