prepare(" SELECT i.*, c.name AS category_name, s.name AS store_name, s.id AS store_id FROM item i JOIN category c ON i.category_id = c.id JOIN store s ON i.store_id = s.id WHERE i.id = :item_id AND i.status = 0 LIMIT 1 "); $stmt->execute(['item_id' => $item_id]); $item = $stmt->fetch(PDO::FETCH_ASSOC); if(!$item) die("Item not found."); // Fetch admin fee $admin_fee_percent = 0; $stmtFee = $pdo->prepare("SELECT master_percentage FROM stores_commission_plan WHERE store_id = :store_id LIMIT 1"); $stmtFee->execute(['store_id' => $item['store_id']]); $feeRow = $stmtFee->fetch(PDO::FETCH_ASSOC); if($feeRow && isset($feeRow['master_percentage'])) { $admin_fee_percent = floatval($feeRow['master_percentage']); } // Unit prices $unit_prices = [ 'small' => floatval($item['small_price']), 'medium' => floatval($item['medium_price']), 'large' => floatval($item['large_price']), ]; // Handle add to cart $success_msg = ''; if($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_to_cart'])) { $unit = $_POST['unit'] ?? 'small'; $qty = max(1,intval($_POST['qty'] ?? 1)); $price = $unit_prices[$unit]; $total_price = $price * $qty; $vat = $total_price * 0.15; $admin_fee = $total_price * ($admin_fee_percent / 100); $grand_total = $total_price + $vat + $admin_fee; $stmtInsert = $pdo->prepare(" INSERT INTO cart_items (item_id, store_id, unit, qty, price, vat, admin_fee, grand_total, created_at) VALUES (:item_id, :store_id, :unit, :qty, :price, :vat, :admin_fee, :grand_total, NOW()) "); $stmtInsert->execute([ 'item_id'=>$item['id'], 'store_id'=>$item['store_id'], 'unit'=>$unit, 'qty'=>$qty, 'price'=>$price, 'vat'=>$vat, 'admin_fee'=>$admin_fee, 'grand_total'=>$grand_total ]); $success_msg = "Item added to cart successfully!"; } ?>

Category:

Store:

Description:

Price: 0.00 ETB

VAT (15%): 0.00 ETB

Admin Fee (%): 0.00 ETB

Grand Total: 0.00 ETB