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()) -- {{$subcategory->name}} - | -
+ {{$subcategory->name}} + | +
Sort:
--}} + + {{--