Closed shopnaill closed 2 years ago
You can update this method to handel it more speed :) ` ``` addProductToCart(barcode) { let product = this.state.products.find(p => p.barcode === barcode); if (!!product) { // if product is already in cart let cart = this.state.cart.find(c => c.id === product.id); if (!!cart) { // update quantity this.setState({ cart: this.state.cart.map(c => { if (c.id === product.id) { c.pivot.quantity = c.pivot.quantity + 1; } return c; }) }); } else { product = { ...product, pivot: { quantity: 1, product_id: product.id, user_id: 1 } };
this.setState({ cart: [...this.state.cart, product] });
}
axios
.post("/admin/cart", { barcode })
.then(res => {
console.log(res);
})
.catch(err => {
Swal.fire("Error!", err.response.data.message, "error");
});
}
}`
@shopnaill, I have merged your method, Thanks you for share :)
you made a great POS, but it's missing something to make it super, you have used the database user_cart table to save cart state, but it's taken too long time to respond! and this is the issue here, you can use localStorage in react and setState you will get more speed,
Thanks for this good project and hope you fix it 👍