PHP Shopping Cart System – Download source code


Are you trying to learn how to build your own PHP shopping cart system? Do you need quick guidance and support while doing it? You’re in the right place.

Google defines the word “system” as a set of connected parts forming a complex whole. We say this “PHP shopping cart source code” is a “system” because of that definition.

Each module of this source code is designed to be very simple and easy to understand. It is based on our PHP OOP CRUD Tutorial and PHP shopping cart tutorial.

You will be able to build a complex web application before you know it. You’ll never get lost. It is your advantage. You can use the same knowledge to build another type of web application.

We are here to help you with anything you do not understand in this source code.

Download and learn how this PHP Shopping Cart System was made. Technologies used include PHP, MySQL, CSS, JavaScript, Bootstrap, Object-oriented programming, and more.

This project is not perfect. It is designed to be simple. This is a very good starting point for your development.

Output Preview

Below are some screenshots of our script’s output. Please note that the following images are just output previews. New features might be added already the time you are reading this.

Index page
Login page
Admin page and menus
User page and menus

Is This Code For Me?

The source code on this page is NOT for you if:

  • You are already an expert in PHP & MySQL programming.
  • You have a lot of time to code the listed features below.
  • You are not really interested in learning PHP & MySQL programming.

But, this source code is FOR YOU if:

  • You want to SAVE a significant amount of development time.
  • You want to develop your own PHP shopping cart system from scratch.
  • You determined to learn how to make a a web application in PHP & MySQL.
  • You need some guidance in learning about this script.

But if you are an expert in PHP & MySQL programming and would like to take a look at our code, please do so! We’d love to hear your response and great insights! The comments section below is always open for anyone with questions and suggestions.

Pre-Requisites

Before you download, make sure you have a basic understanding of these topics:

Features

Admin features

The table below shows the features an admin can do in the system.

ADMIN FEATURES
User Management
Create, read, update, delete, and search users with pagination
Deleting the first administrator account is not allowed
Valid email format required
Password must be an uppercase letter, lowercase letter, number, and special character
Confirm password field
Password validation as you type
View customer order history
Login page, sign up page, logout user
Edit profile of currently logged in user
Show name of currently logged in user
Forgot password page – the system can send unique reset password link via email
Reset password page – user can click the unique verification link and reset his password
Product Management
Create, read, update, delete, and search products with pagination
View inactive products
View products under a category with pagination
Upload product images, you can select many images at once
View product images with thumbnails
Delete product image with the X icon
Upload product PDFs, you can select many PDF files at once
List and delete product PDF
Rich text editor for product description when adding or editing product
Sorting by fields
Variation Management
Set variation name, price, and stocks
Stocks or inventory decreases when an order has been placed
Increase stock by updating the variation
Create, read, update, and delete variations
Category Management
Create, read, update, delete, and search categories with pagination
View products under a product category
Auto-update category drop-down in create or update product form
Auto-update categories in the navigation bar
Highlight the selected category in the navigation
Order Management
View order history of a customer
View pending and completed orders in separate tabs
Pagination on the list of orders
Latest order is seen at the top of the list
View details of an order
Compute the total cost of the order
Change status of an order (pending or completed)
Web Page Management
Create, read, update, delete, and search web pages with pagination
Pages search result with pagination
Rich text editor enabled
Contact Management
Display list of messages with pagination
Read and delete a message
Message list with pagination
Search message with pagination

Customer features

The table below shows the features a customer can do in the system.

CUSTOMER FEATURES
User Management
Valid email format required
Password must be an uppercase letter, lowercase letter, number, and special character
Confirm password field
Password validation as you type
Login page, signup page, and logout function
Edit profile of currently logged in user
Show name of currently logged in user
Forgot password – the system can send unique reset password link via email
Forgot password – user can click the unique verification link and reset his password
Product Management
Search products with pagination
View products under a category with pagination
View product images with thumbnails
View single product with related information, add to cart button, and image slider
Product page with SEO friendly URL (.htaccess file used)
Quantity value must be a number equal to or greater than 1
Category Management
View products under a product category
Highlight selected category in the navigation bar
Order Management
Make an order
Auto-generated unique transaction ID
Add to cart button (for each item) with specified quantity
Cart page with a list of products added to cart
Update quantity button for each product in cart
Compute total and grand total on the cart page
Remove from cart button for each product in the cart
Empty cart button to remove all products in the cart
View order history
A checkout page with billing information
Edit billing information button on the checkout page
Show payment information on the checkout page
Payment via cash on delivery or PayPal
Place order page – Thank you message
View list of orders with pagination
View details of an order
Web Page Management
Read web pages created by the admin
Contact Management
Send a message to Admin
Display other ways to contact Admin

Developer features

The table below shows the developer features of the source code.

Object-oriented programming source code
Bootstrap user interface
PDO extension used
Source code files organized by folders
The database configuration file in the config folder
One-time payment, no recurring payment
Hashed password stored in the database
Login user with hashed password validation
Used PDO bindParam() to prevent SQL injection attacks
Used PHP htmlspecialchars() to prevent XSS attacks
Free support and updates for 1 year

Download source code

Download our source code based on how many times you plan on using it. You can choose to download “1 website” if you’re using this only once. You can also choose the 5 or 10 websites options.

What People Say

Here are some of the things people say about our source code downloads.

“Wow, I love you guys! The best web programming tutorial I’ve ever seen. So comprehensive, yet easy to follow. I love how you combine all necessary elements in such a neat structure.” ~ Olaug Nessa

“The fact that you’ve put it all together saves so much time and its worth buying the code. Makes me feel good supporting a developer like yourself. Keep up the good work!” ~ Dan Hudson

“Thanks for making these awesome tutorials! I bought your source codes. To be honest, it’s very readable code and helps me understand a lot of things and how it’s done in PHP. Thanks for that again.” ~ Michael Lammens

Cart Data Storage

This source code takes advantage of PHP SESSIONS, PHP COOKIES, and MySQL when storing cart data.

  • We use PHP COOKIES to save the site visitor’s user_id locally.
  • We use PHP SESSIONS as back up just in case cookies are disabled in the user’s browser.
  • We use MySQL to store cart items in the database.
  • This way, cart items can be resurrected even if the user closed his browser, logged out or logged in another computer.

Here’s the logic:

IF cookies are enabled, AND if user is logged in, we save ‘session user_id’ to ‘user_id variable’. The value of ‘user_id variable’ is very important because we use it to save ‘user_id’ both in PHP ‘cookie’ and ‘session’.

IF cookies are enabled, AND if user is not logged in, AND if user already have a ‘cookie user_id’ token, we save ‘cookie user_id’ to ‘user_id variable’.

IF cookies are enabled, AND if user is not logged in, AND if ‘cookie user_id’ is not set (it means, visitor never used the cart before), we get new token as ‘user_id variable’ value.

IF cookies are enabled, AND user is logged in OR not logged in, we set ‘cookie user_id’ and ‘session user_id’ with the final ‘user_id variable’ value. This will retrieve the cart data with the same ‘user_id’ from MySQL database.

IF cookies are disabled, AND user is logged in, we maintain ‘session user_id’.

IF cookies are disabled, AND user is not logged in, we get new token and save it to ‘session user_id’.

Important Note: The statements above can be understood more clearly if you will see the code implementation on /config/core.php line 26 onwards.

Database Design

Our database name will be “shop_cart_complete”, and we will have twelve (12) tables.
database-design-php-shopping-cart-source-code

Simple Set Up

You can run this source code successfully with a few easy steps.

Run the Home Page

I assume you are installing this source code on localhost. In my case, I installed this code in this directory:

The reason for these multiple folders is that I have many projects and I need to organize them this way. I can access the system in this URL: http://localhost/CodeOfaNinja/SourceCodes/Systems/ShoppingCartSystem/

You will see an error, that’s why we need to do the following steps.

1. In your PhpMyAdmin, create a database with the name “shopping_cart_system”.

2. Import the “shopping_cart_system.sql” SQL file from the “dev” folder.

3. Change the rewrite base directory in line 7 of the .htaccess file.

RewriteBase RewriteBase /CodeOfaNinja/SourceCodes/Systems/ShoppingCartSystem/

4. Configure $home_url in line 72 of /config/core.php

$home_url = "http://localhost/CodeOfaNinja/SourceCodes/Systems/ShoppingCartSystem/";

5. Configure database in /config/database.php, example settings would look like:

// specify your own database credentials
private $host = "localhost";
private $db_name = "shopping_cart_system";
private $username = "root";
private $password = "";
public $conn;

6. Try to log in by running the login page.

http://localhost/CodeOfaNinja/SourceCodes/Systems/ShoppingCartSystem/login

Use the following login credentials.

Admin Section Login
Username: [email protected]
Password: [email protected]

Customer Account Login
Username: [email protected]
Password: [email protected]

How To Set Up / Enable Auto Return?

With Auto Return for PayPal Website Payments, your buyers are redirected back to your site immediately after clicking the Pay button on the Payment Confirmation page.

Your buyers enjoy a streamlined checkout experience and are returned back to your site quickly!

1. Enable Auto Return In Your Test / Sandbox Account.

  1. Log into https://developer.paypal.com
  2. Click Applications
  3. Click Sandbox accounts
  4. Expand the account in question
  5. Click Sandbox site
  6. Login to the test account
  7. Copy and paste “https://www.sandbox.paypal.com/us/cgi-bin/webscr?cmd=_profile-website-payments” into your browser
  8. Enable Auto Return and click Save
  9. Enter the Auto Return URL and click Save

[Reference]

2. Setting Up Auto Return On Your Official / Real PayPal Account

  1. Log in and click the Profile subtab under My Account.
  2. Click the Website Payment Preferences link under Selling Preferences.
  3. Click the On radio button to enable Auto Return.
  4. Enter the Return URL. Note: You must meet the Return URL requirements in order to set up Auto Return. Learn more about Return URL.

[Reference]

3. How To Disable Sandbox Mode?

This source code is in sandbox mode by default, it means any PayPal transactions are for testing purposes only. To disable the PayPal Sandbox mode:

Open /libs/php/paypal_checkout.php

Change line 51, from

$form='<form id="paypal_checkout" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">';

to

$form='<form id="paypal_checkout" action="https://www.paypal.com/cgi-bin/webscr" method="post">';

Change the email address (line 5) to your real PayPal account email address. Payment will be sent to the specified PayPal account.

How To Make TinyMCE File Manager / File Browser Work?

1. Change line 71 of /libs/js/responsive_filemanager/filemanager/config/config.php

'upload_dir' => '/YOUR_ROOT_DIRECTORY/libs/js/responsive_filemanager/source/',

2. Change line 42-43 of /admin/layout_foot.php

external_filemanager_path:"/YOUR_ROOT_DIRECTORY/libs/js/responsive_filemanager/filemanager/",
external_plugins: { "filemanager" : "/YOUR_ROOT_DIRECTORY/libs/js/responsive_filemanager/filemanager/plugin.min.js"},

Some More Notes

1. This system works with PHP 5.5+

2. Rewrite module must be enabled in your apache server (this is enabled by default in most web servers and localhost)

Related Source Code Modules


You can download the PHP SHOPPING CART SYSTEM by modules. Learn more by clicking any 'View Module' button below.


Modules Action
PHP Login & Registration Module
PHP Shopping Cart Module
PHP Product Catalog Module
PHP Content Management Module
PHP Contact Form Module
PHP PayPal Integration Module

Get In Touch

Contact me if you have any questions about the code, I’ll be more than happy to help and support you! My email is [email protected].

Please subscribe as well to receive news and updates about our source codes and free tutorials. Fill out the form below. CLICK HERE TO SUBSCRIBE!

Thank you for visiting our PHP shopping cart source code download page!

By Mike Dalisay

I'm Mike Dalisay, a pro web developer since 2010. I love web development. Improving our tutorials and source codes makes me happy. Do you want to suggest an edit to our tutorial? Got something to ask about our source codes? You may use our comments section below or email our team at [email protected]

7 comments

  1. It appears that if you wanted to by more than one variation of the same product it is not supported. i.e. a Large and a Medium of the same product cannot be added to your cart.

    1. Hello @disqus_HEaqWy3Omz , you are correct. That feature is not yet included in our script. To send orders of the same product with different variation, the customer should place different orders.

      1. That can be true. But it depends on the business. Many eCommerce sites offer shipping for free.

        Anyway, the script can be modified and developed to fit your needs. The idea is to learn and apply the coding skills obtained from our tutorials.

        See the links from our pre-requisites (section 4.0) above.

  2. Looks good, Question is the foreign key relationship for the “pages” to “Users” missing in diagram above?

Leave a comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back to top