From d2194a2d5cd3d01026f1aa0bea7d6dffe0d62188 Mon Sep 17 00:00:00 2001 From: Bob Wezelman Date: Wed, 22 May 2024 11:44:59 +0200 Subject: [PATCH] Sort images in gallery by position in Magento (#501) --- src/Models/Product.php | 2 +- src/Models/ProductImage.php | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Models/Product.php b/src/Models/Product.php index 772045662..a5b3971fb 100644 --- a/src/Models/Product.php +++ b/src/Models/Product.php @@ -203,7 +203,7 @@ public function getUrlAttribute(): string public function getImagesAttribute(): array { - return $this->gallery->pluck('value')->toArray(); + return $this->gallery->sortBy('productImageValue.position')->pluck('value')->toArray(); } public function getImageAttribute($image): ?string diff --git a/src/Models/ProductImage.php b/src/Models/ProductImage.php index fce7c075e..0443c0573 100644 --- a/src/Models/ProductImage.php +++ b/src/Models/ProductImage.php @@ -10,6 +10,8 @@ class ProductImage extends Model protected $primaryKey = 'value_id'; + protected $with = ['productImageValue']; + protected static function booted(): void { static::addGlobalScope(