[WIP] Refactor models to better lisibility and speed

This commit is contained in:
Ludovic CANDELLIER
2020-08-24 01:14:54 +02:00
parent 77a239fce9
commit 3b6108b449
22 changed files with 351 additions and 400 deletions

View File

@@ -30,7 +30,6 @@ class Articles
$data = $article->toArray();
$data['categories'] = self::getCategoriesByArticle($article);
$data['tags'] = self::getTagsByArticle($article);
// $data['attributes'] = self::getAttributesByArticle($article);
$data['prices'] = self::getPricesByArticle($article);
self::getMeta($data);
return $data;
@@ -41,7 +40,7 @@ class Articles
$data['categories_options'] = Categories::getOptions();
$data['families_options'] = ArticleFamilies::getOptions();
$data['taxes_options'] = Taxes::getOptions();
$data['attribute_families_options'] = ArticleAttributeFamilies::getOptions();
$data['attribute_families_options'] = PriceFamilies::getOptions();
$data['tags_list'] = TagGroups::getTreeTags();
$data['models_options'] = ['App\Models\Botanic\Specie' => 'Espèces', 'App\Models\Botanic\Variety' => 'Variétés'];
return $data;
@@ -49,7 +48,8 @@ class Articles
public static function getByCategory($category_id)
{
return Article::with(['prices.article_attribute.attribute_value','product','image'])->get();
// TODO add category
return Article::with(['prices','product','image'])->get();
}
public static function getCategoriesByArticle($article)
@@ -62,14 +62,9 @@ class Articles
return $article->tags->pluck('id')->toArray();
}
public static function getAttributesByArticle($article)
{
return ArticleAttributes::getByArticleWithPrices($article->id)->toArray();
}
public static function getPricesByArticle($article)
{
return ArticlePrices::getByArticleWithAttribute($article->id)->toArray();
return Prices::getByArticle($article->id)->toArray();
}
public static function get($id)