From b511dc62e07f3d3051c8f11b2e4eaa7f65f3d787 Mon Sep 17 00:00:00 2001 From: Maxime Leclercq Date: Thu, 28 Nov 2024 10:04:28 +0100 Subject: [PATCH] feat: add method to find images by type --- src/Model/Product/ProductDTO.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Model/Product/ProductDTO.php b/src/Model/Product/ProductDTO.php index a5bad0ef..3622e873 100644 --- a/src/Model/Product/ProductDTO.php +++ b/src/Model/Product/ProductDTO.php @@ -17,4 +17,15 @@ class ProductDTO extends Eater { + public function getImagesByType(string $type): array + { + $images = $this->getData('images') ?? []; + if (!\is_array($images)) { + return []; + } + + return array_filter($images, function ($image) use ($type) { + return \is_object($image) && method_exists($image, 'getType') && $image->getType() === $type; + }); + } }