mirror of
https://github.com/jbcr/SyliusElasticsearchPlugin.git
synced 2026-03-24 00:42:08 +01:00
OP-52: Fix error trying to filter svg image with LiipImagineBundle
This commit is contained in:
@@ -35,13 +35,29 @@ final class ImageTransformerSpec extends ObjectBehavior
|
||||
FilterService $filterService
|
||||
): void {
|
||||
$product->getImagesByType('main')->willReturn(new ArrayCollection([$productImage->getWrappedObject()]));
|
||||
$productImage->getPath()->willReturn('/path-to-image');
|
||||
$productImage->getPath()->willReturn('/path-to-image.png');
|
||||
|
||||
$filterService
|
||||
->getUrlOfFilteredImage('/path-to-image', 'sylius_shop_product_thumbnail')
|
||||
->getUrlOfFilteredImage('/path-to-image.png', 'sylius_shop_product_thumbnail')
|
||||
->shouldBeCalled()
|
||||
;
|
||||
|
||||
$this->transform($product);
|
||||
}
|
||||
|
||||
function it_does_not_transforms_svg_product_images_into_product_thumbnail(
|
||||
ProductInterface $product,
|
||||
ImageInterface $productImage,
|
||||
FilterService $filterService
|
||||
): void {
|
||||
$product->getImagesByType('main')->willReturn(new ArrayCollection([$productImage->getWrappedObject()]));
|
||||
$productImage->getPath()->willReturn('/path-to-image.svg');
|
||||
|
||||
$filterService
|
||||
->getUrlOfFilteredImage('/path-to-image.svg', 'sylius_shop_product_thumbnail')
|
||||
->shouldNotBeCalled()
|
||||
;
|
||||
|
||||
$this->transform($product);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,9 +24,12 @@ final class ImageTransformer implements TransformerInterface
|
||||
|
||||
private FilterService $imagineFilter;
|
||||
|
||||
public function __construct(FilterService $imagineFilter)
|
||||
private string $imagesPath;
|
||||
|
||||
public function __construct(FilterService $imagineFilter, string $imagesPath = '/media/image/')
|
||||
{
|
||||
$this->imagineFilter = $imagineFilter;
|
||||
$this->imagesPath = $imagesPath;
|
||||
}
|
||||
|
||||
public function transform(ProductInterface $product): ?string
|
||||
@@ -40,6 +43,15 @@ final class ImageTransformer implements TransformerInterface
|
||||
/** @var ImageInterface $productImage */
|
||||
$productImage = $productThumbnails->first();
|
||||
|
||||
return $this->imagineFilter->getUrlOfFilteredImage($productImage->getPath(), self::SYLIUS_THUMBNAIL_FILTER);
|
||||
if ($this->canImageBeFiltered($productImage->getPath())) {
|
||||
return $this->imagineFilter->getUrlOfFilteredImage($productImage->getPath(), self::SYLIUS_THUMBNAIL_FILTER);
|
||||
}
|
||||
|
||||
return $this->imagesPath . $productImage->getPath();
|
||||
}
|
||||
|
||||
private function canImageBeFiltered(string $imagePath): bool
|
||||
{
|
||||
return !str_ends_with($imagePath, 'svg');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user