PHP Script for updating Shopping Cart

Displaying Cart to add, remove and update products
Backend PHP Script to add, remove and update products
This page will only display the products with quantity and price which are in our shopping cart. From this page nothing can be added or removed from the cart. We will first loop through all the products in our product table. While looping through records if the product is there in our shopping cart then we will display that product details along with quantity.
$q="SELECT p_id,price,img,p_name FROM plus2_cart_products";
$result_set = $connection->query($q);
echo "<div class='row'>
<div class='col-md-7 offset-md-1'>
  <table class='table my_table'>
<tr class='info'><th>Picture</th> <th> ID</th><th>Name</th><th>Quantity</th><th>Unit Price</th><th>Price</th></tr>";
$price_total=0;
while($row = $result_set->fetch_array(MYSQLI_ASSOC)){
foreach ($_SESSION['cart'] as $key => $val) {
       if($row[p_id]=== $_SESSION['cart'][$key]['p_id']){
$price_sub=$_SESSION['cart'][$key]['qty'] * $row[price];
echo "<tr><td ><img src=images/$row[img] class=rounded></td><td>$row[p_id]</td><td >$row[p_name]</td><td>".$_SESSION['cart'][$key]['qty']."</td><td >$row[price] </td><td >$price_sub </td></tr>";
$price_total=$price_total + $price_sub;
	   }
   }

}

Sub total price and total price

We will take quantity from the session array for the product and multiply it with unit price of the product to display sub total price. We will sum up the sub total price to arrive at total price.

We can add percentage of total price as tax, delivery charges to the total price and show the final price to the customer.
$price_tax=round(.1 * $price_total,2);
$price_other = round(0.08 * $price_total,2);
$price_grand=round($price_total + $price_tax + $price_other,2);
To keep it simple we are not adding payment process to this script. You can add like sign up or delivery address to the user and ask them to proceed for payment.

Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com




    Post your comments , suggestion , error , requirements etc here .




    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer