Skip to content

Commit

Permalink
Sort images in gallery by position in Magento (#500)
Browse files Browse the repository at this point in the history
  • Loading branch information
BobWez98 authored May 22, 2024
1 parent 4c67c73 commit 373d531
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Models/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/Models/ProductImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class ProductImage extends Model

protected $primaryKey = 'value_id';

protected $with = ['productImageValue'];

protected static function booted(): void
{
static::addGlobalScope(
Expand Down

0 comments on commit 373d531

Please sign in to comment.