-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcart_view.php
172 lines (159 loc) · 3.5 KB
/
cart_view.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<?php include 'includes/session.php'; ?>
<?php include 'includes/header.php'; ?>
<body class="hold-transition skin-blue layout-top-nav">
<div class="wrapper">
<?php include 'includes/navbar.php'; ?>
<div class="content-wrapper">
<div class="container">
<!-- Main content -->
<section class="content">
<div class="row">
<div class="col-sm-9">
<h1 class="page-header">سبد خرید شما</h1>
<div class="box box-solid">
<div class="box-body">
<table class="table table-bordered">
<thead>
<th></th>
<th>تصویر کالا</th>
<th>نام کالا</th>
<th>قیمت</th>
<th width="20%">تعداد</th>
<th>مجموع</th>
</thead>
<tbody id="tbody">
</tbody>
</table>
</div>
</div>
<?php
if(isset($_SESSION['user'])){
echo "
<div id='mellat-button'>
<button type='button' class='btn btn-success'>پرداخت</button>
</div>
";
}
else{
echo "
<h4> جهت بررسی سبد خرید خود <a href='login.php'>وارد حساب کاربری </a> شوید</h4>
";
}
?>
</div>
<div class="col-sm-3">
<?php include 'includes/sidebar.php'; ?>
</div>
</div>
</section>
</div>
</div>
<?php $pdo->close(); ?>
<?php include 'includes/footer.php'; ?>
</div>
<?php include 'includes/scripts.php'; ?>
<script>
var total = 0;
$(function(){
$(document).on('click', '.cart_delete', function(e){
e.preventDefault();
var id = $(this).data('id');
$.ajax({
type: 'POST',
url: 'cart_delete.php',
data: {id:id},
dataType: 'json',
success: function(response){
if(!response.error){
getDetails();
getCart();
getTotal();
}
}
});
});
$(document).on('click', '.minus', function(e){
e.preventDefault();
var id = $(this).data('id');
var qty = $('#qty_'+id).val();
if(qty>1){
qty--;
}
$('#qty_'+id).val(qty);
$.ajax({
type: 'POST',
url: 'cart_update.php',
data: {
id: id,
qty: qty,
},
dataType: 'json',
success: function(response){
if(!response.error){
getDetails();
getCart();
getTotal();
}
}
});
});
$(document).on('click', '.add', function(e){
e.preventDefault();
var id = $(this).data('id');
var qty = $('#qty_'+id).val();
qty++;
$('#qty_'+id).val(qty);
$.ajax({
type: 'POST',
url: 'cart_update.php',
data: {
id: id,
qty: qty,
},
dataType: 'json',
success: function(response){
if(!response.error){
getDetails();
getCart();
getTotal();
}
}
});
});
getDetails();
getTotal();
});
function getDetails(){
$.ajax({
type: 'POST',
url: 'cart_details.php',
dataType: 'json',
success: function(response){
$('#tbody').html(response);
getCart();
}
});
}
function getTotal(){
$.ajax({
type: 'POST',
url: 'cart_total.php',
dataType: 'json',
success:function(response){
total = response;
}
});
}
</script>
<!-- mellat Express -->
<script>
$(document).on('click', '#mellat-button', function(e){
alert('پرداخت با موفقیت انجام شد');
var time = Date.now()
setTimeout(() => {
window.location = 'sales.php?pay='+time;
}, 3000);
})
</script>
</body>
</html>