Skip to content

Commit

Permalink
Simple recommendation system was added based on the 6 products with t…
Browse files Browse the repository at this point in the history
…he best average rating. Final touches and improvements
  • Loading branch information
vilgefortzz committed Jun 19, 2017
1 parent 28fe4f5 commit 7b56164
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 41 deletions.
2 changes: 1 addition & 1 deletion config/debugbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
|
*/

'enabled' => true,
'enabled' => false,

/*
|--------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public function up()
$table->integer('number_of_ratings')->unsigned()->nullable();
$table->float('ratings_sum')->unsigned()->nullable();
$table->float('average_rating')->unsigned()->nullable();
$table->boolean('recommended')->default(false);
$table->timestamps();

$table->integer('subcategory_id')->index()->unsigned();
Expand Down
6 changes: 4 additions & 2 deletions resources/views/admin/orders/orders.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<label for="order_status_{{$order->id}}" class="control-label">Change status<span class="glyphicon glyphicon-triangle-top"></span></label>
</form>
</div>
<span><strong>Made by: </strong></span>{{ $order->user->username }}
<span><strong>Made by: </strong></span>{{ $order->first_name }} {{ $order->last_name }}
<br>
<a id="order_{{$order->id}}" href="#" class="orders"><small>See order details</small></a>

Expand All @@ -74,7 +74,9 @@
<br>
<strong><span class="glyphicon glyphicon-credit-card"></span>Payment method: </strong>{{ $order->payment->name }}
<br>
<strong><span class="glyphicon glyphicon-gift"></span>Discount for having account: </strong>${{ $order->user->discount }}
@if($order->user)
<strong><span class="glyphicon glyphicon-gift"></span>Discount for having account: </strong>${{ $order->user->discount }}
@endif
<hr>
<strong><span class="glyphicon glyphicon-usd"></span>Total paid: </strong>${{number_format($order->total_paid, 2, '.', '')}}
<br><br>
Expand Down
68 changes: 33 additions & 35 deletions resources/views/main_page.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,47 +61,45 @@
{{--Horizontal line--}}
<hr>

@if(count($recommendedProducts) > 0)
<div id="recommended_products_section">
<!-- Recommended products slider-->
<div class="row" style="margin-top: 30px; margin-bottom: 30px">
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="carousel carousel-showmanymoveone slide" id="itemslider">
<div class="carousel-inner">

@foreach($recommendedProducts as $recommendedProduct)
@if($recommendedProducts->first() == $recommendedProduct)
<div class="item active">
<div class="col-xs-12 col-sm-6 col-md-2">
<a href="{{ url('/products/'.$recommendedProduct->id) }}"><img src="{{$recommendedProduct->path_to_thumbnail}}" class="img-responsive center-block"></a>
<h4 class="text-center">{{$recommendedProduct->name}}</h4>
<h5 class="text-center" style="color: darkred">${{$recommendedProduct->price}}</h5>
</div>
<div id="recommended_products_section">
<!-- Recommended products slider-->
<div class="row" style="margin-top: 30px; margin-bottom: 30px">
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="carousel carousel-showmanymoveone slide" id="itemslider">
<div class="carousel-inner">

@foreach($recommendedProducts as $recommendedProduct)
@if($recommendedProducts->first() == $recommendedProduct)
<div class="item active">
<div class="col-xs-12 col-sm-6 col-md-2">
<a href="{{ url('/products/'.$recommendedProduct->id) }}"><img src="{{$recommendedProduct->path_to_thumbnail}}" class="img-responsive center-block"></a>
<h4 class="text-center">{{$recommendedProduct->name}}</h4>
<h5 class="text-center" style="color: darkred">${{$recommendedProduct->price}}</h5>
</div>
@else
<div class="item">
<div class="col-xs-12 col-sm-6 col-md-2">
<a href="{{ url('/products/'.$recommendedProduct->id) }}"><img src="{{$recommendedProduct->path_to_thumbnail}}" class="img-responsive center-block"></a>
<h4 class="text-center">{{$recommendedProduct->name}}</h4>
<h5 class="text-center" style="color: darkred">${{$recommendedProduct->price}}</h5>
</div>
</div>
@else
<div class="item">
<div class="col-xs-12 col-sm-6 col-md-2">
<a href="{{ url('/products/'.$recommendedProduct->id) }}"><img src="{{$recommendedProduct->path_to_thumbnail}}" class="img-responsive center-block"></a>
<h4 class="text-center">{{$recommendedProduct->name}}</h4>
<h5 class="text-center" style="color: darkred">${{$recommendedProduct->price}}</h5>
</div>
@endif
@endforeach
</div>

<div id="slider-control">
<a class="left carousel-control" href="#itemslider" data-slide="prev"><span class="glyphicon glyphicon-chevron-left"></span></a>
<a class="right carousel-control" href="#itemslider" data-slide="next"><span class="glyphicon glyphicon-chevron-right"></span></a>
</div>
</div>
@endif
@endforeach
</div>

<div id="slider-control">
<a class="left carousel-control" href="#itemslider" data-slide="prev"><span class="glyphicon glyphicon-chevron-left"></span></a>
<a class="right carousel-control" href="#itemslider" data-slide="next"><span class="glyphicon glyphicon-chevron-right"></span></a>
</div>
</div>
</div>

{{--Horizontal line--}}
<hr>
</div>
@endif

{{--Horizontal line--}}
<hr>
</div>
</div>

{{-- AJAX scripts--}}
Expand Down
5 changes: 3 additions & 2 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
$categories = \App\Category::all();

/*
* Recommended products - collection
* Recommended products - sorted by average rating descending and taken 6 best products
*/
$recommendedProducts = \App\Product::all()->where('recommended', true);
$products = \App\Product::orderBy('average_rating', 'desc')->get();
$recommendedProducts = $products->take(6);

return view('main_page', compact('categories', 'recommendedProducts'));
});
Expand Down

0 comments on commit 7b56164

Please sign in to comment.