Solved

Dynamic Shopping Cart

Posted on 2011-03-01
5
1,357 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

759 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