-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
cart copy.php
104 lines (86 loc) · 3.52 KB
/
cart copy.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
include "config.php";
include "tanggal.php";
$input=$_GET['input'];
$id_session=$_GET['id_session'];
$id_barang=$_GET['id_barang'];
if($input=="add"){
$sid = session_id();
$sql = $connect->query("SELECT stock FROM barang WHERE id='$id_barang'");
$s = mysqli_fetch_array($sql);
$stok = $s['stock'];
//echo $stok; exit();
if ($stok == 0) {
echo "<script> alert('stock habis'); location.href='index.php?hal=beli_langsung' </script>";
exit();
} else {
$query=$connect->query("SELECT id_barang, qty from keranjang where id_barang='$id_barang' and id_session='$id_session'");
$data_tmp=mysqli_fetch_array($query);
$cek=mysqli_num_rows($query);
$qty = $data_tmp['qty'];
if($cek==0){
$connect->query("INSERT INTO keranjang(id_barang,id_session,tgl_keranjang,jam_keranjang,qty) VALUES ('$id_barang','$id_session','$tgl_sekarang','$jam_sekarang','1')");
}
else if($qty >= $stok){
echo "<script> alert('Stock yang tersedia tidak cukup'); location.href='index.php?hal=beli_langsung' </script>";
exit();
}
else{
$connect->query("UPDATE keranjang SET qty=qty+1 where id_session='$id_session' and id_barang='$id_barang'");
}
header('location:index.php?hal=beli_langsung');
}
}
// session_start();
// //error_reporting(0);
// include "config.php";
// include "tanggal.php";
// $mod = $_GET['mod'];
// $act = $_GET['act'];
// if ($mod == 'basket' AND $act == 'add') {
// $sid = session_id();
// $sql = $connect->query("SELECT stock FROM barang WHERE id='$_GET[id]'");
// $s = mysqli_fetch_array($sql);
// $stok = $s['stock'];
// //echo $stok; exit();
// if ($stok == 0) {
// echo "<script> alert('stock habis'); location.href='index.php?hal=pos' </script>";
// exit();
// } else {
// $sql_temp = $connect->query("SELECT * FROM orders_temp WHERE id_barang='$_GET[id]' AND id_session='$sid'");
// $data_tmp=mysqli_fetch_array($sql_temp);
// $ketemu = mysqli_num_rows($sql_temp);
// if(!empty($data_tmp['stok_temp'])) {
// if ($data_tmp['jumlah'] >= $stok) {
// echo "<script> alert('Jumlah yang dibeli sedang kosong'); location.href='index.php?hal=pos' </script>";
// exit();
// }
// }
// if ($ketemu == 0) {
// // put the product in cart table
// $connect->query("INSERT INTO orders_temp (id_barang, jumlah, id_session, tgl_order_temp, jam_order_temp, stok_temp)
// VALUES ('$_GET[id]', 1, '$sid', '$tgl_sekarang', '$jam_sekarang', '$stok')");
// } else {
// // update product quantity in cart table
// $connect->query("UPDATE orders_temp
// SET jumlah = jumlah + 1
// WHERE id_session ='$sid' AND id_barang='$_GET[id]'");
// }
// deleteAbandonedCart();
// echo "<script> alert('Product berhasil dibeli'); location.href='index.php?hal=pos' </script>";
// exit;
// }
// } elseif ($mod == 'basket' AND $act == 'del') {
// $connect->query("DELETE FROM orders_temp WHERE id_orders_temp='$_GET[id]'");
// echo "<script> alert('Product berhasil dihapus'); location.href='index.php?hal=pos' </script>";
// exit;
// }
// /*
// Delete all cart entries older than one day
// */
// function deleteAbandonedCart()
// {
// $kemarin = date('Y-m-d', mktime(0, 0, 0, date('m'), date('d') - 1, date('Y')));
// mysqli_query ("DELETE FROM orders_temp HERE tgl_order_temp < '$kemarin'");
// }
?>