Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Setting Up Your Own Shopping Cart, PHP - Intermediate
Phryxus
post Feb 23 2005, 03:31 AM
Post #1


Uptight Dot
Group Icon
Group: Moderator
Posts: 1,168
Joined: 20-October 04
Member No.: 916





Before you start (please read!):

Just to make sure you doesn't waste your time on this tutorial some things you need to know first.

When you want to start with this tutorial you should know how to use sessions and cookies. You should also have a user system. Making a shopping cart is very easy, but always a hurdle. It's always good to set up a good plan. This because you want to make sure that it fits your costumer needs. Not everyone will need a lot of functions. Just saving, ordering and listing products is enough for most of the e-commerce websites.

Sometimes you see a shopping cart that doesn't requires to log-in. When the user clicks to buy the products they will be asked to log-in. In this tutorial we won't make that. Not because it's to hard to make, but because it can be irritating and most of all confusing for your costumers.

First step (setting up your database)

Users ('users') table:
Next to all the information you store for users you should have the following cells in you user table.



It's not a problem if the fields have a different name. Just make sure that you can remember the names that are used. Do not throw different languages through each other. Also look out with HEADCASE and lowercase names.

Products ('products') table:
After this check we need to create an effective database structure. When I started to write this tutorial I encountered a huge problem. There are no products to test it on for me. So now we will need to make a table for our products. If you already have one, just make sure that the most important fields are inside of your table. You can also add a field for product information.

Click here for the image

Again this is just a example. You can add fields if you want more functionality. Just make sure you save a percentage the same way as I do (X / 100). Just to make it easier in the future to calculate the price with discount. Also it’s smart to save taxes in a different table. When taxes change you will only have to change 1 field.

Taxes ('taxes') table
Just a small table. The 'id' is the same as the taxes id in the product table.



Shopping cart ('shoppingcart') table:

Click here for the image

Just take a good look at this table. And try to link the 'pid' and 'uid' to the right table (just to make sure you know what you are doing). You will also need to save the date and time! You will not be using this for the payment. Because a user can wait a couple of days before sending the order. This date will give users the ability to look back at orders they have made. Even if you are not going to use it, it is still smart to save it. Because you will not be able to add this in the future if there are already products in the database.
The check field is for checking if the product is already ordered or not. I prefer to use for true a '1' and for false a '0'.

Please, check everything before you go on with the following step.

Second step (inserting products into the shopping cart)

Now we are going to try to make everything work. You will need to do a lot yourself. I will not write the script for you, because you won't learn anything if I do that. Maybe you are already able to go on for yourself. The hardest part is done for you in the previous step, just make sure that you make a good documentation. Just like I did in Excel. These projects will take more then one day and you don't want to start all over again.

Ok, let's move on. You should first make a page that shows the products. In this page you can place an order form that goes to a page that inserts the product in the shopping cart. Just take a look at a existing e-commerce website. The form requires two fields. In the first field the user can set the amount of products. I used the name 'amount' for the amount of products that is going to be ordered. The other field is a hidden field where you can store the product id ('pid'). A button will submit the field. The handling page should look like this:

CODE
INSERT INTO shoppingcart (pid, uid, amount) VALUE ('" . $pid . "', '" . $uid . "', '" . $amount . "')


The field 'uid' is the id of the user (probably from a session). The date and time shouldn't be inserted yet! Like I've said before, that's the date and time the user orders the product not the date and time of placing it in the shopping cart.

If you're able to insert products into your shopping cart you can make the shopping cart itself. The shopping cart is the page that shows the products that is in the user's list. The select query will look like the one below:

CODE
SELECT * FROM shoppingcart WHERE uid = '" . $uid . "' AND check = '0'


Make sure that the user can do three things in his shopping cart: Edit, delete and ordering the products.

Last step (products check out)

When the user makes the decision to buy the products he can go to his shopping cart and click on a large order button. Behind the order button will be a php script that handles this check out. The php file that handles the check out will do a couple of things:

1. Notifying the owner of the shop that there are products ordered. This can be done by e-mail, but you can also choose for an admin page. The admin page will show which products are ordered, the date of the order and the user that ordered the product. You can use the existing shopping cart table for this page. Off course you can also send all these information to a mail box, but you'll get in trouble if there are to many orders.
2. Updating the ordered products. Setting 'check' to 1, 'date' and 'time'.
3. Confirming the order by sending an e-mail to the user.

I'll hope this third tutorial is very usefull for you, as designer. I've rewritten the last 2 steps for three times I hope it's clear now. Just open a new topic here if you need any help.


IPB
Gelderblom Webdesign {SITE24 - BLA Rotterdam}

Open Source alternatives:
 
+Quote Post  Go to the top of the page
RedDragon
post Mar 4 2005, 03:47 PM
Post #2


insert coin
Group Icon
Group: Main Team
Posts: 5,344
Joined: 24-May 04
From: Maastricht
Member No.: 35





thanks a lot Wouter, this is one hell of a valuable tutorial!

smile.gif


IPB
 
+Quote Post  Go to the top of the page
kickapoo
post Aug 15 2005, 12:04 PM
Post #3


New Member
Group Icon
Group: Member
Posts: 5
Joined: 15-August 05
Member No.: 6,177



this cool...thanks thumbsup.gif
 
+Quote Post  Go to the top of the page
Phryxus
post Aug 15 2005, 12:10 PM
Post #4


Uptight Dot
Group Icon
Group: Moderator
Posts: 1,168
Joined: 20-October 04
Member No.: 916





Your welcome. bigwink.gif

This post has been edited by Phryxus: Aug 15 2005, 12:10 PM


IPB
Gelderblom Webdesign {SITE24 - BLA Rotterdam}

Open Source alternatives:
 
+Quote Post  Go to the top of the page
alias.infnit
post Aug 15 2005, 09:17 PM
Post #5


Ludwig Wendzich
Group Icon
Group: *Premier*
Posts: 1,243
Joined: 13-July 05
From: New Zealand
Member No.: 5,345





Wow looks awesome, wanna teach us about sessions and cookies bigwink.gif



...


..


.


..


...
Maybe throw in a User Management system, Content-Management system and roles & groups (admin,moderator, author & group 1, group 2, group 3)


That would be lovely bigwink.gif


IPB
 
+Quote Post  Go to the top of the page
Phryxus
post Aug 16 2005, 01:11 AM
Post #6


Uptight Dot
Group Icon
Group: Moderator
Posts: 1,168
Joined: 20-October 04
Member No.: 916





Thank you infnit!

Sessions and Cookies... hmmm that's a nice subject indeed.

Allready written one 'cms kinda tutorial' some time ago. smile.gif

Creating Your Own Permission System

Have fun reading it.

This post has been edited by Phryxus: Aug 16 2005, 01:15 AM


IPB
Gelderblom Webdesign {SITE24 - BLA Rotterdam}

Open Source alternatives:
 
+Quote Post  Go to the top of the page
socorro
post Oct 12 2005, 01:00 AM
Post #7


New Member
Group Icon
Group: Member
Posts: 20
Joined: 11-October 05
Member No.: 7,490





thanks a lot Wouter


IPB
(\__/)
(='.'=) This is Bunny. Copy and paste bunny into your
(")_(") signature to help him gain world domination.
 
+Quote Post  Go to the top of the page
mike07
post Aug 7 2007, 12:50 PM
Post #8


New Member
Group Icon
Group: Member
Posts: 1
Joined: 7-August 07
Member No.: 17,192





Thanks for the information helped me set up my shopping cart on my new site. I also need to find a new merchant account to process my payments. Any suggestions?
 
+Quote Post  Go to the top of the page
*D*
post Aug 7 2007, 01:10 PM
Post #9


Merry KissMoose
Group Icon
Group: Main Team
Posts: 15,988
Joined: 18-May 04
From: North Pole
Member No.: 2





QUOTE(mike07 @ Aug 7 2007, 01:50 PM) *
Thanks for the information helped me set up my shopping cart on my new site. I also need to find a new merchant account to process my payments. Any suggestions?


Paypal
 
+Quote Post  Go to the top of the page

Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 

RSS Lo-Fi Version Time is now: 1st December 2008 - 10:30 PM
Remortgages | Bad Credit Mortgages | Credit Counseling | eHarmony Coupon | Computers 2007