Solved

Dynamic Shopping Cart

Posted on 2011-03-01
5
1,356 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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.

828 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