static async addProduct()

in src/app/ContosoTraders.Ui.Website/src/services/cartService.ts [48:69]


    static async addProduct(detailProduct: Product): Promise<any> {  
      const cartItem: CartItem = {
        cartItemId: Math.floor(Math.random() * 1000).toString(),
        email: detailProduct.email.toLowerCase(),
        productId: detailProduct.id,
        name: detailProduct.name,
        price: detailProduct.price,
        imageUrl: detailProduct.imageUrl,
        quantity: detailProduct.quantity,
      };
  
      try {
        const response: AxiosResponse<any> = await axios.post(
          `${this.API_PREFIX}/shoppingcart`,
          cartItem
        );
        return response.data;
      } catch (error) {
        console.error('Error adding product to cart:', error);
        return { errMessage: 'The product could not be added to the cart' };
      }
    }