Skip to content

Commit 68e2fc3

Browse files
committed
checkout system updated
1 parent 0031b5c commit 68e2fc3

14 files changed

+277
-30
lines changed

.DS_Store

0 Bytes
Binary file not shown.

app/.DS_Store

0 Bytes
Binary file not shown.

app/Http/.DS_Store

0 Bytes
Binary file not shown.

app/Http/Controllers/cartController.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,27 @@ class cartController extends Controller
1313
public function index(){
1414
$cart = Cart::content();
1515
return view('cart.index', [
16-
'data' => $cart
16+
'data' => $cart,
17+
1718
]);
1819
}
1920

20-
public function checkout(){
21-
return orders::createOrder();
22-
return back();
23-
}
21+
2422

2523
public function addItem($id){
2624
$pro = products::find($id);
27-
Cart::add(['id' => $pro->id, 'name' => $pro->pro_name,
25+
$add = Cart::add(['id' => $pro->id, 'name' => $pro->pro_name,
2826
'qty' => 1, 'price' => $pro->pro_price,
2927
'options' =>[
3028
'img' => $pro->pro_img,
3129
'size' => 'large'
3230
]]);
33-
echo "add to cart successfully";
31+
if($add){
32+
return view('cart.index',[
33+
'data' => Cart::content()
34+
]);
35+
}
36+
//echo "add to cart successfully";
3437
}
3538

3639
public function update(Request $request){
Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use Illuminate\Http\Request;
6+
use Cart;
7+
use DB;
8+
use Auth;
9+
use App\dAddress;
10+
use App\orders;
11+
class checkoutController extends Controller
12+
{
13+
public function index(){
14+
return view('front.checkout',[
15+
'data' => Cart::content()
16+
]);
17+
}
18+
19+
public function placeOrder(Request $request){
20+
21+
$this->validate($request, [
22+
'fullname' => 'required|min:5|max:35',
23+
'phone' => 'required|numeric',
24+
'email' => 'required|email',
25+
'city' => 'required|min:5|max:25',
26+
'state' => 'required|min:5|max:25',
27+
'country' => 'required',
28+
'fullAddress' => 'required'
29+
]);
30+
31+
$address = new dAddress;
32+
33+
$address->userid = Auth::user()->id;
34+
$address->fullname = $request->fullname;
35+
$address->email = $request->email;
36+
$address->phone = $request->phone;
37+
$address->state = $request->state;
38+
$address->city = $request->city;
39+
$address->country = $request->country;
40+
$address->fullAddress = $request->fullAddress;
41+
$address->save();
42+
43+
44+
orders::createOrder();
45+
46+
Cart::destroy();
47+
return redirect('thankyou');
48+
}
49+
50+
51+
public function checkCoupon(Request $res)
52+
{
53+
$code = $res->code;
54+
55+
$check = DB::table('coupons')
56+
->where('coupon_code',$code)
57+
->get();
58+
if(count($check)=="1"){
59+
//ok
60+
$user_id = Auth::user()->id;
61+
$check_used = DB::table('used_coupons')
62+
->where('user_id',$user_id)
63+
->where('coupon_id',$check[0]->id)
64+
->count();
65+
if($check_used=="0"){
66+
//insert used one
67+
$used_add = DB::table('used_coupons')
68+
->insert([
69+
'coupon_id' => $check[0]->id,
70+
'user_id' => $user_id
71+
]);
72+
$insert_cart_total = DB::table('cart_total')
73+
->insert([
74+
'cart_totol' => Cart::total(),
75+
'discount' => $check[0]->discount,
76+
'user_id' => $user_id,
77+
'gtotal' => Cart::total() - (Cart::total() * $check[0]->discount)/100,
78+
]);
79+
$disnew = $check[0]->discount;
80+
$gtnew = Cart::total() - (Cart::total() * $check[0]->discount)/100;
81+
82+
//echo "applied";
83+
84+
?>
85+
<div class="cart-total" >
86+
<h4>Total Amount</h4>
87+
<table>
88+
<tbody>
89+
<tr>
90+
<td>Sub Total</td>
91+
<td>$ <?php echo Cart::subtotal(); ?></td>
92+
</tr>
93+
<tr>
94+
<td>Tax (%)</td>
95+
<td>$ <?php echo Cart::tax(); ?></td>
96+
</tr>
97+
98+
99+
<tr>
100+
<td>Grand Total </td>
101+
<td>$ <?php echo Cart::total(); ?></td>
102+
</tr>
103+
104+
<tr><td colspan="2"><hr></td></tr>
105+
<tr>
106+
<td>Discount(%) </td>
107+
<td> <?php echo $disnew; ?></td>
108+
</tr>
109+
110+
<tr>
111+
<td>Grand Total (After discount) </td>
112+
<td>$ <?php echo $gtnew; ?></td>
113+
</tr>
114+
</tbody>
115+
</table>
116+
<input type="submit" class="btn update btn-block" value="Continue Shopping">
117+
<a href="{{url('checkout')}}" class="btn check_out btn-block">checkout</a>
118+
</div>
119+
120+
<?php
121+
}
122+
else{?>
123+
124+
<div class="alert alert-warning">you already used this coupon</div>
125+
<div class="cart-total" >
126+
<h4>Total Amount</h4>
127+
<table>
128+
<tbody>
129+
<tr>
130+
<td>Sub Total</td>
131+
<td>$ <?php echo Cart::subtotal(); ?></td>
132+
</tr>
133+
<tr>
134+
<td>Tax (%)</td>
135+
<td>$ <?php echo Cart::tax(); ?></td>
136+
</tr>
137+
138+
139+
<tr>
140+
<td>Grand Total</td>
141+
<td>$ <?php echo Cart::total(); ?></td>
142+
</tr>
143+
</tbody>
144+
</table>
145+
<input type="submit" class="btn update btn-block" value="Continue Shopping">
146+
<a href="{{url('checkout')}}" class="btn check_out btn-block">checkout</a>
147+
</div>
148+
<?php }
149+
}else{
150+
//echo "wrong coupon";
151+
?>
152+
<div class="alert alert-danger">Wrong Coupon code you entered</div>
153+
154+
<div class="cart-total" >
155+
<h4>Total Amount</h4>
156+
<table>
157+
<tbody>
158+
<tr>
159+
<td>Sub Total</td>
160+
<td>$ <?php echo Cart::subtotal(); ?></td>
161+
</tr>
162+
<tr>
163+
<td>Tax (%)</td>
164+
<td>$ <?php echo Cart::tax(); ?></td>
165+
</tr>
166+
167+
168+
<tr>
169+
<td>Grand Total</td>
170+
<td>$ <?php echo Cart::total(); ?></td>
171+
</tr>
172+
</tbody>
173+
</table>
174+
<input type="submit" class="btn update btn-block" value="Continue Shopping">
175+
<a href="{{url('checkout')}}" class="btn check_out btn-block">checkout</a>
176+
</div>
177+
<?php }
178+
}
179+
}

app/dAddress.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace App;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
7+
class dAddress extends Model
8+
{
9+
protected $table='dAddress';
10+
}

database/.DS_Store

0 Bytes
Binary file not shown.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Schema;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Database\Migrations\Migration;
6+
7+
class CreateDAddressTable extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::create('dAddress', function (Blueprint $table) {
17+
$table->increments('id');
18+
$table->string('fullname');
19+
$table->integer('userid');
20+
$table->string('email');
21+
$table->string('phone');
22+
$table->string('city');
23+
$table->string('state');
24+
$table->string('country');
25+
$table->string('fullAddress');
26+
$table->timestamps();
27+
});
28+
}
29+
30+
/**
31+
* Reverse the migrations.
32+
*
33+
* @return void
34+
*/
35+
public function down()
36+
{
37+
Schema::dropIfExists('dAddress');
38+
}
39+
}

resources/.DS_Store

0 Bytes
Binary file not shown.

resources/views/.DS_Store

0 Bytes
Binary file not shown.

resources/views/cart/index.blade.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<script>
44
$(document).ready(function(){
55
$("#CartMsg").hide();
6+
//$('#CartTotal').hide();
67
@foreach($data as $pro)
78
$("#upCart{{$pro->id}}").on('change keyup', function(){
89
var newQty = $("#upCart{{$pro->id}}").val();
@@ -26,7 +27,8 @@
2627
url:'{{url('/checkCoupon')}}',
2728
data: 'code=' + coupon_id,
2829
success:function(res){
29-
alert(res);
30+
// alert(res);
31+
$('#cartTotal').html(res);
3032
}
3133
})
3234
});
@@ -146,8 +148,8 @@ class="cart-remove btn btn-danger">Remove</a>
146148
</div>
147149
<div class="clearfix"></div>
148150
</div>
149-
<div class="col-sm-4">
150-
<div class="cart-total">
151+
<div class="col-sm-4" id="cartTotal">
152+
<div class="cart-total" >
151153
<h4>Total Amount</h4>
152154
<table>
153155
<tbody>
@@ -159,17 +161,16 @@ class="cart-remove btn btn-danger">Remove</a>
159161
<td>Tax (%)</td>
160162
<td>$ {{Cart::tax()}}</td>
161163
</tr>
164+
165+
162166
<tr>
163167
<td>Grand Total</td>
164168
<td>$ {{Cart::total()}}</td>
165169
</tr>
166170
</tbody>
167171
</table>
168-
<input type="submit" class="btn update btn-block"
169-
value="Continue Shopping">
170-
<a href="{{url('checkout')}}"
171-
class="btn check_out btn-block"
172-
>checkout</a>
172+
173+
<a href="{{url('checkout')}}" class="btn check_out btn-block">checkout</a>
173174
</div>
174175
</div>
175176
</div>

0 commit comments

Comments
 (0)