Added a way to starr a product, so it floats on top of the list of products

This commit is contained in:
Krzysztof Płaczek
2024-05-19 11:43:56 +02:00
parent 584bdcdf89
commit a204439a27
4 changed files with 21 additions and 8 deletions

View File

@@ -18,7 +18,8 @@ if (isset($_GET['product_id'])) {
}
if (isset($_GET['category'])) {
$template = 'productList.html.twig';
$products = Product::with('price')->selectRaw('products.*')->fromRaw('products, json_each(products.categories)')->whereRaw('json_each.value = ?', [$_GET['category']])->get();
$products = Product::with('price')->selectRaw('products.*')->fromRaw('products, json_each(products.categories)')->whereRaw('json_each.value = ?', [$_GET['category']])
->orderByDesc('starred')->orderByDesc('created_by')->get();
}
if (isset($_GET['search'])) {
$template = 'productList.html.twig';
@@ -26,9 +27,12 @@ if (isset($_GET['search'])) {
->orWhere([['name', 'like', "%{$_GET['search']}%"]])
->orWhere([['subTitle', 'like', "%{$_GET['search']}%"]])->get();
}
if (isset($_GET['star'])) {
Product::find($_GET['star'])->toggleStarred()->save();
header('Location: '.$_SERVER['HTTP_REFERER']);
}
if (empty($_GET)) {
$template = 'productList.html.twig';
$products = Product::with('price')->get();
$products = Product::with('price')->orderByDesc('starred')->orderByDesc('created_by')->get();
}
$twig->display($template, ['products' => $products, 'product' => $product, 'search' => $_GET['search']]);