Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Dynamic Shopping Cart

Posted on 2011-03-01
5
Medium Priority
?
1,362 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 1500 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

Independent Software Vendors: 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

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…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

916 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