refactoring on Articles, minor fixes
This commit is contained in:
65
app/Repositories/Shop/ArticleInherited.php
Normal file
65
app/Repositories/Shop/ArticleInherited.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\Article;
|
||||
use App\Repositories\Botanic\Species;
|
||||
use App\Repositories\Botanic\Varieties;
|
||||
|
||||
class ArticleInherited
|
||||
{
|
||||
public static function getInherited($id)
|
||||
{
|
||||
$article = Article::with('product.tags.tag_group')->findOrFail($id);
|
||||
|
||||
return self::getInheritedByProduct($article->product_id, $article->product_type);
|
||||
}
|
||||
|
||||
public static function getInheritedByProduct($product_id, $product_type)
|
||||
{
|
||||
$data = [];
|
||||
switch ($product_type) {
|
||||
case 'App\Models\Botanic\Variety':
|
||||
$product = Varieties::get($product_id);
|
||||
if (! $product) {
|
||||
break;
|
||||
}
|
||||
$data[] = [
|
||||
'name' => 'Espèces',
|
||||
'description' => Species::getDescription($product->specie_id),
|
||||
'tags' => Species::getTags($product->specie_id),
|
||||
];
|
||||
$data[] = [
|
||||
'name' => 'Variétés',
|
||||
'description' => $product->description,
|
||||
'tags' => $product->tags->toArray(),
|
||||
];
|
||||
break;
|
||||
case 'App\Models\Botanic\Specie':
|
||||
$product = Species::get($product_id);
|
||||
if (! $product) {
|
||||
break;
|
||||
}
|
||||
$data[] = [
|
||||
'name' => 'Espèces',
|
||||
'description' => $product->description,
|
||||
'tags' => $product->tags->toArray(),
|
||||
];
|
||||
break;
|
||||
case 'App\Models\Shop\Merchandise':
|
||||
$product = Merchandises::get($product_id);
|
||||
if (! $product) {
|
||||
break;
|
||||
}
|
||||
$data[] = [
|
||||
'name' => 'Marchandise',
|
||||
'description' => $product->description,
|
||||
'tags' => $product->tags->toArray(),
|
||||
];
|
||||
break;
|
||||
default:
|
||||
}
|
||||
|
||||
return $data ?? false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user