Solved

Dynamic Shopping Cart

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

Industry Leaders: 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

This article discusses four methods for overlaying images in a container on a web page
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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 …

617 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