SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    May 2013
    0 Post(s)
    0 Thread(s)

    Shopping cart from scratch

    Okay, So I have very little background in PHP or JS or anything other than HTML and CSS basically.

    Here goes nothing
    It seems ive bitten off more than I can chew with my latest project, as I've told someone that I would take the time to figure out on how to add a shopping cart to his website. But the problem is ive never built a shopping cart, I have no experience with databases and I don't know how to code PHP. I am a very fast learner and if I get pointed in the right directions I am positive I can pull it off.

    What I need: A shopping car that I don't need 4-5-6 different programs to operate. Id be more comfortable opening it with Notepad or something similar. If I were to do this step by step. What should be the first thing I do to make myself a shopping cart. Could someone provide me with the basics so that I can do some research on exactly what needs to be done?

    Also, (I know im far from this step but) Id like to have a drop down menu to select the product. I know how to make a drop menu... but I don't know how to point it to a specific place in the Database.

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    The Netherlands
    153 Post(s)
    2 Thread(s)
    The basics are fairly simple, but if you have no experience with databases I would highly suggest you install some premade software like ZenCart (just an example, I've never worked with it and can not recommend for or against it, do your own research to find something that fits your needs).

    Anyway, if you were to roll your own, the basics are that you would need

    A product admin to add/edit/delete products
    Basically this is one or more tables in the database. The products themselves go in one table* and then you'd have another table (optional) for categories. The admin once logged in would then be able to add/edit/delete products and add/edit/delete categories (if needed)

    * Unless you're working with a special case like several different sizes per product which all have a different price, in which case you might need multiple tables.

    A cart
    There are two ways you can do this.

    1 The easiest way is to store the information in the session of the user. You give each product a unique ID and when the user puts it in his cart you simply add the id (and the quantity, and any other field you may want to store) in the user session. Then at the checkout just read back the session and show the products that are in there.

    2 This is a bit more complex but has it's advantages. The first time someone puts something in their cart, create a shopping cart in the database, and store the id of that shopping cart in a cookie. Then you store which products the user has in it's shopping cart in the database. The advantage of this method over method 1 is that a) the shopping cart will remembered even if the user leaves the page, shuts down his computer and comes back later, etc and 2) you can creare an overview of "abandoned carts", i.e., shopping carts with stuff in it that in the end were not bought. This can be handy for the shop owner to see which products people would like but in the end don't buy so he can investigate what's wrong with the offer (maybe something's not clear, maybe it's too expensive, etc).

    A checkout
    This is IMHO by far the hardest part to get working correctly. You need a link with a online payment system so people can pay for the products they bought. Basically you'd need to provide the price and (depending on the payment provider) information about the products to the payment provider, which will then in turn let the customer pay. In the simplest version that's it, and the shop owner would then check the payments in the website of the payment provider, match them to orders in his own system, and dispatch anything that was paid. In a more advanced version you would check with the payment provider if a payment was made, and automatically set the order to 'paid' so the shop owner doesn't have to check this manually (of course it's still recommended he does, just to be sure) and you can send emails to the customer indicating the order was paid and will be shipped ASAP, etc.

    As for implementing this I would work in the order I described; start with the product admin, then a cart, and finally a checkout.
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts