Jump to content

Simple Shopping Cart scripts


zacthespack

Recommended Posts

I'm looking for a simple shopping cart system for my site to do away with the order form I use at the moment. I have been updating the site which now links each page of products on the site to a mysql table of those products so that I can then export my product data from my sage system straight to the website.

What I need is a way for a button to display next to each product that once clicked adds said product to a shopping cart, along with how many of the product the customer wants. the customer once finished then 'checks out' adding there contact information etc. to the order and the order is then sent to my via email.

The tricky part is I do not wish payment to be taken this 'shopping cart' would be used just to take orders which will then be processed and paid at a later date.

Any help would be great!

Thanks

Zac

Link to comment
Share on other sites

why not just store product id's and quantities in a $_SESSION variable, and display them on a 'shopping cart' page? Then on checkout, they get emailed (or placed in a database) for later processing.

 

the site is question is http://www2.acehireltd.co.uk/ we have a very large list of products and so could not simple display them all on one checkout page

Link to comment
Share on other sites

???? you only display the products the client actually wants to buy, not ALL of them. Unless you have clients buying 2000 different products at a time, this shouldn't be a problem.

OK sorry I misunderstood you, my problem is how to set up the checkout as all online help and free systems want payment to be taken at the end or require all the products in one table etc.

Link to comment
Share on other sites

will depend on what you want to do on checkout. You can just make the checkout button send you an email with the order, you can make it store the order in a database and then send you an email just saying there's a new order, whatever you want. Think simple: It's just a button that can point to any script you want.

Link to comment
Share on other sites

will depend on what you want to do on checkout. You can just make the checkout button send you an email with the order, you can make it store the order in a database and then send you an email just saying there's a new order, whatever you want. Think simple: It's just a button that can point to any script you want.

 

OK so what I want it to do is, the user presses the button this adds that item to a shopping basket, user can then keep going through the site adding more products then goes to 'check out' at which point they say how many they want, and add in there personal information (address contact number email etc etc) and then submit the order, which gets sent to a email address.

Link to comment
Share on other sites

ok, cool. start coding, then post your code here and we'll help fix problems.

Thats the problem, I know how to set up the button next to the product sure, but I don't know where to start with the PHP need to select the product info next to the button and put it into the shopping cart

Link to comment
Share on other sites

oh dear...

 

Well, you've got to start somewhere...

 

post item details (unique product id and quantity) to a script that will just add them to a $_SESSION array. You can call it something like $_SESSION['shoppingCart'].

 

then create a standalone page that just prints out the values, so you can check if everything is being added correctly.

something like:

<?php
session_start()
echo '<pre>';
print_r($_SESSION['shoppingCart']);
?>

Link to comment
Share on other sites

Ok sorry can we start with the button, this is the php I have used to create the table on the website to view the products from the database

<?php
mysql_connect('localhost', '******', '*********') or die (mysql_error());
mysql_select_db('acehire1_sage') or die (mysql_error());
$result = mysql_query("SELECT * from BBQ LIMIT 0, 12");
//Table starting tag and header cells
echo "<table width='650' border='0'><tr bgcolor='#adadad' align='center' valign='top'><th width='65'>Hire Code</th><th width='90'>Picture <font size='2'>(click to enlarge)</font></th><th width='300'>Product Description</th><th width='80'>Hire Cost<br><font size='2'>(Excl. VAT)</font>.</th>";
while($row = mysql_fetch_array($result)){
   //Display the results in different cells
   echo "<tr align='center' valign='top' bgcolor='#f0f0f0'><td>" . $row['productcode'] . 
   "</td><td><a href='images/" . $row['picturelg'] . "'><img src='images/" 
   . $row['picture'] . "' alt='image'  /></a> </td><td>" . $row['description'] . "</td><td>£" . $row['salesprice'] . "</td><td>"  . "</td></tr>";
}
//Table closing tag
echo "</table>";
?>

This is for this page http://www2.acehireltd.co.uk/bbq so the button will go in the last table column but the link to post the product information to the shopping basket would need to be generated as the information is not static?

Link to comment
Share on other sites

add the buttons, add the link (for now point it to a page called addToCart.php) and add a productID to the generated url with the value of $row['productcode'].

 

in addToCart.php just do this for now:

<?php
session_start();
if(!isset($_SESSION['shoppingCart']){
   $_SESSION['shoppingCart'] = array();
}
$_SESSION['shoppingCart'][] = $_GET['productID'];
// add a redirect script back to the page you were here ---
?>

 

(I'm showing you a simple way of doing things, just to get you on the right track. Later you will need to implement a few more things, checks, security checks, etc... Also, you'll need to add quantities. But since you seem to know very little about php, I though it would be best to start really simple.)

 

at any time, sizeof($_SESSION['shoppingCart']) will tell you the amount of items in there.

 

Link to comment
Share on other sites

OK so I have done this

<?php
mysql_connect('localhost', 'acehire1_user', 'Authors1') or die (mysql_error());
mysql_select_db('acehire1_sage') or die (mysql_error());
$result = mysql_query("SELECT * from BBQ LIMIT 0, 12");
//Table starting tag and header cells
echo "<table width='650' border='0'><tr bgcolor='#adadad' align='center' valign='top'><th width='65'>Hire Code</th><th width='90'>Picture <font size='2'>(click to enlarge)</font></th><th width='300'>Product Description</th><th width='80'>Hire Cost<br><font size='2'>(Excl. VAT)</font>.</th>";
while($row = mysql_fetch_array($result)){
   //Display the results in different cells
   echo "<tr align='center' valign='top' bgcolor='#f0f0f0'><td>" . $row['productcode'] . 
   "</td><td><a href='images/" . $row['picturelg'] . "'><img src='images/" 
   . $row['picture'] . "' alt='image'  /></a> </td><td>" . $row['description'] . "</td><td>£" . $row['salesprice'] . 
   "</td><td><a href="../addToCart.php">Add</a>"  . "</td></tr>";
}
//Table closing tag
echo "</table>";
?>

However now i get an error on the page "Parse error: syntax error, unexpected '.' in /home/acehire1/public_html/www2/bbq/index.php on line 135", im guessing its because of the ../addToCart.php ? is so how can i link it without php braking

Link to comment
Share on other sites

I can tell you know absolutely nothing about php... How do you expect to accomplish this shopping task?

 

echo "<tr align='center' valign='top' bgcolor='#f0f0f0'><td>" . $row['productcode'] . 
   "</td><td><a href='images/" . $row['picturelg'] . "'><img src='images/" 
   . $row['picture'] . "' alt='image'  /></a> </td><td>" . $row['description'] . "</td><td>£" . $row['salesprice'] . 
   "</td><td><a href="../addToCart.php">Add</a>"  . "</td></tr>";

 

should be

 

echo "<tr align='center' valign='top' bgcolor='#f0f0f0'><td>" . $row['productcode'] . 
   "</td><td><a href='images/" . $row['picturelg'] . "'><img src='images/" 
   . $row['picture'] . "' alt='image'  /></a> </td><td>" . $row['description'] . "</td><td>£" . $row['salesprice'] . 
   "</td><td><a href='../addToCart.php'>Add</a>"  . "</td></tr>";

Link to comment
Share on other sites

man, I have no answer for that. Weather or not you should 'bother' is your choice.

 

If you seriously want to code a shopping cart (even just a simple one) you will have to read up a bit more on php. understand how the basics work, the differences between double and single quotes, how to escape characters (and when/why), how variables work, how arrays work, how sessions work, how loops work, how conditions work, and how to send emails.

(off the top of my head, the above mentioned should be enough skills for this simple project)

Link to comment
Share on other sites

man, I have no answer for that. Weather or not you should 'bother' is your choice.

 

If you seriously want to code a shopping cart (even just a simple one) you will have to read up a bit more on php. understand how the basics work, the differences between double and single quotes, how to escape characters (and when/why), how variables work, how arrays work, how sessions work, how loops work, how conditions work, and how to send emails.

(off the top of my head, the above mentioned should be enough skills for this simple project)

 

Ok thank you, I shall look up some guides on this and learn what I can, sorry for wasting your time and thank you for the help

Link to comment
Share on other sites

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.