in src/app/ContosoTraders.Ui.Website/src/services/cartService.ts [27:41]
static async postProductToCart(
detailProduct: Product
): Promise<{ message?: string; errMessage?: string }> {
const cartItems = await this.getShoppingCart();
if (cartItems) {
const existingProduct:CartItem | undefined = cartItems.find((cartItem) => cartItem.productId === detailProduct.id);
if (existingProduct) {
return this.updateQuantity(existingProduct, existingProduct.quantity + 1)
.then(() => ({ message: 'Product added to shopping cart' }))
.catch(() => ({ errMessage: 'The product could not be added to the cart' }));
}
}
return this.addProduct(detailProduct);
}