diff options
author | lonkaars <loek@pipeframe.xyz> | 2023-06-01 17:12:25 +0200 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2023-06-01 17:12:25 +0200 |
commit | c2b5ab68a84bf830f64e9c4e39f92b24c085c7e6 (patch) | |
tree | 09c459c28d19ff35e4ae1746572f11169e00150c /public/cart.php | |
parent | 6715936a3b33c14b2d8c581677855bb6c1297940 (diff) |
calculate cart sum
Diffstat (limited to 'public/cart.php')
-rw-r--r-- | public/cart.php | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/public/cart.php b/public/cart.php index ba33a9d..f7ee295 100644 --- a/public/cart.php +++ b/public/cart.php @@ -38,6 +38,7 @@ <?php function item_template($item) { $image_path = $item->image ? "/img/product/$item->id-thumb.jpg" : "/img/placeholder.png"; + $price = number_format($item->price, 2, ',', '.'); echo <<<"EOF" <div class="product" product-id="$item->id"> <img src="$image_path" alt="productafbeelding"> @@ -45,7 +46,7 @@ function item_template($item) { <label for="$item->id-count">hoeveelheid:</label> <input type="number" value="$item->count" min="1" max="20" id="$item->id-count" class="count buttonstyle filled" disabled> <button type="submit" value="$item->id" name="product_id" class="button outlined">weghalen</button> - <span class="price">$item->price</span> + <span class="price">$price</span> </div> EOF; } @@ -86,8 +87,17 @@ EOF; <input type="hidden" name="type" value="delete"> EOF; while ($product = $res->fetch_object()) item_template($product); + + $statement = $cursor->prepare("select cart_sum(cart(?)) as `sum`"); + $statement->bind_param("i", $user_id); + if (!$statement->execute()) break; + $res = $statement->get_result(); + $subtotal = number_format($res->fetch_object()->sum, 2, ',', '.'); echo <<<"EOF" </form> + <div class="alignright"> + <span class="sum">Subtotaal: <span class="subtotal price">$subtotal</span></span> + </div> <form class="product-footer" method="post" action="/order-complete.php"> <input type="submit" value="Bestellen" class="buttonstyle filled"> </form> |