From 76f49e74f5727fcc5186b89bdd3fdfab7db4a05d Mon Sep 17 00:00:00 2001 From: Yoga Pangestu Date: Tue, 25 Aug 2026 10:30:33 +0700 Subject: [PATCH] feat: add photo URLs to product variants for improved media handling --- app/Services/Admin/Master/Product/ProductService.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/Services/Admin/Master/Product/ProductService.php b/app/Services/Admin/Master/Product/ProductService.php index 19e384c..63c1ce6 100644 --- a/app/Services/Admin/Master/Product/ProductService.php +++ b/app/Services/Admin/Master/Product/ProductService.php @@ -93,6 +93,17 @@ public function getVariants(Product $product): Collection ->values() ->toArray(); + $firstMedia = $allMedia->first(); + if ($firstMedia) { + $variant->photo_url = $this->s3Service->getTemporaryUrl($firstMedia->getPath()); + $variant->photo_conversion_url = $firstMedia->getGeneratedConversions()->contains('thumb') + ? $this->s3Service->getTemporaryUrl($firstMedia->getPath('thumb')) + : $this->s3Service->getTemporaryUrl($firstMedia->getPath()); + } else { + $variant->photo_url = null; + $variant->photo_conversion_url = null; + } + $prices = $variant->productPrices->mapWithKeys(fn ($p) => [$p->type->value => $p->price]); $variant->prices = $prices; });