Advance Shopping Cart using PHP Free Source Code

Language

Introduction

This is an Advance Shopping Cart Application source code developed in PHP Language. The main purpose of this shopping cart application is to provide the students or those programmers who are new to PHP with a reference to understand and have an Idea of how to develop an advanced shopping cart for their eCommerce or Online Shops/Store projects. With this, you will learn one of the techniques or ways for managing shopping carts on the backend.

What is Shopping Cart?

An eCommerce Shopping Cart is a part of a software or an application that allows the customers or possible customers of a certain shop or business to store the list of Items or products they wanted to check out at once after they completed browsing the products.

About Shopping Cart source code

This advanced shopping cart application was developed using PHP and MySQL Database. The database and sample product data are automatically created upon running or installing the source code. Shopping carts are stored using the PHP Session. Users can simply click the "Add to Cart" button and the selected product item will be listed on the cart list in session. When the product is already on the list, the item on the cart quantity will be updated. On the shopping cart list page, customers can manage the items (update quantity and remove items).

Here's The Sample Snippet used on this Shopping Cart Source Code

  1. <?php
  2. if (isset($_POST['add'])){
  3. /// print_r($_POST['product_id']);
  4. if(isset($_SESSION['cart'])){
  5.  
  6. if(in_array($_POST['product_id'], array_keys($_SESSION['cart']))){
  7. $_SESSION['cart'][$_POST['product_id']] += 1;
  8. header("location: ./");
  9. }else{
  10. // Create new session variable
  11. $_SESSION['cart'][$_POST['product_id']] = 1;
  12. // print_r($_SESSION['cart']);
  13. header("location: ./");
  14. }
  15.  
  16. }else{
  17. // Create new session variable
  18. $_SESSION['cart'][$_POST['product_id']] = 1;
  19. // print_r($_SESSION['cart']);
  20. header("location: ./");
  21. }
  22. }
  23. ?>

The above snippet is the script used for saving or storing the product using PHP Session upon clicking the "Add to Cart" button.

  1. <?php
  2. if (isset($_GET['action']) && $_GET['action'] == 'removeItem'){
  3. unset($_SESSION['cart'][$_GET['id']]);
  4. echo "<script>alert('Product has been Removed from Shopping Cart')</script>";
  5. echo "<script>window.location = 'cart.php'</script>";
  6. }
  7. if(isset($_GET['action']) && $_GET['action'] == "update_qty"){
  8. $pid = $_GET['pid'];
  9. $operation = $_GET['operation'];
  10. if($operation == "add"){
  11. $_SESSION['cart'][$pid] += 1;
  12. }else{
  13. if($_SESSION['cart'][$pid] > 1)
  14. {
  15. $_SESSION['cart'][$pid] -= 1;
  16. }
  17. }
  18. header('location: ./cart.php');
  19. }
  20.  
  21. ?>

The snippet above is the PHP script used of removing the Items on the cart list and updating the item quantity.

Technology used:

  • HTML
  • CSS
  • Boostrap
  • PHP
  • MySQL Database
  • Font-awesome

Features

  • List Products
  • Add Product to Shopping Cart
  • Shopping Cart Item Count
  • Shopping Cart List Page
  • Update Item Quantity in Cart List
  • Remove Item from Cart List
  • Total Payable Summary Panel

Sample Snapshots

Product List Page

Shopping Cart List Page

How to Run?

Download Install the ff:

  • Download and Install any virtual server such as XAMPP/WAMP to run PHP Scripts and for MySQL Database.
  • Download the provided source code zip file. (download button is located after this article)

Installation

  • Open your XAMPP/WAMP's Control Panel and start the Apache and MySQL servers.
  • Extract the download source zip file.
  • Copy the source code folder into the XAMPP's "htdocs" directory. If you are using WAMP, paste the source code into the "www" directory.
  • Locate the Database.php file inside the "inc" folder in the source code directory and open it with your preferred text editor. Configure the database credentials on the file according to your setup.
  • Run the Advance Shopping Cart on your browser. i.e [http://localhost/adv_shopping_cart]

The database, table, and sample data will be automatically created when running the application for the first time.

Demo Video

That's it! You can test and explore the features and functionalities of this Shopping Cart Application in PHP on your local machine. I hope this will help you with what you are looking for and that you'll find it useful for your current and future projects.

Explore more on this website for more Tutorials and Free Source Codes.

Enjoy :)

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Add new comment

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.
3 + 3 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.