From 642cc92cd130d5ec31d5ff7c6235dde820241f7a Mon Sep 17 00:00:00 2001 From: nashtech-tuannguyenhuu1 <105196741+nashtech-tuannguyenhuu1@users.noreply.github.com> Date: Thu, 1 Aug 2024 17:08:16 +0700 Subject: [PATCH] The "Plus" button to increase the quantity of product in shopping cart not work (#817) --- storefront/pages/cart/index.tsx | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/storefront/pages/cart/index.tsx b/storefront/pages/cart/index.tsx index a1ccd9d78e..9f3d387406 100644 --- a/storefront/pages/cart/index.tsx +++ b/storefront/pages/cart/index.tsx @@ -8,7 +8,6 @@ import ConfirmationDialog from '@/common/components/dialog/ConfirmationDialog'; import { useCartContext } from '@/context/CartContext'; import { Cart as CartModel } from '@/modules/cart/models/Cart'; import { - addToCart, getCart, getCartProductThumbnail, removeProductInCart, @@ -113,16 +112,14 @@ const Cart = () => { setIsOpenRemoveDialog(false); }; - const handlePlus = (productId: number) => { - addToCart([ - { - productId: productId, - quantity: 1, - }, - ]) + const handlePlus = (productId: number, productQuantity: number) => { + updateCart({ + productId: productId, + quantity: productQuantity + 1, + }) .then(() => loadCart()) .catch((err) => { - console.log('Add to cart fail: ' + err.message); + console.log('Plus product to cart fail: ' + err.message); }); }; @@ -316,7 +313,7 @@ const Cart = () => { type="button" value="+" className="plus" - onClick={() => handlePlus(item.productId)} + onClick={() => handlePlus(item.productId, item.quantity)} />