From e900b85583595f982885535f5ed6a6e8bf207a3f Mon Sep 17 00:00:00 2001 From: Alexis Gousseau Date: Mon, 13 Jan 2025 11:08:42 +0100 Subject: [PATCH] feat: :sparkles: add new product filter on food products no art in back-end #53 --- .../Controllers/Bo/ProductsController.php | 24 +++- app/Models/Product.php | 16 +-- resources/views/bo/products/index.blade.php | 108 +++++++++--------- 3 files changed, 83 insertions(+), 65 deletions(-) diff --git a/app/Http/Controllers/Bo/ProductsController.php b/app/Http/Controllers/Bo/ProductsController.php index d77037e3..45ab191f 100644 --- a/app/Http/Controllers/Bo/ProductsController.php +++ b/app/Http/Controllers/Bo/ProductsController.php @@ -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' + )); } /** diff --git a/app/Models/Product.php b/app/Models/Product.php index e8ed80a2..a8a92fdd 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -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; diff --git a/resources/views/bo/products/index.blade.php b/resources/views/bo/products/index.blade.php index e8a64a4c..f203a417 100644 --- a/resources/views/bo/products/index.blade.php +++ b/resources/views/bo/products/index.blade.php @@ -1,65 +1,70 @@ @extends('layouts.bo-layout') @section('content') -
-

Produits Liste

- -
-
- -
- +
+
+

Produits Liste

+ - - +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + Effacer le filtre +
+
- @if(count(Config::get('theme.enum_product_types'))>1) - + @if(count(Config::get('theme.enum_product_types')) > 1) + @endif - + - @@ -69,13 +74,13 @@ @foreach ($products as $product) @if(count(Config::get('theme.enum_product_types'))>1) - + @endif -
TypeTypeRef ExterneCode produit Image Nom Marque Prix en € StockRéférence Gamme Publié Ordre
- {{ Config::get('theme.enum_product_types')[$product->product_type] }} - + {{ Config::get('theme.enum_product_types')[$product->product_type] }} + @if($product->product_type == "foodProduct") - {{ $product->foodProduct->no_art }} + {{ $product->foodProduct->no_art }} @endif @@ -89,7 +94,6 @@ {{ $product->brand->label ?? '' }} {{ number_format($product->price, 2, ',', ' ') }}€ {{ number_format($product->stock, 0, ',', ' ') }}{{ $product->reference }} {{ $product->range->name }}