From d51f78a8db2db4d1fcbf4cc6d9275a2bbd0cca71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Fri, 8 Sep 2023 13:27:32 +0200 Subject: [PATCH 1/2] Fix for ProductResource resource --- app/Http/Resources/ProductResource.php | 6 ++++-- app/Models/Product.php | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/Http/Resources/ProductResource.php b/app/Http/Resources/ProductResource.php index 4c144b9..54431c5 100644 --- a/app/Http/Resources/ProductResource.php +++ b/app/Http/Resources/ProductResource.php @@ -73,8 +73,9 @@ class ProductResource extends JsonResource if (count($this->product->origins)) { $origins = ""; foreach ($this->product->origins as $originValue) { + /** @var \App\Enums\Products\OriginEnum $enumValue */ foreach (OriginEnum::toArray() as $enumValue) { - if (intval($originValue['id']) === $enumValue->value) { + if ($originValue === $enumValue->value) { $origins = $origins . $enumValue->label . ", "; } } @@ -83,8 +84,9 @@ class ProductResource extends JsonResource if (count($this->product->claims)) { $claims = ""; foreach ($this->product->claims as $originValue) { + /** @var \App\Enums\Products\ClaimEnum $enumValue */ foreach (ClaimEnum::toArray() as $enumValue) { - if (intval($originValue['id']) === $enumValue->value) { + if ($originValue === $enumValue->value) { if ($enumValue->value === ClaimEnum::others->value) { $claims = $claims . $enumValue->label . ": " . $this->product->specified_claim . ", "; } else { diff --git a/app/Models/Product.php b/app/Models/Product.php index 09adb53..77901de 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -33,8 +33,8 @@ use Symfony\Component\HttpFoundation\StreamedResponse; * @property array $docs * @property string $url * @property enum $certification - * @property object $origins - * @property object $claims + * @property array $origins + * @property array $claims * @property string $specified_claim * @property enum $distribution_network * @property enum $ray From 16f4af41fd70c31c9cab68c79f656adef3baa3a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Fri, 8 Sep 2023 13:29:25 +0200 Subject: [PATCH 2/2] Fix product-body division by ero when product->weight is 0 --- .../views/documents/product-body.blade.php | 161 +++++++++--------- 1 file changed, 81 insertions(+), 80 deletions(-) diff --git a/resources/views/documents/product-body.blade.php b/resources/views/documents/product-body.blade.php index 0a2c620..6a97672 100644 --- a/resources/views/documents/product-body.blade.php +++ b/resources/views/documents/product-body.blade.php @@ -6,113 +6,114 @@ @if (isset($product->picture) && !empty($product->picture)) - - + + +
- {{ $product->picture_alt }} - - @else - + + {{ $product->picture_alt }} + + @else + @endif - @if (isset($product->brand_id->name)) + @if (isset($product->brand_id->name))

{{ __('Marque du produit : ') }}{{ $product->brand_id->name }}

- @endif - @if (isset($product->name)) + @endif + @if (isset($product->name))

{{ __('Nom du produit : ') }}{{ $product->name }}

- @endif - @if (isset($product->certification)) + @endif + @if (isset($product->certification))

{{ __('Certification : ') }}{{ $product->certification }}

- @endif - @if (isset($product->origins)) + @endif + @if (isset($product->origins))

{{ __('Origines : ') }}{{ Str::replaceLast(', ', '', $product->origins) }}

- @endif - @if (isset($product->claims)) + @endif + @if (isset($product->claims))

{{ __('Allégations : ') }}{{ Str::replaceLast(', ', '', $product->claims) }}

- @endif - - - @if (isset($product->gencod)) + @endif +
+ + @if (isset($product->gencod)) - @endif - @if (isset($product->weight)) + @endif + @if (isset($product->weight)) - @endif - @if (isset($product->pvc)) + @endif + @if (isset($product->pvc)) - @endif - - - - @if (isset($product->gencod)) + @endif + + + + @if (isset($product->gencod)) - @endif - @if (isset($product->weight)) + @endif + @if (isset($product->weight)) - @endif - @if (isset($product->pvc)) + @endif + @if (isset($product->pvc)) - @endif - @php - $priceKg = 1000 * $product->pvc / $product->weight; - @endphp - - -
{{ __('GENCOD') }}{{ __('Poids UVC') }}{{ __('PVC') }}{{ __('Prix kg') }}
{{ __('Prix kg') }}
{{ $product->gencod }}{{ $product->weight }}{{ $product->pvc }}€{{ number_format(round($priceKg, 2), 2, ',', ' ') }}€
- @if (isset($product->productKeywords)) + @endif + @php + $priceKg = $product->weight ? (1000 * $product->pvc) / $product->weight : 0; + @endphp +
{{ number_format(round($priceKg, 2), 2, ',', ' ') }}€
+ @if (isset($product->productKeywords))

{{ __('Tendances identifiées : ') }}{{ Str::replaceLast(', ', '', $product->productKeywords) }}

- @endif - @if (isset($product->distribution_network)) + @endif + @if (isset($product->distribution_network))

{{ __('Réseau de distribution : ') }}{{ $product->distribution_network }}

- @endif - @if (isset($product->ray)) + @endif + @if (isset($product->ray))

{{ __('Rayon : ') }}{{ $product->ray }}

- @endif - @if (isset($product->product_range)) + @endif + @if (isset($product->product_range))

{{ __('Famille : ') }}{{ $product->product_range }}

- @endif - @if (isset($product->geo_area)) + @endif + @if (isset($product->geo_area))

{{ __('Zone géographique : ') }}{{ $product->geo_area }}

- @endif + @endif @if (isset($product->freeComment)) -

{{ __('Commentaire libre : ') }}{{ strip_tags($product->freeComment) }}

+

{{ __('Commentaire libre : ') }}{{ strip_tags($product->freeComment) }}

@endif -@if(isset($product->productComments)) -@foreach ($product->productComments as $productComment) -

{{ __('Commentaire dégustation du : ') }}{{ $productComment->date }}

- - - - - - - - - - - - - - - -
{{ __('Appréciation') }}{{ __('Aspect') }}{{ __('Odeur') }}{{ __('Texture') }}{{ __('Goût') }}
{{ $productComment->evaluation }}{{ $productComment->aspect }}{{ $productComment->taste }}{{ $productComment->odor }}{{ $productComment->texture }}
-@endforeach +@if (isset($product->productComments)) + @foreach ($product->productComments as $productComment) +

{{ __('Commentaire dégustation du : ') }}{{ $productComment->date }}

+ + + + + + + + + + + + + + + +
{{ __('Appréciation') }}{{ __('Aspect') }}{{ __('Odeur') }}{{ __('Texture') }}{{ __('Goût') }}
{{ $productComment->evaluation }}{{ $productComment->aspect }}{{ $productComment->taste }}{{ $productComment->odor }}{{ $productComment->texture }}
+ @endforeach @endif - +
@if (isset($product->seen_at)) - + @endif @if (isset($product->source)) - + @endif
- {{ __('Téléchargez les documents :') }} - {{ __('ICI') }} - + {{ __('Téléchargez les documents :') }} + {{ __('ICI') }} + -

{{ __('Vu le : ') }}{{ $product->seen_at }}

-

{{ __('Lieu : ') }}{{ $product->source }}, {{ $product->fair }}{{ $product->shop }}{{ $product->catalogue }}

-

{{ __('Par : ') }}{{ $product->user_id->firstname }} {{ $product->user_id->lastname }}

-
+

{{ __('Vu le : ') }}{{ $product->seen_at }}

+

{{ __('Lieu : ') }}{{ $product->source }}, {{ $product->fair }}{{ $product->shop }}{{ $product->catalogue }} +

+

{{ __('Par : ') }}{{ $product->user_id->firstname }} {{ $product->user_id->lastname }}

+