Refactor article getter for descriptions & tags, minor fixes on tags
This commit is contained in:
@@ -30,6 +30,7 @@ class Articles
|
||||
public static function getOffersGroupedByNature($id, $sale_channel_id = false)
|
||||
{
|
||||
$article_ids = self::getSiblingsIds($id);
|
||||
$article_ids[] = $id;
|
||||
$offers = Offers::getOffersByArticles($article_ids, $sale_channel_id);
|
||||
foreach ($offers as $offer) {
|
||||
$data[strtolower($offer->article_nature->name)][] = [
|
||||
@@ -92,10 +93,16 @@ class Articles
|
||||
}
|
||||
|
||||
public static function getArticleToSell($id, $sale_channel_id = false)
|
||||
{
|
||||
$data = self::getArticle($id);
|
||||
$data['offers'] = self::getOffersGroupedByNature($id, $sale_channel_id);
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getArticle($id)
|
||||
{
|
||||
$article = self::get($id);
|
||||
$data = $article->toArray();
|
||||
// $parents = self::getInheritedByProduct($article->product_id, $article->product_type);
|
||||
$data['description'] = self::getFullDescriptionByArticle($article);
|
||||
$images = self::getFullImagesByArticle($article);
|
||||
$data['image'] = self::getPreviewSrc($images[0] ?? false);
|
||||
@@ -103,8 +110,8 @@ class Articles
|
||||
$data['image_big'] = self::getImageSrc($images[0] ?? false);
|
||||
$data['inherited'] = self::getInherited($id);
|
||||
$data['categories'] = self::getCategoriesNameByArticle($article);
|
||||
$data['tags'] = self::getTagsSlugByArticle($article);
|
||||
$data['offers'] = self::getOffersGroupedByNature($id, $sale_channel_id);
|
||||
$data['tags'] = self::getFullTagsSlugByArticle($article);
|
||||
$data['comments'] = Comments::getByModel($article);
|
||||
return $data;
|
||||
}
|
||||
|
||||
@@ -113,6 +120,7 @@ class Articles
|
||||
switch ($article->product_type) {
|
||||
case 'App\Models\Botanic\Variety':
|
||||
$data['variety'] = $article->product->description;
|
||||
$data['plus'] = $article->product->plus;
|
||||
if ($article->product->specie->description ?? false) {
|
||||
$data['specie'] = $article->product->specie->description;
|
||||
}
|
||||
@@ -122,6 +130,7 @@ class Articles
|
||||
break;
|
||||
case 'App\Models\Shop\Merchandise':
|
||||
$data['merchandise'] = $article->product->description;
|
||||
$data['producer'] = $article->product->producer->description;
|
||||
break;
|
||||
default:
|
||||
}
|
||||
@@ -132,20 +141,14 @@ class Articles
|
||||
if ($siblings) {
|
||||
array_push($data, $siblings);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getArticle($id)
|
||||
{
|
||||
$article = self::get($id);
|
||||
$data = $article->toArray();
|
||||
$data['description'] = (!empty($article->description)) ? $article->description : $article->product->description;
|
||||
$data['image'] = Articles::getPreview($article->image);
|
||||
$data['image_big'] = Articles::getImage($article->image);
|
||||
$data['inherited'] = self::getInherited($id);
|
||||
$data['categories'] = self::getCategoriesNameByArticle($article);
|
||||
$data['tags'] = self::getTagsSlugByArticle($article);
|
||||
$data['comments'] = Comments::getByModel($article);
|
||||
/*
|
||||
$data['resume'] = ($data['semences'] ?? null) .
|
||||
($data['plants'] ?? null) .
|
||||
($data['variety'] ?? null) .
|
||||
($data['merchandise'] ?? null) .
|
||||
($data['plus'] ?? null);
|
||||
*/
|
||||
$data['description'] = $article->description;
|
||||
return $data;
|
||||
}
|
||||
|
||||
@@ -421,6 +424,36 @@ class Articles
|
||||
return $article->tags->pluck('slug', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getFullTagsSlugByArticle($article)
|
||||
{
|
||||
$data = [];
|
||||
|
||||
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();
|
||||
}
|
||||
break;
|
||||
case 'App\Models\Botanic\Specie':
|
||||
$data += $article->product->tags->toArray();
|
||||
break;
|
||||
case 'App\Models\Shop\Merchandise':
|
||||
$data += $article->product->tags->toArray();
|
||||
$data += $article->product->producer->tags->toArray();
|
||||
break;
|
||||
default:
|
||||
}
|
||||
$data += $article->tags->toArray();
|
||||
|
||||
foreach ($data as $tag) {
|
||||
if (!isset($tags[$tag['group']][$tag['name']])) {
|
||||
$tags[$tag['group']][] = $tag['name'];
|
||||
}
|
||||
}
|
||||
return $tags;
|
||||
}
|
||||
|
||||
public static function getPricesByArticle($article)
|
||||
{
|
||||
return Prices::getByArticle($article->id);
|
||||
@@ -472,8 +505,7 @@ class Articles
|
||||
|
||||
public static function getFullImageById($id)
|
||||
{
|
||||
$article = self::get($id);
|
||||
return self::getFullImageByImage($article);
|
||||
return self::getFullImageByArticle(self::get($id));
|
||||
}
|
||||
|
||||
public static function getFullImageByArticle($article)
|
||||
|
||||
Reference in New Issue
Block a user