wip: cart
This commit is contained in:
27
spa/src/stores/CartStore.js
Normal file
27
spa/src/stores/CartStore.js
Normal file
@@ -0,0 +1,27 @@
|
||||
import {defineStore} from "pinia";
|
||||
|
||||
export const useCartStore = defineStore('cart', {
|
||||
state: () => ({
|
||||
items: [],
|
||||
}),
|
||||
|
||||
actions: {
|
||||
getProduct(productId) {
|
||||
return this.items.find(item => parseInt(item.productId) === parseInt(productId)) ?? null;
|
||||
},
|
||||
|
||||
hasProduct(productId) {
|
||||
return this.getProduct(productId) !== null;
|
||||
},
|
||||
|
||||
addProduct(productId, productName, price, quantity = 1, options = []) {
|
||||
this.items.push({
|
||||
productId: productId,
|
||||
productName: productName,
|
||||
price: price,
|
||||
quantity: quantity,
|
||||
options: options,
|
||||
});
|
||||
},
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user