Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion resources/js/components/Product/AddToCart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,26 @@ 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 () {
// Can't have a second image if there are no images
if (!this.currentThumbnail || !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) ?? []
},

matchingChildren: function () {
Expand Down
34 changes: 23 additions & 11 deletions resources/views/listing/partials/item.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,29 @@
<add-to-cart v-bind:product="item" v-slot="addToCart" v-cloak>
<div class="group relative flex flex-1 flex-col rounded-sm bg-white h-full">
<a :href="url(addToCart.productUrl)" v-on:click="sendEvent('click', item, 'Hit Clicked')" class="block mb-auto">
<img
v-if="addToCart.currentThumbnail"
:src="url('/storage/{{ config('rapidez.store') }}/resizes/200/magento/catalog/product' + addToCart.currentThumbnail + '.webp')"
class="mb-3 h-48 w-full rounded-t-sm object-contain"
:alt="item.name"
:loading="config.category && count <= 4 ? 'eager' : 'lazy'"
v-bind:style="{ 'view-transition-name': 'image-' + item.sku }"
width="200"
height="200"
/>
<x-rapidez::no-image v-else="" class="mb-3 h-48 rounded-t-sm" />
<div class="relative mb-3 h-48 w-full">
<img
v-if="addToCart.currentThumbnail"
:src="url('/storage/{{ config('rapidez.store') }}/resizes/200/magento/catalog/product' + addToCart.currentThumbnail + '.webp')"
class="size-full rounded-t-sm object-contain"
v-bind:class="{ 'group-hover:opacity-0 transition-opacity': addToCart.hoverImage }"
:alt="item.name"
:loading="config.category && count <= 4 ? 'eager' : 'lazy'"
v-bind:style="{ 'view-transition-name': 'image-' + item.sku }"
width="200"
height="200"
/>
<x-rapidez::no-image v-else="" class="size-full rounded-t-sm" />
<img
v-if="addToCart.hoverImage"
:src="url('/storage/{{ config('rapidez.store') }}/resizes/200/magento/catalog/product' + addToCart.hoverImage + '.webp')"
class="absolute inset-0 size-full rounded-t-sm object-contain opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none"
alt=""
loading="lazy"
width="200"
height="200"
/>
</div>
<div>
<x-rapidez::highlight attribute="name" class="text-base font-medium hover:underline decoration-2"/>
@if (App::providerIsLoaded('Rapidez\Reviews\ReviewsServiceProvider'))
Expand Down
Loading