diff --git a/app/Repositories/Shop/ArticleTags.php b/app/Repositories/Shop/ArticleTags.php index 053e3e76..4d84f437 100644 --- a/app/Repositories/Shop/ArticleTags.php +++ b/app/Repositories/Shop/ArticleTags.php @@ -27,21 +27,34 @@ class ArticleTags switch ($article->product_type) { case 'App\Models\Botanic\Variety': - $data += $article->product->tags->toArray(); - if ($article->product->specie ?? false) { - $data += $article->product->specie->tags->toArray(); + $variety = $article->product; + if ($variety && $variety->tags) { + $data = array_merge($data, $variety->tags->toArray()); + } + if ($variety && $variety->specie && $variety->specie->tags) { + $data = array_merge($data, $variety->specie->tags->toArray()); } break; case 'App\Models\Botanic\Specie': - $data += $article->product->tags->toArray(); + $specie = $article->product; + if ($specie && $specie->tags) { + $data = array_merge($data, $specie->tags->toArray()); + } break; case 'App\Models\Shop\Merchandise': - $data += $article->product->tags->toArray(); - $data += $article->product->producer->tags->toArray(); + $merchandise = $article->product; + if ($merchandise && $merchandise->tags) { + $data = array_merge($data, $merchandise->tags->toArray()); + } + if ($merchandise && $merchandise->producer && $merchandise->producer->tags) { + $data = array_merge($data, $merchandise->producer->tags->toArray()); + } break; default: } - $data += $article->tags->toArray(); + if ($article->tags) { + $data = array_merge($data, $article->tags->toArray()); + } foreach ($data as $tag) { if (! isset($tags[$tag['group']][$tag['name']])) { diff --git a/app/Repositories/Shop/Articles.php b/app/Repositories/Shop/Articles.php index fe0cf1ea..354f1cad 100644 --- a/app/Repositories/Shop/Articles.php +++ b/app/Repositories/Shop/Articles.php @@ -135,8 +135,11 @@ class Articles $data['specie'] = $article->product ? $article->product->description : ''; break; case 'App\Models\Shop\Merchandise': - $data['merchandise'] = $article->product ? $article->product->description : ''; - $data['producer'] = $article->product->producer->description; + $merchandise = $article->product; + $data['merchandise'] = $merchandise ? ($merchandise->description ?? '') : ''; + if ($merchandise && $merchandise->producer) { + $data['producer'] = $merchandise->producer->description ?? ''; + } break; default: }