From f852c8ecc2862dd7ce3e88f308b584b2114f9de5 Mon Sep 17 00:00:00 2001 From: Jade Geels Date: Thu, 9 Jan 2025 14:53:27 +0100 Subject: [PATCH 1/3] Fix add to cart always redirecting on products with super attributes --- resources/js/components/Product/AddToCart.vue | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/resources/js/components/Product/AddToCart.vue b/resources/js/components/Product/AddToCart.vue index eca58d1c..bdd1de6e 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,21 @@ export default { }, computed: { + 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 From 224029ebe104606e00e7d5e149ea084aa0d6955a Mon Sep 17 00:00:00 2001 From: Jade Geels Date: Thu, 9 Jan 2025 15:09:17 +0100 Subject: [PATCH 2/3] Move show_swatches check to only be around the super_attributes & thumbnail depends on selected options --- resources/js/components/Product/AddToCart.vue | 4 ++ .../views/listing/partials/item.blade.php | 56 ++++++++++--------- .../listing/partials/item/addtocart.blade.php | 34 ++++++----- 3 files changed, 49 insertions(+), 45 deletions(-) diff --git a/resources/js/components/Product/AddToCart.vue b/resources/js/components/Product/AddToCart.vue index bdd1de6e..e8f6e7fc 100644 --- a/resources/js/components/Product/AddToCart.vue +++ b/resources/js/components/Product/AddToCart.vue @@ -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) { diff --git a/resources/views/listing/partials/item.blade.php b/resources/views/listing/partials/item.blade.php index 57ac0fa2..f1004772 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') - -
- - + +
+ From 5c6b8944873492f77820f953acffb0d3fed1efb7 Mon Sep 17 00:00:00 2001 From: Jade-GG Date: Thu, 9 Jan 2025 14:10:17 +0000 Subject: [PATCH 3/3] Apply fixes from Prettier --- resources/js/components/Product/AddToCart.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/js/components/Product/AddToCart.vue b/resources/js/components/Product/AddToCart.vue index e8f6e7fc..9534d40c 100644 --- a/resources/js/components/Product/AddToCart.vue +++ b/resources/js/components/Product/AddToCart.vue @@ -258,7 +258,7 @@ export default { }, computed: { - currentThumbnail: function() { + currentThumbnail: function () { return this.simpleProduct?.thumbnail || this.simpleProduct?.images?.[0] || this.product?.thumbnail },