📁 File Manager
Editing:
/home/wedigitalindia/public_html/demo.wedigitalindia.com/bbhealthy.in/carts.php
<?php session_start(); include 'config.php'; if (!isset($_COOKIE["shopping_user"])) { header("location:login"); } if(isset($_POST['update'])){ $qty = $_POST['quant']; function updateQuantity($productId, $quantity) { if (isset($_SESSION['cart'][$productId])) { if ($quantity > 0) { $_SESSION['cart'][$productId]['quantity'] = $quantity; } else { unset($_SESSION['cart'][$productId]); } } } foreach ($qty as $productId => $p_det) { $quantity = addslashes(trim($p_det['qty'])); updateQuantity($productId, $quantity); } // header("Location: ".$_SERVER['PHP_SELF']); header("location:checkout"); } ?> <!DOCTYPE html> <html lang="en"> <head> <?php include_once("assets/include/head.php")?> <style> table { width: 100%; border-collapse: collapse; margin-bottom: 20px; } table, th, td { border: 1px solid black; padding: 8px; text-align: center; } th { background-color: #438626; color: #fff; } .apan { padding-left: 10px; padding-right: 10px; } </style> </head> <body> <div id="main"> <?php include_once("assets/include/header.php")?> <div class="cart-main-area mtb-60px"> <div class="container"> <h3 class="cart-page-title text-center"><b>Cart Items</b></h3> </div> </div> <div class="container"> <form id="updateCartForm" method="POST" action=""> <table id="cart"> <thead> <tr> <th>Product</th> <th>Price</th> <th>Quantity</th> <th>Subtotal</th> <th>Remove</th> </tr> </thead> <tbody id="cart-body"> <?php $a = 0; $count = 1; foreach ($_SESSION['cart'] as $pid => $value) { $que = mysqli_query($con, "SELECT * FROM tbl_product where p_id='$pid'"); $row1 = mysqli_fetch_array($que); ?> <tr data-id="<?php echo $pid; ?>"> <td><img src="<?php path() ?>/assets/images/product-image/<?php echo $value['image']; ?>" style="width: 100px; height: 100px;" alt=""> <a href="#" style="color: #000;"><?php echo $row1['p_name']; ?></a></td> <td><b id="price<?php echo $count; ?>"><?php echo $row1['p_current_price']; ?></b></td> <td> <button type="button" onclick="decreaseQuantity(<?php echo $count; ?>)" class="btn btn-success">-</button> <span class="apan" id="quantity<?php echo $count; ?>"><?php echo $value['quantity']; ?></span> <input type="hidden" name="quant[<?php echo $pid; ?>][qty]" id="inputQuantity<?php echo $count; ?>" value="<?php echo $value['quantity']; ?>"> <button type="button" onclick="increaseQuantity(<?php echo $count; ?>)" class="btn btn-success">+</button> </td> <td><b id="subtotal<?php echo $count; ?>"><?php echo $row1['p_current_price'] * $value['quantity']; ?></b></td> <td> <div class="shopping-cart-delete" data-id="<?php echo $pid; ?>"> <button type="button" onclick="removeCart(this)" class="remove btn btn-success"><i class="fa fa-times"></i></button> </div> </td> </tr> <?php $t = $row1['p_current_price'] * $value['quantity']; $a = $a + $t; $count++; } ?> </tbody> <tfoot> <tr> <td colspan="3"><strong>Total</strong></td> <td id="grandTotal"><b><?php echo $a; ?></b></td> </tr> </tfoot> </table> <div class="row"> <div class="col-lg-12"> <div class="cart-shiping-update-wrapper"> <div class="cart-shiping-update"> <a href="<?php path(); ?>">Continue Shopping</a> </div> <div class="cart-clear"> <!--<a href="<?php path(); ?>/checkout.php">Proceed to Checkout</a>--> </div> <button type="submit" name="update" style="border-radius:50px; padding:12px 63px 17px;" class="btn btn-primary">Proceed to Checkout</button> </div> </div> </div> </form> </div> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script> <script> function increaseQuantity(count) { let quantityElem = document.getElementById('quantity' + count); let quantity = parseInt(quantityElem.innerText) + 1; quantityElem.innerText = quantity; document.getElementById('inputQuantity' + count).value = quantity; updateSubtotal(count, quantity); } function decreaseQuantity(count) { let quantityElem = document.getElementById('quantity' + count); let quantity = parseInt(quantityElem.innerText); if (quantity > 1) { quantity -= 1; quantityElem.innerText = quantity; document.getElementById('inputQuantity' + count).value = quantity; updateSubtotal(count, quantity); } } function updateSubtotal(count, quantity) { let priceElem = document.getElementById('price' + count); let price = parseFloat(priceElem.innerText); let subtotalElem = document.getElementById('subtotal' + count); let subtotal = price * quantity; subtotalElem.innerText = subtotal.toFixed(2); updateGrandTotal(); } function updateGrandTotal() { let subtotals = document.querySelectorAll('[id^=subtotal]'); let grandTotal = 0; subtotals.forEach(function (subtotalElem) { grandTotal += parseFloat(subtotalElem.innerText); }); document.getElementById('grandTotal').innerText = grandTotal.toFixed(2); } // function removeCart(button) { // const productId = button.closest('tr').dataset.id; // $.ajax({ // url: 'ajax/remove_item', // type: 'POST', // data: { productId: productId }, // success: function(response) { // const data = JSON.parse(response); // if (data.success) { // // Remove the item row from the table // button.closest('tr').remove(); // // Update the grand total // updateGrandTotal(); // } else { // alert('Failed to remove item.'); // } // } // }); // } </script> <?php include_once("assets/include/footer.php")?> </div> </body> </html>
Save
Cancel