Add method to get image with parent for article
This commit is contained in:
@@ -80,8 +80,9 @@ class Articles
|
||||
$article = self::get($id);
|
||||
$data = $article->toArray();
|
||||
$data['description'] = (!empty($article->description)) ? $article->description : $article->product->description;
|
||||
$data['image'] = self::getPreview($article->image);
|
||||
$data['image_big'] = self::getImage($article->image);
|
||||
$image = self::getFullImageByArticle($article);
|
||||
$data['image'] = self::getPreview($image);
|
||||
$data['image_big'] = self::getImage($image);
|
||||
$data['inherited'] = self::getInherited($id);
|
||||
$data['categories'] = self::getCategoriesNameByArticle($article);
|
||||
$data['tags'] = self::getTagsSlugByArticle($article);
|
||||
@@ -113,7 +114,7 @@ class Articles
|
||||
if (!is_array($data[$article->name] ?? false)) {
|
||||
$data[$article->name] = [
|
||||
'description' => (!empty($article->description)) ? $article->description : $article->product->description,
|
||||
'image' => $article->image,
|
||||
'image' => self::getFullImageByArticle($article),
|
||||
'product_type' => $article->product_type,
|
||||
'product_id' => $article->product_id,
|
||||
'product_name' => $article->product->name,
|
||||
@@ -324,6 +325,34 @@ class Articles
|
||||
return Article::find($id);
|
||||
}
|
||||
|
||||
public static function getFullImageById($id)
|
||||
{
|
||||
$article = self::get($id);
|
||||
return self::getFullImageByImage($article);
|
||||
}
|
||||
|
||||
public static function getFullImageByArticle($article)
|
||||
{
|
||||
$image = $article->image;
|
||||
if (!$image) {
|
||||
switch ($article->product_type) {
|
||||
case 'App\Models\Botanic\Variety':
|
||||
$variety = $article->product;
|
||||
$image = $variety->image;
|
||||
if (!$image) {
|
||||
$specie = $variety->specie;
|
||||
$image = $specie->image;
|
||||
}
|
||||
break;
|
||||
case 'App\Models\Botanic\Specie':
|
||||
$specie = $article->product;
|
||||
$image = $specie->image;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $image;
|
||||
}
|
||||
|
||||
public static function storeFull($data)
|
||||
{
|
||||
$images = isset($data['images']) ? $data['images'] : false;
|
||||
|
||||
@@ -33,7 +33,8 @@ class Offers
|
||||
|
||||
public static function getThumbSrc(Offer $offer)
|
||||
{
|
||||
return $offer->article ? Articles::getThumbSrc($offer->article->image) : false;
|
||||
$image = $offer->article ? Articles::getFullImageByArticle($offer->article) : false;
|
||||
return $image ? Articles::getThumbSrc($image) : false;
|
||||
}
|
||||
|
||||
public static function getLast()
|
||||
|
||||
Reference in New Issue
Block a user