Merge branch 'schema-org-again' into 'develop'

fix: 🐛 fix schema condition to prevents loop between recipe and product models

See merge request ldc-web/projets/le-gaulois!224
This commit is contained in:
noah.lancien 2025-06-11 14:36:53 +00:00
commit 046fe6dfc4
5 changed files with 27 additions and 24 deletions

View file

@ -79,7 +79,7 @@ class ProductController extends Controller
public function show(string $slug): \Illuminate\Contracts\View\View
{
/** @var \App\Models\Product|null $productModel Current product model */
$productModel = Product::query()->where('slug', $slug)->first();
$productModel = Product::query()->where([['slug', $slug], ['published', true]])->first();
if (is_null($productModel)) {
abort(404);
}

View file

@ -75,7 +75,7 @@ class RecipeController extends Controller
public function show(string $slug): \Illuminate\Contracts\View\View
{
/** @var \App\Models\Recipe|null $recipeModel Current recipe model */
$recipeModel = Recipe::query()->where('slug', $slug)->with([
$recipeModel = Recipe::query()->where([['slug', $slug], ['published', true]])->with([
'products.meat',
'products.submeat',
'products.approach'
@ -87,9 +87,10 @@ class RecipeController extends Controller
$staticPageModel = StaticPage::getCachedStaticPage(StaticPageType::recipe);
return view('fo.pages.recipes.show', [
'recipeModel' => $recipeModel,
'recipeModels' => $this->getRecipesFiltered($recipeModel),
'staticPageModel' => $staticPageModel,
'recipeModel' => $recipeModel,
'recipeModels' => $this->getRecipesFiltered($recipeModel),
'associatedProductModels' => $recipeModel->products->where('published', true),
'staticPageModel' => $staticPageModel,
]);
}

View file

@ -293,7 +293,7 @@ class Product extends Model implements SeoInterface, Sitemapable, SchemaOrgInter
// Recipes associated.
if ($model->recipes->count() && !$asReference) {
$schema->subjectOf($model->recipes->where('published', true)->map(function (Recipe $recipe) {
return $recipe->toSchemaOrg();
return $recipe->toSchemaOrg(true);
})->toArray());
}
@ -318,7 +318,7 @@ class Product extends Model implements SeoInterface, Sitemapable, SchemaOrgInter
} else {
array_push($categories, $model->subrange->toSchemaOrg());
}
if ($model->load('claims')->meat_id) {
if ($model->meat_id) {
array_push($categories, $model->meat->toSchemaOrg());
} else {
array_push($categories, $model->submeat->toSchemaOrg());

View file

@ -327,7 +327,7 @@ class Recipe extends Model implements SeoInterface, Sitemapable, SchemaOrgInterf
$schema->recipeIngredient($ingredientsList);
// Products associated.
if (!$asReference) {
if ($model->products->count() && !$asReference) {
$linkedProducts = $model->products->map(function (Product $product) {
return $product->toSchemaOrg(true);
})->toArray();

View file

@ -133,18 +133,20 @@
</p>
</li>
</ul>
<div class="row my-4">
<div class="col-12">
<h4>{{ str(__('réalisé avec'))->upper() }}</h4>
</div>
@foreach ($recipeModel->products as $productModel)
<div class="col-12 col-xl-6">
@include('fo.partials.product-card-tiny', [
'productModel' => $productModel,
])
@if ($associatedProductModels->count())
<div class="row my-4">
<div class="col-12">
<h4>{{ str(__('réalisé avec'))->upper() }}</h4>
</div>
@endforeach
</div>
@foreach ($associatedProductModels as $productModel)
<div class="col-12 col-xl-6">
@include('fo.partials.product-card-tiny', [
'productModel' => $productModel,
])
</div>
@endforeach
</div>
@endif
<div class="bottom-left-shadow">
<div class="d-md-none line-border-small w-100 bg-white p-4">
<h4>{{ str(__('les ingrédients'))->upper() }}</h4>
@ -167,17 +169,17 @@
</div>
</section>
{{-- RECIPES --}}
@if ($recipeModels->isNotEmpty())
@if ($recipeModels->isNotEmpty() && $associatedProductModels->count())
@include('fo.partials.cards-slider', [
'id' => 'recipe',
'title' => $staticPageModel->data['recipes_title']['value'],
'text' => $staticPageModel->data['text']['value'],
'models' => $recipeModels,
'btnRouteName' => $recipeModel->products->first()->meat
? route('fo.recipes.search.meat', $recipeModel->products->first()->meat->slug)
'btnRouteName' => $associatedProductModels->first()->meat
? route('fo.recipes.search.meat', $associatedProductModels->first()->meat->slug)
: route('fo.recipes.search.submeat', [
'model_slug' => $recipeModel->products->first()->submeat->first()->meat->slug,
'child_slug' => $recipeModel->products->first()->submeat->slug,
'model_slug' => $associatedProductModels->first()->submeat->first()->meat->slug,
'child_slug' => $associatedProductModels->first()->submeat->slug,
]),
'btnRouteTitle' => 'nos recettes',
])