Today, We want to share with you Simple Ecommerce PHP Shopping Cart Example.
In this post we will show you simple shopping cart php code, hear for php simple ecommerce script we will give you demo and example for implement.
In this post, we will learn about how to create simple shopping cart in php with an example.
Simple Ecommerce PHP Shopping Cart source
There are the Following The simple About Simple Ecommerce PHP Shopping Cart source Full Information With Example and source code.
PHP Shopping Cart Software Development Overview
As I will cover this Post with live Working example to develop Simple PHP Shopping Cart, so the some major files and Directory File Structure for this example is following below.let’s make a simple OOP PHP shopping cart web Application with MySQL
- index.php
- dbcontroller.php
- style.css
product-images – Directory
We have buield a dynamic and custom shopping cart application Item gallery by displaying all Items results from MySQL database display table using PHP Example.
Database Product Table for Shopping Cart
Table Name : item_table
CREATE TABLE IF NOT EXISTS `item_table` ( `id` int(8) NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, `code` varchar(255) NOT NULL, `image` text NOT NULL, `price` double(10,2) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `product_code` (`code`) ) INSERT INTO `item_table` (`id`, `name`, `code`, `image`, `price`) VALUES (1, '4D Live Camera', '3DcAM01', 'item-images/live-camera.jpg', 1500.00), (2, 'External Pen Drive', 'USB02', 'item-images/external-pen-drive.jpg', 800.00), (3, 'Mobile MI 8', 'wristWear03', 'item-images/mobile-mi-8.jpg', 300.00);
Making Product Gallery for Shopping Cart
index.php
This is where I will make a simple HTML form and PHP server side source code for our web application. To make the forms simply all souce code copy and write it into your any text editor Like Notepad++, then save file it as index.php.
runQuery("SELECT * FROM item_table WHERE code='" . $_GET["code"] . "'"); $itemArray = array($codeByItem[0]["code"]=>array('name'=>$codeByItem[0]["name"], 'code'=>$codeByItem[0]["code"], 'product_qty'=>$_POST["product_qty"], 'price'=>$codeByItem[0]["price"])); if(!empty($_SESSION["product_cart"])) { if(in_array($codeByItem[0]["code"],array_keys($_SESSION["product_cart"]))) { foreach($_SESSION["product_cart"] as $k => $v) { if($codeByItem[0]["code"] == $k) { if(empty($_SESSION["product_cart"][$k]["product_qty"])) { $_SESSION["product_cart"][$k]["product_qty"] = 0; } $_SESSION["product_cart"][$k]["product_qty"] += $_POST["product_qty"]; } } } else { $_SESSION["product_cart"] = array_merge($_SESSION["product_cart"],$itemArray); } } else { $_SESSION["product_cart"] = $itemArray; } } break; case "remove": if(!empty($_SESSION["product_cart"])) { foreach($_SESSION["product_cart"] as $k => $v) { if($_GET["code"] == $k) unset($_SESSION["product_cart"][$k]); if(empty($_SESSION["product_cart"])) unset($_SESSION["product_cart"]); } } break; case "empty": unset($_SESSION["product_cart"]); break; } } ?>Simple PHP with Session Shopping Cart Shopping Cart Empty Cart
Name Code Quantity Price Action <a href="index.php?action=remove&code=" class="btnRemoveAction">Remove Item Total: ProductsrunQuery("SELECT * FROM item_table ORDER BY id ASC"); if (!empty($arrat_items_all)) { foreach($arrat_items_all as $key=>$value){ ?><form method="post" action="index.php?action=add&code="><img src="">
Best online shopping cart for small business
dbcontroller.php
conn = $this->connectDB(); } function connectDB() { $conn = mysqli_connect($this->host,$this->user,$this->password,$this->database); return $conn; } function runQuery($query) { $result = mysqli_query($this->conn,$query); while($row=mysqli_fetch_assoc($result)) { $resultset[] = $row; } if(!empty($resultset)) return $resultset; } function numRows($query) { $result = mysqli_query($this->conn,$query); $rowcount = mysqli_num_rows($result); return $rowcount; } } ?>
style.css
body{width:610px;font-family:calibri;} #cart-live-shopping table{width:100%;background-color:#F5F5F5;} #cart-live-shopping table td{background-color:#FFFFFF;} .txt-shopping-header{ padding: 10px 10px; border-radius: 1px; color: #FFFFFF; background: #6aadf1; margin-bottom:10px; } a.btnRemoveAction{color:#D60202;border:0;padding:1px 10px;font-size:0.9em;} a.btnRemoveAction:visited{color:#D60202;border:0;padding:1px 10px;font-size:0.9em;} #clearButton { background-color: #3d3d3d; border-radius: 4px; border: #FFFFFF 1px solid; color: #ff0000; float: right; font-size: 0.8em; padding: 1px 10px; text-decoration: none; } .insertItemBtn{ background-color: #eb9e4f; border: 0; padding: 3px 10px; color: #3d3d3d; margin-left: 1px; border-radius: 1px; } #cart-live-shopping {margin-bottom:30px;} .cart-item {border-bottom: #79b946 1px dotted;padding: 10px;} #item-grid-card {margin-bottom:30px;} .product-item { float:left; background: #3d3d3d;margin:15px 10px; padding:5px;border:#CCC 1px solid;border-radius:4px;} .product-item div{text-align:center; margin:10px;} .item-price-card { color: #005dbb; font-weight: 600; } .product-image {height:100px;background-color:#FFFFFF;} .clear-float{clear:both;} .demo-input-box{border-radius:1px;border:#CCC 1px solid;padding:1px 1px;}
Simple PHP Shopping Cart – Output
Angular 6 CRUD Operations Application Tutorials
Read :
Summary
You can also read about AngularJS, ASP.NET, VueJs, PHP.
I hope you get an idea about best online shopping cart for small business.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.