Jump to content

Simple Shopping Cart


gc40

Recommended Posts

Greetings All,

I am looking at creating an extremely simple shopping cart.

 

I have already made the script that would allow me to add categories and products, along with displaying those categories and products. The script also allows me to edit/delete and add new categories and products.

 

However, I would like visitors to be able to view products then add them to a virtual shopping cart. Once the product is stored in the shopping cart, he can then click checkout.

 

My checkout is going to be a bit different. I do not allows users to sign in or register because we are only offering 10-20 products, however, when they add products to the shopping cart, it will be stored based on sessions that are logged by cookies.

Now, when they click submit, it will ask them for their EMAIL, FULL NAME, TELEPHONE, and ADDRESS. Once they fill it in and submit, the products they choose and their information will be emailed as a purchase order to my email inbox.

 

Can anyone guide me to a script that does this or help me make one? I am lost and need some urgent help. Thanks.

Link to comment
Share on other sites

Here is a mail script. You will have to customize it to what your needs are though.

 

<?php
                                $headers ="MIME-Version: 1.0" . "\r\n";
			$headers .= "X-Mailer: PHP/" .phpversion() ."\n";
			$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
			$headers .= "From: NAMEHERE <user@domain.com>"; //set your from address here

			$to=$email;//set the email address it being sent to
			$subject = 'Subject '; //subject of email
			$body=' Body of Email Here'; //the body of the email

			mail($to, $subject, $body, $headers);

?>

 

This is the basic code. Generally for the body part, I will make a new html doc and make it a nice layout there plugging in the variables that are going to be used in the script. Then once I have the layout and everything looks good in that html doc, I then copy and paste the table's code from there into the body var in this mail script. Make sure you concatenate all the vars in the $body.

 

As far as gathering the product info for this mail script you will need to do a few queries to grab the info you want using the sessions. But it sounds like you have a good handle on this part of it.

 

Enjoy!

 

Nate

Link to comment
Share on other sites

Read more at the PHP docs - http://www.php.net/session

 

Simply start a session on every page allowing you to access the $_SESSION vars on any page where the session is started. And when the user submits the form save the products to an array or something similar. You can also store their information in the $_SESSION variable (persistent through pages) until they verify the purchase and decided to receive the email.

 

<?php
//starts session, MUST be called before sending ANY text to the screen
session_start();
//setting Super global session variable ball to true
$_SESSION["products"]["ball"] = true;
?>

Link to comment
Share on other sites

Yeah, the virtual cart is simply the sessions. The cart would be comprised of product id's or something unique to each item in the "cart". e.g.

 

<?php

session_start();
$_SESSION['products'][] = 23;
$_SESSION['products'][] = 5;


?>

 

With this you could have a display, "Your Cart has <?=count($_SESSION['products']) ?> Items", which would return... Your Cart has 2 items.

 

In this scenario, I am storing the "product id's " in a session array called products. This is the quick and dirty of it, hope it helps.

Link to comment
Share on other sites

  • 3 years later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.