JezK
Edit File: cart.php
<?php include 'userObject.php'; include 'checkSession.php'; if (isset($_POST['addToCart'])) { $_POST['userId'] = $_SESSION['id']; $insertStatus = $user->addCartItem($_POST); echo $insertStatus; } if (isset($_POST['getCartProducts'])) { $userCartProductDetails = $user->getUserCartProducts($_POST); $count = count($userCartProductDetails); $htmlText = ''; if ($count > 0) { foreach ($userCartProductDetails as $row) { $warranty = $row['warranty']; $warrantyDurationType = ($row['warranty_duration_type'] == 1) ? 'Month' : 'Year'; $pluralSuffix = ($warranty == 1) ? '' : 's'; if($row['expiry'] == 0){ $expiry = ''; }else{ $expiryDurationType = ($row['duration'] == 1) ? 'Month' : 'Year'; $pluralSuffixExpiry = ($row['expiry'] == 1) ? '' : 's'; $expiry = 'Expiry: '.$row['expiry'].' '. $expiryDurationType . $pluralSuffixExpiry; } $warranty .= ' ' . $warrantyDurationType . $pluralSuffix; $htmlText .= ' <div class="col-lg-3 col-12 cart-card"> <img src="' . $baseUrl . 'uploads/products/' . $row["image_name"] . '" class="d-block m-auto w-100 cart-image" > <button class="no-btn" onclick="deleteCartItem(' . $row['cartId'] . ')" > <img src="cancelImage.png" alt="cancel" class="cancelimage"> </button> <h5 class="pd-title">' . $row["productName"] . '</h5> <p class="pd-description ">' . $row["description"] . '</p> <p class="product-price">RS. ' . $row["amount"] . '</p> <p class="warranty">(' . $warranty . ')</p> <p class="warranty">' . $expiry . '</p> <div class="d-flex justify-content-center align-items-center"> <button class="no-btn" onclick="changeProductCount(' . $row['cartId'] . ',2)"><img src="minusicon.png" alt="minus button"></button> <span class="mx-2">' . $row['product_count'] . '</span> <button class="no-btn" onclick="changeProductCount(' . $row['cartId'] . ',1)"><img src="plusicon.png" alt="plus button"></button> </div> </div>'; } } else { $htmlText = "You haven't added any products"; } echo $htmlText; } if (isset($_POST['changeProductCount'])) { $updateStatus = $user->changeProductCount($_POST); echo $updateStatus; } if (isset($_POST['getCartServices'])) { $userCartServiceDetails = $user->getUserCartServices($_POST); $count = count($userCartServiceDetails); $htmlText = ''; if ($count > 0) { foreach ($userCartServiceDetails as $row) { $htmlText .= '<div class="col-lg-3 col-12 cart-card"> <img src="' . $baseUrl . 'uploads/services/' . $row["image_name"] . '" class="d-block m-auto img-fluid" alt="images" > <button class="no-btn" onclick="deleteCartItem(' . $row['cartId'] . ')"><img src="cancelImage.png" alt="cancel" class="cancelimage"></button> <h5 class="pd-title">' . $row['serviceName'] . '</h5> <p class="product-price">RS. ' . $row['amount'] . '</p> </div>'; } } else { $htmlText = "You haven't added any services"; } echo $htmlText; } if (isset($_POST['getCartCareClubs'])) { $userCartCareClubDetails = $user->getUserCartCareClubs($_POST); $count = count($userCartCareClubDetails); $htmlText = ''; if ($count > 0) { foreach ($userCartCareClubDetails as $row) { $expiry = $row['expiry']; $expiryDurationType = ($row['duration_type'] == 1) ? 'Month' : 'Year'; $pluralSuffix = ($expiry == 1) ? '' : 's'; $expiry .= ' ' . $expiryDurationType . $pluralSuffix; $htmlText .= '<div class="col-lg-3 col-12 cart-card"> <button class="no-btn" onclick="deleteCartItem(' . $row['cartId'] . ')"><img src="cancelImage.png" alt="cancel" class="cancelimage"></button> <h5 class="pd-title">' . $row['careClubName'] . '</h5> <p class="product-price">RS. ' . $row['amount'] . '</p> <p class="">' . $expiry . '</p> </div>'; } } else { $htmlText .= "You haven't added any care clubs"; } echo $htmlText; } if (isset($_POST['getUserCartDetails'])) { $userCartProductDetails = $user->getUserCartProducts($_POST); $userCartServiceDetails = $user->getUserCartServices($_POST); $userCartCareClubDetails = $user->getUserCartCareClubs($_POST); $htmlText = ''; $total = 0; foreach ($userCartProductDetails as $row) { $warranty = $row['warranty']; $warrantyDurationType = ($row['warranty_duration_type'] == 1) ? 'Month' : 'Year'; $pluralSuffix = ($warranty == 1) ? '' : 's'; $warranty .= ' ' . $warrantyDurationType . $pluralSuffix; $costWithCount = $row['amount'] * $row['product_count']; $htmlText .= '<div class="d-flex justify-content-between mx-4"> <div> <p class="bill-description">' . $row['productName'] . ' (' . $row['product_count'] . ') </p> <p class="warranty text-left">(' . $warranty . ')</p> </div> <div> <h1 class="bill-description">' . $costWithCount . '</h1> </div> </div>'; $total += $costWithCount; } foreach ($userCartServiceDetails as $row) { $htmlText .= '<div class="d-flex justify-content-between mx-4"> <div> <p class="bill-description">' . $row['serviceName'] . '</p> </div> <div> <h1 class="bill-description"> ' . $row['amount'] . '</h1> </div> </div>'; $total += $row['amount']; } foreach ($userCartCareClubDetails as $row) { $htmlText .= '<div class="d-flex justify-content-between mx-4"> <div> <p class="bill-description">' . $row['careClubName'] . '</p> </div> <div> <h1 class="bill-description"> ' . $row['amount'] . '</h1> </div> </div>'; $total += $row['amount']; } echo json_encode(array("htmlText" => $htmlText, "total" => $total)); } if (isset($_POST['deleteCartItem'])) { $deleteStatus = $user->deleteCartItem($_POST); echo $deleteStatus; } if (isset($_POST['couponCheck'])) { $couponDetails = $user->checkCoupon($_POST); if ($couponDetails['status'] == 3) { $couponData = $couponDetails['couponData']; $cartItemsAmount = $couponDetails['cartItemsAmount']; $couponAmount = intval($couponData['amount']); $totalAmount = intval($cartItemsAmount['totalAmount']); $grandTotal = $totalAmount - $couponAmount; $couponDetails['grandTotal'] = $grandTotal; $couponDetails['usersLeft'] = intval($couponData['usercount']) - intval($couponData['usedusers']); $couponDetails['couponAmount'] = $couponAmount; } echo json_encode($couponDetails); } if (isset($_POST['action']) && $_POST['action'] == 'checkCart') { $userId = $_POST['userId']; $cart_count = $user->checkCart($userId); echo $cart_count; }