Skip to content

Commit

Permalink
feat: add method to find images by type
Browse files Browse the repository at this point in the history
  • Loading branch information
delyriand committed Nov 28, 2024
1 parent 11f2bde commit b511dc6
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Model/Product/ProductDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
}
}

0 comments on commit b511dc6

Please sign in to comment.