diff --git a/resources/js/components/Product/AddToCart.vue b/resources/js/components/Product/AddToCart.vue index eca58d1c..9534d40c 100644 --- a/resources/js/components/Product/AddToCart.vue +++ b/resources/js/components/Product/AddToCart.vue @@ -59,11 +59,7 @@ export default { methods: { async add() { - if ( - window.location.pathname !== this.product.url && - (this.product?.has_options || - ('children' in this.product && Object.values(this.product.children).length && !config.show_swatches)) - ) { + if (this.shouldRedirectToProduct) { Turbo.visit(window.url(this.product.url)) return } @@ -262,6 +258,25 @@ 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) { + return false + } + + // Products with product options always have to be set on the product page + if (this.product?.has_options) { + return true + } + + // Check if all super_attributes have an option selected + return Object.keys(this.product?.super_attributes).join(',') !== Object.keys(this.options).join(',') + }, + simpleProduct: function () { var product = this.product diff --git a/resources/views/listing/partials/item.blade.php b/resources/views/listing/partials/item.blade.php index ca066288..c21acda9 100644 --- a/resources/views/listing/partials/item.blade.php +++ b/resources/views/listing/partials/item.blade.php @@ -1,31 +1,33 @@ diff --git a/resources/views/listing/partials/item/addtocart.blade.php b/resources/views/listing/partials/item/addtocart.blade.php index ad53e05b..1574e74d 100644 --- a/resources/views/listing/partials/item/addtocart.blade.php +++ b/resources/views/listing/partials/item/addtocart.blade.php @@ -1,21 +1,19 @@ - -
-
-
- @{{ (addToCart.simpleProduct.special_price || addToCart.simpleProduct.price) | price }} -
-
- @{{ addToCart.simpleProduct.price | price }} -
+ +
+
+ @{{ (addToCart.simpleProduct.special_price || addToCart.simpleProduct.price) | price }}
+
+ @{{ addToCart.simpleProduct.price | price }} +
+
-

- @lang('Sorry! This product is currently out of stock.') -

-
- @include('rapidez::listing.partials.item.super_attributes') +

+ @lang('Sorry! This product is currently out of stock.') +

+
+ @includeWhen(Rapidez::config('catalog/frontend/show_swatches_in_product_list', 1), 'rapidez::listing.partials.item.super_attributes') - -
- - + +
+