Skip to content

Commit

Permalink
Move show_swatches check to only be around the super_attributes & thu…
Browse files Browse the repository at this point in the history
…mbnail depends on selected options
  • Loading branch information
Jade-GG committed Jan 9, 2025
1 parent f852c8e commit 224029e
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 45 deletions.
4 changes: 4 additions & 0 deletions resources/js/components/Product/AddToCart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,10 @@ export default {
},
computed: {
currentThumbnail: function() {
return this.simpleProduct?.thumbnail || this.simpleProduct?.images?.[0] || this.product?.thumbnail
},
shouldRedirectToProduct: function () {
// Never redirect if we're already on the product page
if (window.location.pathname === this.product.url) {
Expand Down
56 changes: 29 additions & 27 deletions resources/views/listing/partials/item.blade.php
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
<template {!! isset($slider) ? '' : 'slot="renderItem" slot-scope="{ item, count }"' !!}>
<div class="my-0.5 w-full h-full shrink-0 snap-start px-0.5 sm:my-2 sm:px-2 sm:w-1/2 lg:w-1/3">
<div class="group relative flex flex-1 flex-col rounded border bg-white p-5" :key="item.entity_id">
@if (App::providerIsLoaded('Rapidez\Wishlist\WishlistServiceProvider'))
<div class="group absolute right-0 top-0 z-10 p-2">
@include('rapidez::wishlist.button')
</div>
@endif
<a :href="item.url | url" class="block">
<img
v-if="item.thumbnail"
:src="'/storage/{{ config('rapidez.store') }}/resizes/200/magento/catalog/product' + item.thumbnail + '.webp'"
class="mb-3 h-48 w-full rounded-t object-contain" :alt="item.name" :loading="config.category && count <= 4 ? 'eager' : 'lazy'"
width="200"
height="200"
/>
<x-rapidez::no-image v-else class="mb-3 h-48 rounded-t" />
<div class="px-2">
<div class="text-base font-medium">@{{ item.name }}</div>
@if (!Rapidez::config('catalog/frontend/show_swatches_in_product_list', 1))
<div class="flex items-center space-x-2">
<div class="font-semibold">@{{ (item.special_price || item.price) | price }}</div>
<div class="text-sm line-through" v-if="item.special_price">@{{ item.price | price }}</div>
</div>
@endif
</div>
</a>
@includeWhen(Rapidez::config('catalog/frontend/show_swatches_in_product_list', 1), 'rapidez::listing.partials.item.addtocart')
</div>
<add-to-cart v-bind:product="item" v-slot="addToCart" v-cloak>
<div class="group relative flex flex-1 flex-col rounded border bg-white p-5" :key="item.entity_id">
@if (App::providerIsLoaded('Rapidez\Wishlist\WishlistServiceProvider'))
<div class="group absolute right-0 top-0 z-10 p-2">
@include('rapidez::wishlist.button')
</div>
@endif
<a :href="item.url | url" class="block">
<img
v-if="addToCart.currentThumbnail"
:src="'/storage/{{ config('rapidez.store') }}/resizes/200/magento/catalog/product' + addToCart.currentThumbnail + '.webp'"
class="mb-3 h-48 w-full rounded-t object-contain" :alt="item.name" :loading="config.category && count <= 4 ? 'eager' : 'lazy'"
width="200"
height="200"
/>
<x-rapidez::no-image v-else class="mb-3 h-48 rounded-t" />
<div class="px-2">
<div class="text-base font-medium">@{{ item.name }}</div>
@if (!Rapidez::config('catalog/frontend/show_swatches_in_product_list', 1))
<div class="flex items-center space-x-2">
<div class="font-semibold">@{{ (item.special_price || item.price) | price }}</div>
<div class="text-sm line-through" v-if="item.special_price">@{{ item.price | price }}</div>
</div>
@endif
</div>
</a>
@include('rapidez::listing.partials.item.addtocart')
</div>
</add-to-cart>
</div>
</template>
34 changes: 16 additions & 18 deletions resources/views/listing/partials/item/addtocart.blade.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
<add-to-cart v-bind:product="item" v-slot="addToCart" v-cloak>
<form class="px-2 pb-2" v-on:submit.prevent="addToCart.add">
<div class="flex items-center space-x-2 mb-2">
<div class="font-semibold">
@{{ (addToCart.simpleProduct.special_price || addToCart.simpleProduct.price) | price }}
</div>
<div class="line-through text-sm" v-if="addToCart.simpleProduct.special_price">
@{{ addToCart.simpleProduct.price | price }}
</div>
<form class="px-2 pb-2" v-on:submit.prevent="addToCart.add">
<div class="flex items-center space-x-2 mb-2">
<div class="font-semibold">
@{{ (addToCart.simpleProduct.special_price || addToCart.simpleProduct.price) | price }}
</div>
<div class="line-through text-sm" v-if="addToCart.simpleProduct.special_price">
@{{ addToCart.simpleProduct.price | price }}
</div>
</div>

<p v-if="!item.in_stock" class="text-red-600 text-xs">
@lang('Sorry! This product is currently out of stock.')
</p>
<div v-else>
@include('rapidez::listing.partials.item.super_attributes')
<p v-if="!item.in_stock" class="text-red-600 text-xs">
@lang('Sorry! This product is currently out of stock.')
</p>
<div v-else>
@includeWhen(Rapidez::config('catalog/frontend/show_swatches_in_product_list', 1), 'rapidez::listing.partials.item.super_attributes')

<x-rapidez::button.cart/>
</div>
</form>
</add-to-cart>
<x-rapidez::button.cart/>
</div>
</form>

0 comments on commit 224029e

Please sign in to comment.