feat: ✨ add new product filter on food products no art in back-end #53

This commit is contained in:
Alexis Gousseau 2025-01-13 11:08:42 +01:00
parent 184da0204b
commit e900b85583
3 changed files with 83 additions and 65 deletions

View file

@ -16,6 +16,7 @@ use App\Models\TaxRate;
use App\Models\XmlInco;
use App\Traits\Controllers\ChangesModelOrder;
use App\Traits\Controllers\UpdateModelStatus;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\File;
@ -35,12 +36,18 @@ class ProductsController extends Controller
{
$ranges = Range::all();
$filter_range = $request->query('filter_range');
$filter_brand = $request->query('filter_brand');
$filter_name = $request->query('filter_name');
$filter_range = $request->query('filter_range');
$filter_brand = $request->query('filter_brand');
$filter_name = $request->query('filter_name');
$filter_code_product = $request->query('filter_code_product');
$products = new Product();
$products = (new Product())::query();
if (!empty($filter_code_product)) {
$products = $products->whereHas('foodProduct', function (Builder $q) use ($filter_code_product) {
$q->where('no_art', 'like', $filter_code_product);
});
}
if (!empty($filter_name)) {
$products = $products->where('name', 'like', '%' . $filter_name . '%');
}
@ -65,7 +72,14 @@ class ProductsController extends Controller
}
}
unset($product);
return view('bo.products.index', compact('products', 'ranges', 'filter_name', 'filter_range', 'filter_brand'));
return view('bo.products.index', compact(
'products',
'ranges',
'filter_name',
'filter_range',
'filter_brand',
'filter_code_product'
));
}
/**

View file

@ -29,8 +29,8 @@ class Product extends Model implements Buyable
*/
protected $casts = [
'orderable_start' => 'datetime',
'orderable_end' => 'datetime',
'price' => 'float'
'orderable_end' => 'datetime',
'price' => 'float'
];
/**
@ -155,12 +155,12 @@ class Product extends Model implements Buyable
public function getCalcPrices()
{
$prices = array(
'priceHt' => $this->priceHt,
'priceKgTtc' => $this->priceKgTtc,
'discountAmount' => $this->discountAmount,
'discountRate' => $this->discountRate,
'discountedPriceHt' => $this->discountedPriceHt,
'priceTtc' => $this->priceTtc,
'priceHt' => $this->priceHt,
'priceKgTtc' => $this->priceKgTtc,
'discountAmount' => $this->discountAmount,
'discountRate' => $this->discountRate,
'discountedPriceHt' => $this->discountedPriceHt,
'priceTtc' => $this->priceTtc,
'discountedPriceTtc' => $this->discountedPriceTtc,
);
return $prices;

View file

@ -1,65 +1,70 @@
@extends('layouts.bo-layout')
@section('content')
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
<h1 class="h2">Produits <small class="text-muted">Liste</small></h1>
<form method="GET">
<div class="row">
<label for="filter_range" class="col-form-label">Gamme</label>
<div class="col">
<select class="form-control" id="filter_range" name="filter_range">
<option value="" @if ($filter_range == '') selected @endif>Toutes</option>
@foreach($ranges as $range)
<option value="{{$range->id}}" @if ($range->id == $filter_range) selected @endif>{{$range->name}}</option>
@endforeach
</select>
<div class="pt-3 pb-2 mb-3 border-bottom">
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center ">
<h1 class="h2">Produits <small class="text-muted">Liste</small></h1>
<div class="dropdown">
<button class="btn btn-primary float-right dropdown-toggle" type="button" id="dropdownMenuButton" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Ajouter un produit
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
@foreach (Config::get('theme.enum_product_types') as $productType => $label)
<a class="dropdown-item" href="{{route('bo.products.create', $productType)}}">{{ __($label) }}</a>
@endforeach
</div>
<label for="filter_range" class="col-form-label">Marque</label>
<div class="col">
<select class="form-control" id="filter_brand" name="filter_brand">
<option value="" @if ($filter_brand == '') selected @endif>Toutes</option>
@foreach (ProductBrand::toArray() as $productbrand)
<option value="{{ $productbrand->value }}" @if ($productbrand->value == $filter_brand) selected @endif>{{ $productbrand->label }}</option>
@endforeach
</select>
</div>
<label for="filter_name" class="col-form-label">Nom</label>
<div class="col">
<input class="form-control" type="text"
placeholder="Recherchez un produit"
id="filter_name" name="filter_name"
value="{{ $filter_name ?? ''}}">
</div>
<div class="col">
<button class="btn btn-primary">Filtrer</button>
<a class="btn btn-info" href="{{ route('bo.products.index') }}">Effacer le filtre</a>
</div>
</div>
</form>
<div class="dropdown">
<button class="btn btn-primary float-right dropdown-toggle" type="button" id="dropdownMenuButton" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Ajouter un produit
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
@foreach (Config::get('theme.enum_product_types') as $productType=>$label)
<a class="dropdown-item" href="{{route('bo.products.create', $productType)}}">{{ __($label) }}</a>
@endforeach
</div>
</div>
<form class="row" method="GET">
<div class="col-12 col-md-6">
<label for="filter_name" class="col-form-label">Nom</label>
<input class="form-control" type="text"
placeholder="Recherchez un produit"
id="filter_name" name="filter_name"
value="{{ $filter_name ?? ''}}">
</div>
<div class="col-12 col-md-6">
<label for="filter_range" class="col-form-label">Gamme</label>
<select class="form-control" id="filter_range" name="filter_range">
<option value="" @if ($filter_range == '') selected @endif>Toutes</option>
@foreach($ranges as $range)
<option value="{{$range->id}}" @if ($range->id == $filter_range) selected @endif>{{$range->name}}</option>
@endforeach
</select>
</div>
<div class="col-12 col-md-6">
<label for="filter_code_product" class="col-form-label">Code produit</label>
<input class="form-control" type="number"
placeholder="Recherchez un code produit"
id="filter_code_product" name="filter_code_product"
value="{{ $filter_code_product ?? ''}}">
</div>
<div class="col-12 col-md-6">
<label for="filter_range" class="col-form-label">Marque</label>
<select class="form-control" id="filter_brand" name="filter_brand">
<option value="" @if ($filter_brand == '') selected @endif>Toutes</option>
@foreach (ProductBrand::toArray() as $productbrand)
<option value="{{ $productbrand->value }}" @if ($productbrand->value == $filter_brand) selected @endif>{{ $productbrand->label }}</option>
@endforeach
</select>
</div>
<div class="col-12 text-center mt-3 mb-2">
<button class="btn btn-primary">Filtrer</button>
<a class="btn btn-info" href="{{ route('bo.products.index') }}">Effacer le filtre</a>
</div>
</form>
</div>
<table class="table">
<thead>
@if(count(Config::get('theme.enum_product_types'))>1)
<th scope="col">Type</th>
@if(count(Config::get('theme.enum_product_types')) > 1)
<th scope="col">Type</th>
@endif
<th scope="col">Ref Externe</th>
<th scope="col">Code produit</th>
<th scope="col">Image</th>
<th scope="col">Nom</th>
<th scope="col">Marque</th>
<th scope="col">Prix en €</th>
<th scope="col">Stock</th>
<th scope="col">Référence</th>
<th scope="col">Gamme</th>
<th scope="col">Publié</th>
<th scope="col">Ordre</th>
@ -69,13 +74,13 @@
@foreach ($products as $product)
<tr>
@if(count(Config::get('theme.enum_product_types'))>1)
<td>
{{ Config::get('theme.enum_product_types')[$product->product_type] }}
</td>
<td>
{{ Config::get('theme.enum_product_types')[$product->product_type] }}
</td>
@endif
<td>
@if($product->product_type == "foodProduct")
{{ $product->foodProduct->no_art }}
{{ $product->foodProduct->no_art }}
@endif
</td>
<td>
@ -89,7 +94,6 @@
<td>{{ $product->brand->label ?? '' }}</td>
<td>{{ number_format($product->price, 2, ',', ' ') }}€</td>
<td>{{ number_format($product->stock, 0, ',', ' ') }}</td>
<td>{{ $product->reference }}</td>
<td>{{ $product->range->name }}</td>
<td>
<form action="{{ route('bo.products.change-published', $product) }}" method="POST">