diff --git a/app/Http/Controllers/ProductsController.php b/app/Http/Controllers/ProductsController.php index 6d5fb366..7fd78f39 100644 --- a/app/Http/Controllers/ProductsController.php +++ b/app/Http/Controllers/ProductsController.php @@ -45,7 +45,7 @@ class ProductsController extends Controller $products = Product::where('range_id', $range->id)->where('status', 1)->paginate(9); // Find promo within range. $offres = Product::where('range_id', $range->id) - ->where('status', 1) + ->where('status', 1) ->has('promotions') ->with('promotions')->get(); return view('range', compact('range', 'products', 'offres')); @@ -128,7 +128,7 @@ class ProductsController extends Controller $products = $productsQuery->paginate(6); if ($request->ajax()) { - return \response()->json(ProductResource::collection($products)); + return \response()->json([ProductResource::collection($products), $products->total()]); } else { $ranges = Range::all(); $tags = Tag::where('status', true)->get(); diff --git a/resources/views/front/sable/js/components/FilterComponent.vue b/resources/views/front/sable/js/components/FilterComponent.vue index 3c892ebe..4fdb3edb 100644 --- a/resources/views/front/sable/js/components/FilterComponent.vue +++ b/resources/views/front/sable/js/components/FilterComponent.vue @@ -198,6 +198,7 @@ tags: [], search: "", products: [], + productsCount: 0, productsResults: 0, url: "", currentPage: 1, @@ -215,6 +216,7 @@ this.tags = jsonData.tags ?? []; this.search = jsonData.search ?? ""; this.products = jsonData.products ?? []; + this.productsCount = jsonData.productsCount ?? this.products.length ?? 0; this.productsResults = jsonData.productsResults ?? 0; this.filters = jsonData.filters ?? []; this.selectFilters(); @@ -275,7 +277,8 @@ this.loading = true, window.axios.get(this.url) .then(response => { - this.products = this.products.concat(response.data); + this.products = this.products.concat(response.data[0]); + this.productsCount = response.data[1]; this.loading = false; this.countResults(); }) @@ -345,7 +348,7 @@ * Update filters total number. */ countResults() { - this.btnResults.textContent = "Voir les " + this.products.length + " produits"; + this.btnResults.textContent = "Voir les " + this.productsCount + " produits"; }, /** * Check proper boxes on start diff --git a/resources/views/front/sable/ranges.blade.php b/resources/views/front/sable/ranges.blade.php index 0f98bc8a..e7091ff5 100644 --- a/resources/views/front/sable/ranges.blade.php +++ b/resources/views/front/sable/ranges.blade.php @@ -15,6 +15,7 @@ 'tags' => $tags, 'products' => \App\Http\Resources\ProductResource::collection($products), 'productsResults' => $products->perPage(), + 'productsCount' => $products->total(), 'search' => $sessionFilter->search ?? '', 'filters' => $sessionFilter, ];