Skip to content

Commit

Permalink
Products sorting by price was added. Changes in giving reviews. User …
Browse files Browse the repository at this point in the history
…can give reviews in orders history panel only after buying this product
  • Loading branch information
vilgefortzz committed May 20, 2017
1 parent effa807 commit 77d7f49
Show file tree
Hide file tree
Showing 11 changed files with 183 additions and 117 deletions.
12 changes: 9 additions & 3 deletions app/Http/Controllers/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,18 @@ public function show(Product $product){
// Get all reviews for this product and sort reviews by date from the newest one
$reviews = Review::where('product_id', $product->id)->orderBy('created_at', 'desc')->paginate(2);

// Check if has user already given a review to this product
// Check if has user already given a review to this product and if has user ordered this product
if (Auth::check()){

$isGiven = $reviews->contains('user_id', Auth::user()->id);

return view('products.product_details', compact('product', 'isGiven', 'reviews'));
$isOrdered = false;

foreach (Auth::user()->orders as $order){
if ($order->orderProducts->contains('product_id', $product->id)){
$isOrdered = true;
}
}
return view('products.product_details', compact('product', 'isGiven', 'isOrdered', 'reviews'));
}

return view('products.product_details', compact('product', 'reviews'));
Expand Down
26 changes: 26 additions & 0 deletions app/Http/Controllers/SubcategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,30 @@ public function showAllProducts(Subcategory $subcategory, Request $request){
}
return view('subcategories.subcategory_products', compact('categories','category','subcategory','products'));
}

public function showAllProductsByPriceAscending(Subcategory $subcategory, Request $request){

$categories = Category::all();
$category = $subcategory->category;
$products = Product::where('subcategory_id', $subcategory->id)
->orderBy('price', 'asc')->paginate(3);

if ($request->ajax()) {
return view('products.products_list', compact('products'))->render();
}
return view('subcategories.subcategory_products', compact('categories','category','subcategory','products'));
}

public function showAllProductsByPriceDescending(Subcategory $subcategory, Request $request){

$categories = Category::all();
$category = $subcategory->category;
$products = Product::where('subcategory_id', $subcategory->id)
->orderBy('price', 'desc')->paginate(3);

if ($request->ajax()) {
return view('products.products_list', compact('products'))->render();
}
return view('subcategories.subcategory_products', compact('categories','category','subcategory','products'));
}
}
13 changes: 1 addition & 12 deletions public/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -11242,7 +11242,6 @@ var app = new Vue({

__webpack_require__(35);
__webpack_require__(34);
__webpack_require__(31);
__webpack_require__(32);

/**
Expand Down Expand Up @@ -12128,17 +12127,7 @@ Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
});

/***/ }),
/* 31 */
/***/ (function(module, exports, __webpack_require__) {

/* WEBPACK VAR INJECTION */(function($) {var url = window.location;

$('td a').filter(function () {
return this.href == url;
}).parent().addClass('active').css('backgroundColor', '#b4b37a');
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(1)))

/***/ }),
/* 31 */,
/* 32 */
/***/ (function(module, exports, __webpack_require__) {

Expand Down
5 changes: 0 additions & 5 deletions resources/assets/js/active_links.js

This file was deleted.

1 change: 0 additions & 1 deletion resources/assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const app = new Vue({

require('./hover_menu');
require('./hide_flash_messages');
require('./active_links');
require('./ajax_config');

/**
Expand Down
20 changes: 5 additions & 15 deletions resources/views/main_page.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
@foreach($categories as $category)
<ul id="sub_cat_{{$category->id}}" class="sub_cat_menu" hidden>
@foreach($category->subcategories as $subcategory)
<li><a href="{{ url('/subcategories/'.$subcategory->id.'/products') }}"><b>{{$subcategory->name}}</b></a></li>
<li id="sub_link_{{$subcategory->id}}"><a href="{{ url('/subcategories/'.$subcategory->id.'/products') }}"><b>{{$subcategory->name}}</b></a></li>
@endforeach
</ul>
@endforeach
Expand Down Expand Up @@ -129,14 +129,6 @@
</a>

@endif

{{--For autheniticated users--}}
@if(Auth::check())
<br>
<a class="give_review" href="{{ url('/products/'.$recommendedProduct->id) }}">
<span class="glyphicon glyphicon-comment"></span><b>Give a review</b>
</a>
@endif
</div>
</div>
</div>
Expand Down Expand Up @@ -168,13 +160,11 @@
$('#sub_cat_' + id).fadeIn();
});
/**
* Animate from another page - set
*/
$('.sub_cat_menu').on('click', function () {
$('.give_review').on('click', function () {
localStorage.setItem('animate', 'animate');
})
var id = $(this).find('li').attr('id');
localStorage.setItem('active_link', id);
});
</script>

Expand Down
93 changes: 44 additions & 49 deletions resources/views/products/product_details.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,11 @@

@endif

{{--For autheniticated users--}}
@if(Auth::check())
<br>
<a id="give_review_this_page" class="give_review" href="javascript:undefined">
<span class="glyphicon glyphicon-comment"></span><b>Give a review</b>
<a id="see_reviews_this_page" class="give_review" href="javascript:undefined">
<span class="glyphicon glyphicon-comment"></span><b>See reviews</b>
</a>
@endif

</div>
</div>

Expand Down Expand Up @@ -106,45 +104,51 @@
<div id="reviews_section">
{{--Autheniticated users can give reviews--}}
@if(Auth::check())
@if(!$isGiven)
<div id="write_review">
<div class="row">
<div class="col-sm-1">
<div class="thumbnail">
<b><i>You</i></b>
@if($isOrdered)
@if(!$isGiven)
<div id="write_review">
<div class="row">
<div class="col-sm-1">
<div class="thumbnail">
<b><i>You</i></b>
</div>
</div>
</div>

<div class="col-sm-5">
<div class="panel panel-review panel-default">
<div class="panel-heading panel-heading-fix panel-heading-review">
<label for="review_text_area"><span class="glyphicon glyphicon-pencil"></span>Write your review below</label>
<br>
<u><b class="info">Please write truth to help others make a good purchase</b></u>
</div>
<div class="panel-body">
<form role="form" method="POST" action="{{ url('/products/'.$product->id.'/reviews/add')}}">
{{ csrf_field() }}

<div class="form-group{{ $errors->has('review') ? ' has-error' : '' }}" style="margin-bottom: 0">
<br>
<textarea id="review_text_area" name="review" class="textarea_review" placeholder="Write here!!" required></textarea>
@if ($errors->has('review'))
<span class="help-block">
<div class="col-sm-5">
<div class="panel panel-review panel-default">
<div class="panel-heading panel-heading-fix panel-heading-review">
<label for="review_text_area"><span class="glyphicon glyphicon-pencil"></span>Write your review below</label>
<br>
<u><b class="info">Please write truth to help others make a good purchase</b></u>
</div>
<div class="panel-body">
<form role="form" method="POST" action="{{ url('/products/'.$product->id.'/reviews/add')}}">
{{ csrf_field() }}

<div class="form-group{{ $errors->has('review') ? ' has-error' : '' }}" style="margin-bottom: 0">
<br>
<textarea id="review_text_area" name="review" class="textarea_review" placeholder="Write here!!" required></textarea>
@if ($errors->has('review'))
<span class="help-block">
<strong>{{ $errors->first('review') }}</strong>
</span>
@endif
</div>
<button class="btn btn-info" type="submit">Post</button>
</form>
@endif
</div>
<button class="btn btn-info" type="submit">Post</button>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
@else
<div id="review_given">
<span class="glyphicon glyphicon-ok-sign"></span>You have already given a review to this product.
</div>
@endif
@else
<div id="review_given">
<span class="glyphicon glyphicon-ok-sign"></span>You have already given a review to this product.
<div>
<span class="glyphicon glyphicon-info-sign"></span>You cannot give reviews to this product without buying it
</div>
@endif
@endif
Expand Down Expand Up @@ -204,23 +208,14 @@
});
/**
* Animate from this page
* Animate from this page to reviews section
*/
$('#give_review_this_page').on('click', function() {
$('#see_reviews_this_page').on('click', function() {
if($('#write_review').length != 0) {
$('html, body').animate({
scrollTop: $('#write_review').offset().top - 170
}, 800);
$('#review_text_area').focus();
}
else{
$('html, body').animate({
scrollTop: $('#review_given').offset().top - 170
}, 800);
}
$('html, body').animate({
scrollTop: $('#reviews').offset().top - 170
}, 800);
});
/**
Expand Down
9 changes: 1 addition & 8 deletions resources/views/products/products_list.blade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{{-- Pagination links --}}
{{ $products->links() }}
<hr>

@foreach($products as $product)
<div class="item col-xs-4 col-lg-4">
Expand Down Expand Up @@ -57,14 +58,6 @@
</a>

@endif

{{--For autheniticated users--}}
@if(Auth::check())
<br>
<a class="give_review" href="{{ url('/products/'.$product->id) }}">
<span class="glyphicon glyphicon-comment"></span><b>Give a review</b>
</a>
@endif
</div>
</div>
</div>
Expand Down
Loading

0 comments on commit 77d7f49

Please sign in to comment.