diff --git a/config/rapidez/searchkit.php b/config/rapidez/searchkit.php index 1ede85549..e2659ea59 100644 --- a/config/rapidez/searchkit.php +++ b/config/rapidez/searchkit.php @@ -25,7 +25,7 @@ 'price', 'special_price', 'image', - 'images', + 'media', 'url', 'thumbnail', 'has_options', diff --git a/resources/js/components/Product/AddToCart.vue b/resources/js/components/Product/AddToCart.vue index dbc4d469e..46ee0df69 100644 --- a/resources/js/components/Product/AddToCart.vue +++ b/resources/js/components/Product/AddToCart.vue @@ -311,7 +311,30 @@ export default { computed: { currentThumbnail: function () { - return this.simpleProduct?.thumbnail || this.simpleProduct?.images?.[0] || this.product?.thumbnail + return this.simpleProduct?.thumbnail || this.images[0] || this.product?.thumbnail + }, + + hoverImage: function () { + if (!this.currentThumbnail) { + return null + } + + // Can't have a second image if there are no images + if (!this.images.length) { + return null + } + + // Return the second image if the thumbnail is also the first image + if (this.currentThumbnail == this.images[0]) { + return this.images[1] ?? null + } + + // Otherwise, return the first image because the thumbnail is something else + return this.images[0] + }, + + images: function () { + return this.simpleProduct?.media?.filter((media) => media.media_type == 'image')?.map((media) => media.image) ?? [] }, shouldRedirectToProduct: function () { diff --git a/resources/js/components/Product/Images.vue b/resources/js/components/Product/Images.vue index 94113d088..4116561e6 100644 --- a/resources/js/components/Product/Images.vue +++ b/resources/js/components/Product/Images.vue @@ -3,7 +3,6 @@ import { useEventListener } from '@vueuse/core' export default { data: () => ({ - images: config.product.images, media: config.product.media, active: 0, zoomed: false, @@ -30,7 +29,6 @@ export default { child === simpleProduct && Object.values(window.config.product.super_attributes).filter((attribute) => attribute.update_image).length ) { - self.images = simpleProduct.images self.media = simpleProduct.media.toSorted((a, b) => a.position - b.position) self.active = Math.min(self.active, self.media.length - 1) } diff --git a/resources/views/listing/partials/item.blade.php b/resources/views/listing/partials/item.blade.php index d5391b593..860f797a2 100644 --- a/resources/views/listing/partials/item.blade.php +++ b/resources/views/listing/partials/item.blade.php @@ -2,17 +2,28 @@
- - +
+ + + +
@if (App::providerIsLoaded('Rapidez\Reviews\ReviewsServiceProvider')) diff --git a/resources/views/product/partials/images.blade.php b/resources/views/product/partials/images.blade.php index a9067ac13..554d7a456 100644 --- a/resources/views/product/partials/images.blade.php +++ b/resources/views/product/partials/images.blade.php @@ -1,6 +1,6 @@
-
+
@include('rapidez::product.partials.gallery.slider') @include('rapidez::product.partials.gallery.thumbnails') diff --git a/src/Casts/Children.php b/src/Casts/Children.php index 3010d6179..225e0f328 100644 --- a/src/Casts/Children.php +++ b/src/Casts/Children.php @@ -25,7 +25,7 @@ public function get($model, $key, $value, $attributes) } } - $child->images = isset($child->images) ? collect($child?->images)->sortBy('position')->pluck('value')->toArray() : []; + $child->media = isset($child->media) ? collect($child?->media)->sortBy('position')->toArray() : []; unset($child->special_from_date, $child->special_to_date); } diff --git a/src/Models/Traits/Product/Searchable.php b/src/Models/Traits/Product/Searchable.php index ef2f60e52..611835b69 100644 --- a/src/Models/Traits/Product/Searchable.php +++ b/src/Models/Traits/Product/Searchable.php @@ -78,6 +78,7 @@ public function toSearchableArray(): array ->mapWithKeys(fn ($position, $category_id) => [$category_id => $maxPositions[$category_id] - $position]); $data['popularity'] = $this->getPopularity(); + $data['media'] = $this->media; return Eventy::filter('index.' . static::getModelName() . '.data', $data, $this); }