Skip to content

Commit

Permalink
Merge pull request #1013 from w3bdesign/1012-clear-cart-on-successful…
Browse files Browse the repository at this point in the history
…-order

1012 clear cart on successful order
  • Loading branch information
w3bdesign authored Feb 5, 2023
2 parents 8529bf0 + eae084c commit cc54c25
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 27 deletions.
8 changes: 8 additions & 0 deletions pages/success.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
</template>

<script setup>
import { useCart } from "@/store/useCart";
const cart = useCart();
onBeforeMount(() => {
cart.clearCart();
});
useHead({
title: "Order placed",
titleTemplate: "%s - Nuxt 3 Woocommerce",
Expand Down
28 changes: 1 addition & 27 deletions store/useCart.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { defineStore } from "pinia";

const state = {
cart: [],
order: {},
customer: {},
loading: true,
error: null,
};
Expand All @@ -26,39 +24,15 @@ export const useCart = defineStore("cartState", {
removeProductFromCart(product) {
this.cart.splice(this.cart.indexOf(product), 1);
},

clearCart() {
this.cart.length = 0;
},
clearCustomer() {
this.customer = {};
},
clearOrder() {
this.order = {};
},
saveCustomerDetails(customer) {
this.customer = customer;
},
saveOrderId(order) {
this.order = order;
},
getSingleProduct(slug) {
return this.products.find((product) => product.slug === slug);
},
},
getters: {
getCartQuantity() {
return this.cart.reduce((total, product) => total + product.quantity, 0);
},
getOrderDetails() {
return this.order;
},
getCartContent() {
return this.cart;
},
getCustomerDetails() {
return this.customer;
},

getCartTotal() {
const currencySymbol = useRuntimeConfig().public.currencySymbol || "kr";

Expand Down

1 comment on commit cc54c25

@vercel
Copy link

@vercel vercel bot commented on cc54c25 Feb 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.