Solved

Dynamic Shopping Cart

Posted on 2011-03-01
5
1,353 Views
Last Modified: 2012-05-11
Hi,

I was looking for inspiration to design and implement a simple dynamic shopping cart. This will be a add-on to a existing system.

Some of the possible features I want to include are:

- Dynamic table where data is pulled from mysql database
- User can add/remove products and change quantity
- Value are updated in real-time on-screen (possibly using jquery or ajax)
- Checkout page on submission

Any code snippets/ links or ideas would be greatly appreciated.

Thanks in advance.
0
Comment
Question by:abdulv
  • 2
  • 2
5 Comments
 
LVL 3

Expert Comment

by:wwwdeveloper2
ID: 35014075
Have you looked at the free open source solutions out there that have all of those features you mentioned plus many more?

Here is a run down of a top 10:
http://www.100webhosting.com/best-open-source-shopping-carts/

You can install them your self, or many hosting companies offer them as a install for free through hosting applications such as cpanel.

If you have questions, let me know.
0
 

Author Comment

by:abdulv
ID: 35019299
I am aware of there open source solutions and I have a cpanel setup on my web server.

I was looking very basic script example to add to a existing system. One were users can click and add a product and it shows the total on the same page.

Would I have to use jQuery or javascript to achieve this?
0
 
LVL 3

Expert Comment

by:wwwdeveloper2
ID: 35026143
Can you give more details about your existing system?  Any code examples of the page you currently have that you want to add this to would be extremely helpful.
0
 
LVL 1

Accepted Solution

by:
Defne_ earned 500 total points
ID: 35031883
Hi;  
This snippet might help you. This only adds the product id and the amount to session (as array) and the function displays the total with ajax.

 
//ON PAGE
<div id="cart">the result will be here</div>
<input type="button" value=" " class="addToCart" onClick="window.scrollTo(0,50); addToCart('.$product_id.',1);">   

//Input  calls the Ajax script:

  <script type="text/javascript">
function addToCart_js(id,num)
{
	
	var div="cart";
	if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
	document.getElementById(div).innerHTML=xmlhttp.responseText;
	}
  }

xmlhttp.open("GET","cart.php&function=addToChart&id="+id+"&num="+num+"",true);
xmlhttp.send();
}
</script>

//cart.php  Than the script goes to following function :


function addToCart()
{
	$id=$_GET['id'];
	$num=$_GET['num'];

	$customer_id=$_SESSION['customer_id'];

//cart session array declared with customer_id and holds product id(key) and the amount(value)
		if(array_key_exists($id,$_SESSION[$customer_id]))
		{
			$num=$num+$_SESSION["p".$customer_id][$id];
			
		}
$_SESSION[$customer_id][$id]=$num;

foreach($_SESSION[$customer_id] as $key => $value)
	{
	 $toplam_num+=$value;
	}
//YOUR RESULT:
	echo '<div class="cart"><a href="?page=cart" >
<p class="text">Your Cart : '.$total.' </p>
         </div></a>';


}

Open in new window

0
 

Author Closing Comment

by:abdulv
ID: 35043909
Thanks
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now