diff --git a/app/Http/Controllers/ProductController.php b/app/Http/Controllers/ProductController.php index 33aafef..024a84c 100644 --- a/app/Http/Controllers/ProductController.php +++ b/app/Http/Controllers/ProductController.php @@ -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')); diff --git a/app/Http/Controllers/SubcategoryController.php b/app/Http/Controllers/SubcategoryController.php index c16f7df..9dd7015 100644 --- a/app/Http/Controllers/SubcategoryController.php +++ b/app/Http/Controllers/SubcategoryController.php @@ -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')); + } } diff --git a/public/js/app.js b/public/js/app.js index 40e40e1..510aa1d 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -11242,7 +11242,6 @@ var app = new Vue({ __webpack_require__(35); __webpack_require__(34); -__webpack_require__(31); __webpack_require__(32); /** @@ -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__) { diff --git a/resources/assets/js/active_links.js b/resources/assets/js/active_links.js deleted file mode 100644 index 57460a7..0000000 --- a/resources/assets/js/active_links.js +++ /dev/null @@ -1,5 +0,0 @@ -var url = window.location; - -$('td a').filter(function() { - return this.href == url; -}).parent().addClass('active').css('backgroundColor', '#b4b37a'); \ No newline at end of file diff --git a/resources/assets/js/app.js b/resources/assets/js/app.js index fb3366a..65943f5 100644 --- a/resources/assets/js/app.js +++ b/resources/assets/js/app.js @@ -25,7 +25,6 @@ const app = new Vue({ require('./hover_menu'); require('./hide_flash_messages'); -require('./active_links'); require('./ajax_config'); /** diff --git a/resources/views/main_page.blade.php b/resources/views/main_page.blade.php index dde6f8f..8ed05b3 100644 --- a/resources/views/main_page.blade.php +++ b/resources/views/main_page.blade.php @@ -32,7 +32,7 @@ @foreach($categories as $category) @endforeach @@ -129,14 +129,6 @@ @endif - - {{--For autheniticated users--}} - @if(Auth::check()) -
- - Give a review - - @endif @@ -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); + }); diff --git a/resources/views/products/product_details.blade.php b/resources/views/products/product_details.blade.php index 6739864..13ad949 100644 --- a/resources/views/products/product_details.blade.php +++ b/resources/views/products/product_details.blade.php @@ -62,13 +62,11 @@ @endif - {{--For autheniticated users--}} - @if(Auth::check())
- - Give a review + + See reviews - @endif + @@ -106,45 +104,51 @@
{{--Autheniticated users can give reviews--}} @if(Auth::check()) - @if(!$isGiven) -
-
-
-
- You + @if($isOrdered) + @if(!$isGiven) +
+
+
+
+ You +
-
-
-
-
- -
- Please write truth to help others make a good purchase -
-
-
- {{ csrf_field() }} - -
-
- - @if ($errors->has('review')) - +
+
+
+ +
+ Please write truth to help others make a good purchase +
+
+ + {{ csrf_field() }} + +
+
+ + @if ($errors->has('review')) + {{ $errors->first('review') }} - @endif -
- - + @endif +
+ + +
-
+ @else +
+ You have already given a review to this product. +
+ @endif @else -
- You have already given a review to this product. +
+ You cannot give reviews to this product without buying it
@endif @endif @@ -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); }); /** diff --git a/resources/views/products/products_list.blade.php b/resources/views/products/products_list.blade.php index 3ed4b6f..4af8430 100644 --- a/resources/views/products/products_list.blade.php +++ b/resources/views/products/products_list.blade.php @@ -1,5 +1,6 @@ {{-- Pagination links --}} {{ $products->links() }} +
@foreach($products as $product)
@@ -57,14 +58,6 @@ @endif - - {{--For autheniticated users--}} - @if(Auth::check()) -
- - Give a review - - @endif
diff --git a/resources/views/subcategories/subcategory_products.blade.php b/resources/views/subcategories/subcategory_products.blade.php index d359c79..2bebeef 100644 --- a/resources/views/subcategories/subcategory_products.blade.php +++ b/resources/views/subcategories/subcategory_products.blade.php @@ -18,33 +18,57 @@
+ + {{--Products filtration--}} + +
+
+ Sort by price: +
+ +
+
+
@foreach($categories as $category) -
- +
+ -
-
- - @foreach($category->subcategories as $subcategory) - - - - @endforeach -
- {{$subcategory->name}} -
+
+
+ + @foreach($category->subcategories as $subcategory) + + + + @endforeach +
+
-
@endforeach
+ + {{--
--}} + {{--

Sort:

--}} + + {{--
--}} +
@@ -69,9 +93,33 @@ diff --git a/resources/views/users/orders.blade.php b/resources/views/users/orders.blade.php index 11e67c6..3771bf4 100644 --- a/resources/views/users/orders.blade.php +++ b/resources/views/users/orders.blade.php @@ -50,7 +50,8 @@ Product Price Quantity - Totals + Totals + Give review @@ -61,6 +62,18 @@ ${{$orderProduct->product->price}} {{$orderProduct->quantity}} ${{$orderProduct->priceForAllItems}} + + + {{-- Give a review after you made an order --}} + @if(!Auth::user()->reviews->contains('product_id', $orderProduct->product->id)) + + Give a review + + @else + {{--You have already gave a review--}} + Done + @endif + @endforeach @@ -94,6 +107,11 @@ var id = order_id.split('_')[1]; $('#order_details_' + id).slideDown(); + }); + + $('.give_review').on('click', function () { + + localStorage.setItem('animate', 'animate'); }) }) diff --git a/routes/web.php b/routes/web.php index 1094302..123dd1b 100644 --- a/routes/web.php +++ b/routes/web.php @@ -96,7 +96,14 @@ Route::get('/{product}', 'ProductController@show'); }); +/** + * Subcategories, products, filtration + */ + Route::get('/subcategories/{subcategory}/products', 'SubcategoryController@showAllProducts'); +Route::get('/subcategories/{subcategory}/products/prices/ascending', 'SubcategoryController@showAllProductsByPriceAscending'); +Route::get('/subcategories/{subcategory}/products/prices/descending', 'SubcategoryController@showAllProductsByPriceDescending'); + Route::post('/products/{product}/reviews/add', 'ReviewController@store'); /*