Skip to content

Commit cc54c25

Browse files
authored
Merge pull request #1013 from w3bdesign/1012-clear-cart-on-successful-order
1012 clear cart on successful order
2 parents 8529bf0 + eae084c commit cc54c25

File tree

2 files changed

+9
-27
lines changed

2 files changed

+9
-27
lines changed

pages/success.vue

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

88
<script setup>
9+
import { useCart } from "@/store/useCart";
10+
11+
const cart = useCart();
12+
13+
onBeforeMount(() => {
14+
cart.clearCart();
15+
});
16+
917
useHead({
1018
title: "Order placed",
1119
titleTemplate: "%s - Nuxt 3 Woocommerce",

store/useCart.js

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import { defineStore } from "pinia";
22

33
const state = {
44
cart: [],
5-
order: {},
6-
customer: {},
75
loading: true,
86
error: null,
97
};
@@ -26,39 +24,15 @@ export const useCart = defineStore("cartState", {
2624
removeProductFromCart(product) {
2725
this.cart.splice(this.cart.indexOf(product), 1);
2826
},
29-
3027
clearCart() {
3128
this.cart.length = 0;
3229
},
33-
clearCustomer() {
34-
this.customer = {};
35-
},
36-
clearOrder() {
37-
this.order = {};
38-
},
39-
saveCustomerDetails(customer) {
40-
this.customer = customer;
41-
},
42-
saveOrderId(order) {
43-
this.order = order;
44-
},
45-
getSingleProduct(slug) {
46-
return this.products.find((product) => product.slug === slug);
47-
},
4830
},
4931
getters: {
5032
getCartQuantity() {
5133
return this.cart.reduce((total, product) => total + product.quantity, 0);
5234
},
53-
getOrderDetails() {
54-
return this.order;
55-
},
56-
getCartContent() {
57-
return this.cart;
58-
},
59-
getCustomerDetails() {
60-
return this.customer;
61-
},
35+
6236
getCartTotal() {
6337
const currencySymbol = useRuntimeConfig().public.currencySymbol || "kr";
6438

0 commit comments

Comments
 (0)