From c2b5ab68a84bf830f64e9c4e39f92b24c085c7e6 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Thu, 1 Jun 2023 17:12:25 +0200 Subject: calculate cart sum --- public/cart.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'public/cart.php') 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 @@ image ? "/img/product/$item->id-thumb.jpg" : "/img/placeholder.png"; + $price = number_format($item->price, 2, ',', '.'); echo <<<"EOF"
productafbeelding @@ -45,7 +46,7 @@ function item_template($item) { - $item->price + $price
EOF; } @@ -86,8 +87,17 @@ EOF; 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" +
+ Subtotaal: $subtotal +
-- cgit v1.2.3