Show sourcecode
The following files exists in this folder. Click to view.
webbserverprogrammering/projekt/snake_oil_seller/php/
about_us.php
add_to_cart.php
admin.php
buy_cart.php
config.php
contact.php
create_products.php
create_tables.php
createtable.php
dbconnection.php
delete_post.php
delete_tables.php
deletepost.php
deletetable.php
entry.php
header.php
insert_posts.php
insertposts.php
leaderboard.php
log_in.php
log_out.php
main.php
my_account.php
question_maker.php
quiz_form.php
quiz_list.php
quiz_maker.php
result.php
select_posts.php
selectposts.php
shop.php
shop_item.php
shopping_cart.php
sign_in.php
title_card.php
update_posts.php
updateposts.php
user_verified.php
verify_page.php
shopping_cart.php
89 lines UTF-8 Windows (CRLF)
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
<?php
// Initierar sessionen
session_start();
/** @var PDO $dbconn*/
include ("dbconnection.php");
?>
<!DOCTYPE html>
<html lang="sv">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Shopping cart</title>
<link href="../css/snake_oil.css" rel="stylesheet">
<link href="../css/main.css" rel="stylesheet">
</head>
<body>
<!-- Titel -->
<?php include "title_card.php";?>
<!-- Rubriker -->
<?php include "header.php";?>
<!-- Kundvagnen -->
<?php
echo "<div id='product_container_shopping_cart'>";
// Meddelar efter köp
$purchase_completed = false;
if (!empty($_SESSION["purchase_completed"])) {
$purchase_completed = true;
unset($_SESSION["purchase_completed"]);
}
// Visar meddelandet när kundvagnen efter ett köp
if ($purchase_completed) {
echo "<div id='empty_cart_notice'>Your purchase was completed.<br>Thanks for shopping at Snake Oil Seller!</div>";
// Visar alla produkter som ligger i kundvagnen
} else if (!empty($_SESSION["cart"])) {
foreach ($_SESSION["cart"] as $product_id => $amount) {
$sql = "SELECT * FROM product_items WHERE id = ?";
$fetch_all = $dbconn->prepare($sql);
$fetch_all->execute([$product_id]);
if ($products = $fetch_all->fetch(PDO::FETCH_ASSOC)) {
$product_name = $products["name"];
$product_price = $products["price"];
$product_info = $products["info"];
$product_img = $products["img"];
$product_amount = $products["amount"];
$price_to_pay = $product_amount * $product_price;
// Varje produkt är en länk som tar en tillbaka till produktsidan
echo "<a href='shop_item.php?item_id=$product_id' class='item_container'>
<img src='../bilder/$product_img' id='product_image_cart'>
<div class='image_text'>
<span style='font-weight: bold;'>$product_name</span>
<span>$amount st<br></span>
<span>$price_to_pay kr</span>
</div>
</a>";
}
}
} else {
// Om kundvagen är tom utan köp
echo "<div id='empty_cart_notice'>You have 0 items in your shopping cart</div>";
}
// Tömmer kundvagnen
echo "<div class='cart_buttons_wrapper'> <button class='shopping_cart_buttons' id='clear_cart' onclick='clear_cart()'>Empty cart</button>";
if ($_SERVER["REQUEST_METHOD"] === "POST") {
$_SESSION["cart"] = [];
}
// Köper allt i kundvagnen
if ($is_logged_in) {
echo "<button class='shopping_cart_buttons' id='buy_cart' onclick='buy_cart()'>Buy all</button></div>";
} else {
echo "<button class='shopping_cart_buttons' id='buy_cart' style='color: red;'>NOT LOGGED IN</button></div>";
}
echo "</div>";
?>
<!-- JS för ajax uppdatering -->
<script src="../js/use_cart.js"></script>
</body>
</html>