Show Variation Images on Product Page
-
Hi, I am just testing Bagisto so far I like it I have one question with regards to variations...
Is there anyway to show all the product variation images on the parent product page rather than uploading them to the parent product as well as each variation? The parent images get shown when a variant has been selected. The problem here is that if you add all the images to the parent then the images get doubled up.
This is the parent product with no options selected but a default image applied.
This is the variation selected, note how the red image is duplicated as it is both the product image and the variation image. Ideally all images should be shown with no duplication of the variation image.
Any thoughts on how to achieve this?
Thanks
Simon -
Hi @SiCo
As you can see, we have a created ProductImage Helper to get product images in Product package.
In this helper there is a method called getGalleryImages which is returning images of product.To show all variant images on product view page, first off all you need to override 'gallery.blade.php'.
Then create a helper function in your package and called your helper using your overrided view file.Paste given code in your helpers getGalleryImages method.
/** * Retrieve collection of gallery images * * @param Product $product * @return array */ public function getGalleryImages($product) { if (! $product) return []; $images = []; if ($product->product->type == 'configurable') { foreach ($product->variants as $variant) { foreach ($variant->images as $image) { if (! Storage::has($image->path)) continue; $images[] = [ 'small_image_url' => url('cache/small/' . $image->path), 'medium_image_url' => url('cache/medium/' . $image->path), 'large_image_url' => url('cache/large/' . $image->path), 'original_image_url' => url('cache/original/' . $image->path), ]; } } } foreach ($product->images as $image) { if (! Storage::has($image->path)) continue; $images[] = [ 'small_image_url' => url('cache/small/' . $image->path), 'medium_image_url' => url('cache/medium/' . $image->path), 'large_image_url' => url('cache/large/' . $image->path), 'original_image_url' => url('cache/original/' . $image->path), ]; } if (! $product->parent_id && ! count($images)) { $images[] = [ 'small_image_url' => asset('vendor/webkul/ui/assets/images/product/small-product-placeholder.png'), 'medium_image_url' => asset('vendor/webkul/ui/assets/images/product/meduim-product-placeholder.png'), 'large_image_url' => asset('vendor/webkul/ui/assets/images/product/large-product-placeholder.png'), 'original_image_url' => asset('vendor/webkul/ui/assets/images/product/large-product-placeholder.png') ]; } return $images; }
Follow this link to override view file - https://forums.bagisto.com/topic/221/how-to-override-view-file-in-bagisto
Thanks