Skip to content

Commit 3589259

Browse files
committed
Fetch Products with Ajax Request
Price Range Slider and Brand Checkboxes updated
1 parent 0685bc1 commit 3589259

File tree

8 files changed

+424
-256
lines changed

8 files changed

+424
-256
lines changed

EasyShop/app/Http/Controllers/HomeController.php

+46-17
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,45 @@ public function index() {
3939
return view('front.home');
4040
}
4141

42-
public function shop() {
43-
44-
$Products = DB::table('products')->get(); // now we are fetching all products
42+
public function shop(Request $request) {
43+
if ($request->ajax() && isset($request->start)) {
44+
$start = $request->start; // min price value
45+
$end = $request->end; // max price value
46+
47+
$Products = DB::table('products')
48+
->where('pro_price', '>=', $start)
49+
->where('pro_price', '<=', $end)
50+
->orderby('pro_price', 'ASC')
51+
->paginate(6);
52+
53+
response()->json($Products); //return to ajax
54+
return view('front.products', compact('Products'));
55+
}
56+
else if(isset($request->brand)){
57+
58+
$brand = $request->brand; //brand
59+
60+
$Products = DB::table('products')
61+
->whereIN('cat_id', explode( ',', $brand ))
62+
->paginate(6);
63+
64+
// dd($Products);
65+
66+
response()->json($Products); //return to ajax
67+
return view('front.products', compact('Products'));
68+
69+
70+
}
71+
else {
4572

46-
return view('front.shop', compact('Products'));
73+
$Products = DB::table('products')->paginate(6); // now we are fetching all products
74+
return view('front.shop', compact('Products'));
75+
}
4776
}
4877

4978
public function proCats(Request $request) {
5079
$catName = $request->name;
51-
$Products = DB::table('pro_cat')->leftJoin('products', 'pro_cat.id', '=', 'products.cat_id')->where('pro_cat.name', '=', $catName)->paginate(2);
80+
$Products = DB::table('pro_cat')->leftJoin('products', 'pro_cat.id', '=', 'products.cat_id')->where('pro_cat.name', '=', $catName)->paginate(12);
5281

5382
return view('front.shop', compact('Products'));
5483
}
@@ -69,7 +98,7 @@ public function search(Request $request) {
6998
if ($search == '') {
7099
return view('front.home');
71100
} else {
72-
$Products = DB::table('products')->where('pro_name', 'like', '%' . $search . '%')->paginate(2);
101+
$Products = DB::table('products')->where('pro_name', 'like', '%' . $search . '%')->paginate(12);
73102
return view('front.shop', ['msg' => 'Results: ' . $search], compact('Products'));
74103
}
75104
}
@@ -87,26 +116,26 @@ public function wishList(Request $request) {
87116
$wishList->user_id = Auth::user()->id;
88117
$wishList->pro_id = $request->pro_id;
89118

119+
90120
$wishList->save();
91121

92-
$Products = DB::table('products')->where('id', $request->pro_id)->get();
122+
$Products = DB::table('products')->where('id', $request->pro_id)->get();
93123
//$Products = DB::table('wishlist')->leftJoin('products', 'wishlist.pro_id', '=', 'products.ic')->get();
94124

95125
return view('front.product_details', compact('Products'));
96126
}
97-
98-
public function View_wishList(){
99-
100-
$Products = DB::table('wishlist')->leftJoin('products', 'wishlist.pro_id', '=', 'products.id')->get();
101-
return view('front.wishList', compact('Products'));
127+
128+
public function View_wishList() {
129+
130+
$Products = DB::table('wishlist')->leftJoin('products', 'wishlist.pro_id', '=', 'products.id')->get();
131+
return view('front.wishList', compact('Products'));
102132
}
103-
104-
public function removeWishList($id){
105-
133+
134+
public function removeWishList($id) {
135+
106136
DB::table('wishlist')->where('pro_id', '=', $id)->delete();
107-
137+
108138
return back()->with('msg', 'Item Removed from Wishlist');
109-
110139
}
111140

112141
}

EasyShop/resources/views/front/master.blade.php

+20-26
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
<script src="js/respond.min.js"></script>
1919
<![endif]-->
2020
<link rel="shortcut icon" href="{{asset('theme/images/ico/favicon.ico')}}">
21-
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="images/ico/apple-touch-icon-144-precomposed.png">
22-
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="images/ico/apple-touch-icon-114-precomposed.png">
23-
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="images/ico/apple-touch-icon-72-precomposed.png">
24-
<link rel="apple-touch-icon-precomposed" href="images/ico/apple-touch-icon-57-precomposed.png">
21+
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="{{url('../')}}/theme/images/ico/apple-touch-icon-144-precomposed.png">
22+
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="{{url('../')}}/theme/images/ico/apple-touch-icon-114-precomposed.png">
23+
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="{{url('../')}}/theme/images/ico/apple-touch-icon-72-precomposed.png">
24+
<link rel="apple-touch-icon-precomposed" href="{{url('../')}}/theme/images/ico/apple-touch-icon-57-precomposed.png">
2525
</head><!--/head-->
2626

2727
<body>
@@ -33,7 +33,7 @@
3333
<div class="row">
3434
<div class="col-sm-4">
3535
<div class="logo pull-left">
36-
<a href="{{url('/')}}"><img src="{{('theme/images/home/logo.png')}}" alt="" /></a>
36+
<a href="{{url('/')}}"><img src="{{url('../')}}/theme/images/home/logo.png" alt="" /></a>
3737
</div>
3838
<div class="btn-group pull-right">
3939
<div class="btn-group">
@@ -62,26 +62,26 @@
6262
<div class="col-sm-8">
6363
<div class="shop-menu pull-right">
6464
<ul class="nav navbar-nav">
65-
<?php if(Auth::check()){?>
66-
<li><a href="{{url('/')}}/profile"><i class="fa fa-user"></i>{{ucwords(Auth::user()->name)}}</a></li>
67-
<?php }?>
65+
<?php if (Auth::check()) { ?>
66+
<li><a href="{{url('/')}}/profile"><i class="fa fa-user"></i>{{ucwords(Auth::user()->name)}}</a></li>
67+
<?php } ?>
6868
<li><a href="{{url('/WishList')}}"><i class="fa fa-star"></i> Wishlist <span style="color:green; font-weight: bold">({{App\wishList::count()}})</span> </a></li>
6969
<li><a href="{{url('/checkout')}}"><i class="fa fa-crosshairs"></i> Checkout</a></li>
7070
<li><a href="{{url('/cart')}}"><i class="fa fa-shopping-cart"></i> Cart <span style="color:green; font-weight: bold">({{Cart::count()}})</span><br>
71-
<p align="center" style="color:green; font-weight:bold">({{Cart::subtotal()}})</p></a></li>
72-
<?php if(Auth::check()){?>
73-
<li><a href="{{url('/logout')}}"><i class="fa fa-lock"></i> Logout</a></li>
74-
<?php } else {?>
75-
<li><a href="{{url('/login')}}"><i class="fa fa-lock"></i> Login</a></li>
76-
<?php }?>
71+
<p align="center" style="color:green; font-weight:bold">({{Cart::subtotal()}})</p></a></li>
72+
<?php if (Auth::check()) { ?>
73+
<li><a href="{{url('/logout')}}"><i class="fa fa-lock"></i> Logout</a></li>
74+
<?php } else { ?>
75+
<li><a href="{{url('/login')}}"><i class="fa fa-lock"></i> Login</a></li>
76+
<?php } ?>
7777
</ul>
7878
</div>
7979
</div>
8080
</div>
8181
</div>
8282
</div><!--/header-middle-->
8383

84-
@include('front.menu')
84+
@include('front.menu')
8585
</header><!--/header-->
8686
@yield('content')
8787

@@ -100,7 +100,7 @@
100100
<div class="video-gallery text-center">
101101
<a href="#">
102102
<div class="iframe-img">
103-
<img src="images/home/iframe1.png" alt="" />
103+
<img src="{{url('../')}}/theme/images/home/iframe1.png" alt="" />
104104
</div>
105105
<div class="overlay-icon">
106106
<i class="fa fa-play-circle-o"></i>
@@ -115,7 +115,7 @@
115115
<div class="video-gallery text-center">
116116
<a href="#">
117117
<div class="iframe-img">
118-
<img src="images/home/iframe2.png" alt="" />
118+
<img src="{{url('../')}}/theme/images/home/iframe2.png" alt="" />
119119
</div>
120120
<div class="overlay-icon">
121121
<i class="fa fa-play-circle-o"></i>
@@ -130,7 +130,7 @@
130130
<div class="video-gallery text-center">
131131
<a href="#">
132132
<div class="iframe-img">
133-
<img src="images/home/iframe3.png" alt="" />
133+
<img src="{{url('../')}}/theme/images/home/iframe3.png" alt="" />
134134
</div>
135135
<div class="overlay-icon">
136136
<i class="fa fa-play-circle-o"></i>
@@ -145,7 +145,7 @@
145145
<div class="video-gallery text-center">
146146
<a href="#">
147147
<div class="iframe-img">
148-
<img src="images/home/iframe4.png" alt="" />
148+
<img src="{{url('../')}}/theme/images/home/iframe4.png" alt="" />
149149
</div>
150150
<div class="overlay-icon">
151151
<i class="fa fa-play-circle-o"></i>
@@ -158,7 +158,7 @@
158158
</div>
159159
<div class="col-sm-3">
160160
<div class="address">
161-
<img src="images/home/map.png" alt="" />
161+
<img src="{{url('../')}}/theme/images/home/map.png" alt="" />
162162
<p>505 S Atlantic Ave Virginia Beach, VA(Virginia)</p>
163163
</div>
164164
</div>
@@ -244,12 +244,6 @@
244244
</footer><!--/Footer-->
245245

246246

247-
<script src="{{asset('theme/js/jquery.js')}}"></script>
248-
<script src="{{asset('theme/js/bootstrap.min.js')}}"></script>
249-
<script src="{{asset('theme/js/jquery.scrollUp.min.js')}}"></script>
250-
<script src="{{asset('theme/js/price-range.js')}}"></script>
251-
<script src="{{asset('theme/js/jquery.prettyPhoto.js')}}"></script>
252-
<script src="{{asset('theme/js/main.js')}}"></script>
253247
</body>
254248
</html>
255249

EasyShop/resources/views/front/product_details.blade.php

+8-6
Original file line numberDiff line numberDiff line change
@@ -150,21 +150,21 @@
150150
<div class="product-details"><!--product-details-->
151151
<div class="col-sm-5">
152152
<div class="view-product">
153-
<img src="{{url('../')}}/upload/images/large/<?php echo $value->pro_img; ?>" alt="" />
153+
<img src="<?php echo $value->pro_img; ?>" alt="" />
154154
<h3>ZOOM</h3>
155155
</div>
156156
<div id="similar-product" class="carousel slide" data-ride="carousel">
157157

158158
<!-- Wrapper for slides -->
159159
<div class="carousel-inner">
160160
<div class="item active">
161-
<img src="{{url('/')}}/upload/images/small/<?php echo $value->pro_img; ?>" alt="" />
161+
<img src="<?php echo $value->pro_img; ?>" alt="" />
162162
</div>
163163
<div class="item">
164-
<img src="{{url('/')}}/upload/images/small/<?php echo $value->pro_img; ?>" alt="" />
164+
<img src="<?php echo $value->pro_img; ?>" alt="" />
165165
</div>
166166
<div class="item">
167-
<img src="{{url('/')}}/upload/images/sma;ll/<?php echo $value->pro_img; ?>" alt="" />
167+
<img src="<?php echo $value->pro_img; ?>" alt="" />
168168
</div>
169169

170170
</div>
@@ -203,20 +203,22 @@
203203
<a href=""><img src="{{url('/')}}/theme/images/product-details/share.png" class="share img-responsive" alt="" /></a>
204204

205205
<?php
206+
if(Auth::check()){
206207
$wishData = DB::table('wishlist')->leftJoin('products', 'wishlist.pro_id', '=', 'products.id')->where('wishlist.pro_id', '=',$value->id)->get();
207208
208209
//if($wishData==""){ echo 'empty'; } else { echo 'filled';}
209210
$count = App\wishList::where(['pro_id' => $value->id])->count();
210211
?>
211212
<?php if($count=="0"){?>
212-
<form action="{{url('/addToWishList')}}">
213+
<form action="{{url('/addToWishList')}}" method="post">
213214
{{ csrf_field() }}
214215
<input type="hidden" value="{{$value->id}}" name="pro_id"/>
215216
<input type="submit" value="Add to WishList" class="btn btn-success"/>
216217
</form>
217218
<?php } else {?>
218219
<h5 style="color:green"> Added to <a href="{{url('/WishList')}}">wishList</a></h5>
219-
<?php }?>
220+
<?php }
221+
}?>
220222

221223

222224
</div><!--/product-information-->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<div class="features_items"> <!--features_items-->
2+
<b> Total Products</b>: {{$Products->total()}}
3+
<h2 class="title text-center">
4+
<?php
5+
if (isset($msg)) {
6+
echo $msg;
7+
} else {
8+
?> Features Item <?php } ?> </h2>
9+
10+
<?php if ($Products->isEmpty()) { ?>
11+
sorry, products not found
12+
<?php } else { ?>
13+
@foreach($Products as $product)
14+
<div class="col-sm-4" >
15+
<div class="product-image-wrapper">
16+
<div class="single-products">
17+
<div class="productinfo text-center">
18+
<a href="{{url('/product_details')}}">
19+
<img src="<?php echo $product->pro_img; ?>" alt="" />
20+
</a>
21+
<h2 id="price">$<?php echo $product->pro_price; ?></h2>
22+
23+
<p><a href="{{url('/product_details')}}"><?php echo $product->pro_name; ?></a></p>
24+
<a href="{{url('/cart/addItem')}}/<?php echo $product->id; ?>" class="btn btn-default add-to-cart"><i class="fa fa-shopping-cart"></i>Add to cart</a>
25+
</div>
26+
<a href="{{url('/product_details')}}/<?php echo $product->id; ?>">
27+
<div class="product-overlay">
28+
<div class="overlay-content">
29+
<h2>$<?php echo $product->pro_price; ?></h2>
30+
<p><?php echo $product->pro_name; ?></p>
31+
<a href="{{url('/cart/addItem')}}/<?php echo $product->id; ?>" class="btn btn-default add-to-cart"><i class="fa fa-shopping-cart"></i>Add to cart</a>
32+
</div>
33+
</div></a>
34+
</div>
35+
<div class="choose">
36+
<?php
37+
$wishData = DB::table('wishlist')->leftJoin('products', 'wishlist.pro_id', '=', 'products.id')->where('wishlist.pro_id', '=', $product->id)->get();
38+
$count = App\wishList::where(['pro_id' => $product->id])->count();
39+
?>
40+
41+
<?php if ($count == "0") { ?>
42+
<form action="{{url('/addToWishList')}}" method="post">
43+
{{ csrf_field() }}
44+
<input type="hidden" value="{{$product->id}}" name="pro_id"/>
45+
<p align="center">
46+
<input type="submit" value="Add to WishList" class="btn btn-primary"/>
47+
</p>
48+
</form>
49+
<?php } else { ?>
50+
<h5 style="color:green"> Added to <a href="{{url('/WishList')}}">wishList</a></h5>
51+
<?php } ?>
52+
53+
</div>
54+
</div>
55+
</div>
56+
57+
@endforeach
58+
<?php } ?>
59+
60+
61+
</div>
62+
<ul class="pagination">
63+
{{ $Products->links()}}
64+
</ul>

0 commit comments

Comments
 (0)