Ticket 1263: fix count of products filtered

This commit is contained in:
Alexis Gousseau 2023-01-30 11:53:48 +01:00
parent 518c2d0d60
commit daeb24d7a9
3 changed files with 8 additions and 4 deletions

View file

@ -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();

View file

@ -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

View file

@ -15,6 +15,7 @@
'tags' => $tags,
'products' => \App\Http\Resources\ProductResource::collection($products),
'productsResults' => $products->perPage(),
'productsCount' => $products->total(),
'search' => $sessionFilter->search ?? '',
'filters' => $sessionFilter,
];