Skip to content

Commit 234d77b

Browse files
committed
tinggal payment cuk
1 parent 1023ade commit 234d77b

6 files changed

Lines changed: 308 additions & 70 deletions

File tree

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{
22
"name": "mufti/pbl_oron",
3-
"require": {}
3+
"require": {
4+
"midtrans/midtrans-php": "^2.6"
5+
}
46
}

composer.lock

Lines changed: 75 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

features/cart/cart.php

Lines changed: 138 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,148 @@
1-
<?php
2-
include '../connection/connection.php';
3-
4-
session_start();
5-
if (isset($_SESSION['account_id'])) {
6-
$accountId = $_SESSION['account_id'];
7-
8-
// Query dengan account_id dari session
9-
$query = "SELECT
10-
c.cart_id,
11-
p.product_id,
12-
p.name AS product_name,
13-
p.current_price,
14-
p.discount
15-
FROM
16-
cart c
17-
JOIN
18-
products p ON c.product_id = p.product_id
19-
WHERE
20-
c.account_id = $accountId";
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Home Page</title>
7+
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
8+
</head>
9+
<body>
10+
<?php
11+
// Start session
12+
session_start();
13+
14+
// Check if user is logged in
15+
$isLoggedIn = isset($_SESSION['username']);
16+
?>
2117

22-
// Eksekusi query
23-
$result = oci_parse($conn, $query);
24-
oci_execute($result);
25-
26-
// Tampilkan data...
27-
} else {
28-
echo "Echo Echo";
29-
exit;
30-
}exit;
31-
32-
// Display cart data as an HTML table
33-
echo "<h2>Your Cart</h2>";
34-
echo "<table border='1'>";
35-
echo "<tr>
18+
<!-- Navbar -->
19+
<nav class="navbar navbar-expand-lg navbar-light">
20+
<div class="container">
21+
<a class="navbar-brand" href="#">ORON</a>
22+
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
23+
<span class="navbar-toggler-icon"></span>
24+
</button>
25+
<div class="collapse navbar-collapse" id="navbarNav">
26+
<ul class="navbar-nav ms-auto">
27+
<li class="nav-item">
28+
<a class="nav-link" href="../store/store.php">Store</a>
29+
</li>
30+
<li class="nav-item">
31+
<a class="nav-link" href="#">Library</a>
32+
</li>
33+
<li class="nav-item">
34+
<?php if ($isLoggedIn): ?>
35+
<a class="nav-link" href="../profile/profile.php"><?php echo htmlspecialchars($_SESSION['username']); ?></a>
36+
<?php else: ?>
37+
<a class="nav-link" href="../login/login.php">Profile</a>
38+
<?php endif; ?>
39+
</li>
40+
<li class="nav-item">
41+
<a class="nav-link" href="../cart/cart.php">Cart</a>
42+
</li>
43+
</ul>
44+
</div>
45+
</div>
46+
</nav>
47+
</body>
48+
</html>
49+
50+
<?php
51+
include '../connection/connection.php';
52+
53+
if (!isset($_SESSION['account_id'])) {
54+
echo "<p>You need to log in to view your cart.</p>";
55+
exit();
56+
}
57+
58+
$accountId = $_SESSION['account_id'];
59+
60+
// Handle remove product
61+
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['remove_selected'])) {
62+
if (isset($_POST['selected_products'])) {
63+
foreach ($_POST['selected_products'] as $productToRemove) {
64+
$deleteQuery = "DELETE FROM cart WHERE account_id = :account_id AND product_id = :product_id";
65+
$deleteproduct = oci_parse($conn, $deleteQuery);
66+
oci_bind_by_name($deleteproduct, ":account_id", $accountId);
67+
oci_bind_by_name($deleteproduct, ":product_id", $productToRemove);
68+
oci_execute($deleteproduct);
69+
oci_free_statement($deleteproduct);
70+
}
71+
}
72+
echo '<script>alert("Selected products removed successfully.");</script>';
73+
}
74+
75+
// Query untuk mendapatkan data keranjang
76+
$query = "SELECT
77+
c.cart_id,
78+
p.product_id,
79+
p.name AS product_name,
80+
p.current_price,
81+
p.discount
82+
FROM
83+
cart c
84+
JOIN
85+
products p ON c.product_id = p.product_id
86+
WHERE
87+
c.account_id = :account_id";
88+
89+
$stid = oci_parse($conn, $query);
90+
oci_bind_by_name($stid, ":account_id", $accountId);
91+
oci_execute($stid);
92+
93+
echo '<h2>Your Cart</h2>';
94+
95+
echo '<form method="POST">';
96+
echo '<table border="1" cellpadding="10">';
97+
echo '<tr>
98+
<th>Select</th>
3699
<th>Product Name</th>
37100
<th>Current Price</th>
38101
<th>Discount</th>
39-
</tr>";
102+
<th>Final Price</th>
103+
</tr>';
40104

105+
$totalPrice = 0;
41106
while (($row = oci_fetch_array($stid, OCI_ASSOC)) != false) {
42-
echo "<tr>";
43-
echo "<td>" . htmlspecialchars($row['PRODUCT_NAME']) . "</td>";
44-
echo "<td>" . htmlspecialchars($row['CURRENT_PRICE']) . "</td>";
45-
echo "<td>" . htmlspecialchars($row['DISCOUNT']) . "</td>";
46-
echo "</tr>";
107+
$finalPrice = $row['CURRENT_PRICE'] - ($row['CURRENT_PRICE'] * ($row['DISCOUNT']));
108+
$totalPrice += $finalPrice;
109+
110+
echo '<tr>';
111+
echo '<td><input type="checkbox" name="selected_products[]" value="' . htmlspecialchars($row['PRODUCT_ID']) . '"></td>';
112+
echo '<td>' . htmlspecialchars($row['PRODUCT_NAME']) . '</td>';
113+
echo '<td>$' . number_format($row['CURRENT_PRICE'], 2) . '</td>';
114+
echo '<td>' . htmlspecialchars($row['DISCOUNT'] * 100) . '%</td>';
115+
echo '<td>$' . number_format($finalPrice, 2) . '</td>';
116+
echo '</tr>';
47117
}
48-
echo "</table>";
118+
echo '</table>';
119+
120+
// Tombol untuk menghapus produk yang dipilih
121+
echo '<button type="submit" name="remove_selected">Remove Selected</button>';
122+
123+
// Tombol untuk menghitung total harga berdasarkan produk yang dipilih
124+
echo '<button type="button" onclick="calculateTotal()">Calculate Total</button>';
125+
echo '</form>';
49126

50127
oci_free_statement($stid);
51128
oci_close($conn);
52-
?>
129+
?>
130+
131+
<!-- Tambahkan Total Harga -->
132+
<h3>Total Price: $<span id="total-price">0.00</span></h3>
133+
134+
<script>
135+
function calculateTotal() {
136+
let checkboxes = document.querySelectorAll('input[name="selected_products[]"]:checked');
137+
let rows = document.querySelectorAll('table tr');
138+
let total = 0;
139+
140+
checkboxes.forEach(checkbox => {
141+
let row = checkbox.closest('tr');
142+
let finalPrice = parseFloat(row.cells[4].innerText.replace('$', ''));
143+
total += finalPrice;
144+
});
145+
146+
document.getElementById('total-price').innerText = total.toFixed(2);
147+
}
148+
</script>

features/payments/placeOrder.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
start_session();
3+
/*Install Midtrans PHP Library (https://github.com/Midtrans/midtrans-php)
4+
composer require midtrans/midtrans-php
5+
6+
Alternatively, if you are not using **Composer**, you can download midtrans-php library
7+
(https://github.com/Midtrans/midtrans-php/archive/master.zip), and then require
8+
the file manually.
9+
10+
require_once dirname(__FILE__) . '/pathofproject/Midtrans.php'; */
11+
require_once dirname(__FILE__) . '../../vendor/midtrans/midtrans-php/Midtrans.php';
12+
13+
14+
//SAMPLE REQUEST START HERE
15+
16+
// Set your Merchant Server Key
17+
\Midtrans\Config::$serverKey = 'YOUR_SERVER_KEY';
18+
// Set to Development/Sandbox Environment (default). Set to true for Production Environment (accept real transaction).
19+
\Midtrans\Config::$isProduction = false;
20+
// Set sanitization on (default)
21+
\Midtrans\Config::$isSanitized = true;
22+
// Set 3DS transaction for credit card to true
23+
\Midtrans\Config::$is3ds = true;
24+
25+
$params = array(
26+
'transaction_details' => array(
27+
'order_id' => rand(),
28+
'gross_amount' => 10000,
29+
),
30+
'customer_details' => array(
31+
'first_name' => 'budi',
32+
'last_name' => 'pratama',
33+
'email' => 'budi.pra@example.com',
34+
'phone' => '08111222333',
35+
),
36+
);
37+
38+
$snapToken = \Midtrans\Snap::getSnapToken($params);
39+
?>

0 commit comments

Comments
 (0)