Hotfix: Adding a correct media conversions to handle small review images
This commit is contained in:
@@ -5,8 +5,11 @@ namespace Modules\Core\Review\Models;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Lunar\Models\Product;
|
||||
use Spatie\Image\Enums\BorderType;
|
||||
use Spatie\Image\Enums\Fit;
|
||||
use Spatie\MediaLibrary\HasMedia;
|
||||
use Spatie\MediaLibrary\InteractsWithMedia;
|
||||
use Spatie\MediaLibrary\MediaCollections\Models\Media;
|
||||
|
||||
class ProductReview extends Model implements HasMedia
|
||||
{
|
||||
@@ -30,4 +33,23 @@ class ProductReview extends Model implements HasMedia
|
||||
{
|
||||
$this->addMediaCollection(self::IMAGES_COLLECTION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unlike Product/ProductVariant, this model sits outside Lunar's own
|
||||
* MediaDefinitionsInterface (Lunar\Base\StandardMediaDefinitions), which is
|
||||
* what registers the 'small' conversion those models get automatically. Without
|
||||
* this, Modules\Core\Search\ProductIndexer::mapMedia() — shared across product,
|
||||
* variant, and review media — throws Spatie\MediaLibrary\MediaCollections\
|
||||
* Exceptions\InvalidConversion the first time a review has an image, since
|
||||
* $media->getUrl('small') has no matching conversion to resolve.
|
||||
*/
|
||||
public function registerMediaConversions(?Media $media = null): void
|
||||
{
|
||||
$this->addMediaConversion('small')
|
||||
->fit(Fit::Fill, 300, 300)
|
||||
->border(0, BorderType::Overlay, color: '#FFF')
|
||||
->background('#FFF')
|
||||
->sharpen(10)
|
||||
->keepOriginalImageFormat();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user