Skip to content

Commit efcd9cb

Browse files
authored
Merge pull request #1505 from w3bdesign/develop
Fix product and checkout
2 parents 8d47a92 + f89c47b commit efcd9cb

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

pages/checkout.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
</template>
77

88
<script setup>
9+
import { useCart } from "@/store/useCart";
10+
const cart = useCart();
11+
if (cart.cart.length === 0) {
12+
await navigateTo("/");
13+
}
914
useHead({
1015
title: "Checkout",
1116
titleTemplate: "%s - Nuxt 3 Woocommerce",

pages/product/[product].vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ const route = useRoute();
99
1010
const variables = { id: route.query.id };
1111
const { result } = await useAsyncQuery(GET_SINGLE_PRODUCT_QUERY, variables);
12-
const productData = result.value?.product;
12+
13+
const productData = computed(() => result.value?.product);
1314
1415
useHead({
1516
title: route.params.product,

store/useCart.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,14 @@ export const useCart = defineStore(
9393
loading.value = true;
9494
error.value = null;
9595
try {
96+
const isLastItem = cart.value.length === 1;
9697
await updateCartItemQuantity(key, 0);
98+
if (isLastItem) {
99+
await navigateTo("/");
100+
}
97101
} catch (err) {
98102
} finally {
99103
loading.value = false;
100-
await refetchCart();
101104
}
102105
};
103106

0 commit comments

Comments
 (0)