From 84ae09f61f05f212ec098da1fd4ed14960119527 Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Tue, 27 Jun 2023 09:07:22 +0700 Subject: promotion detail --- .../product/components/Product/ProductDesktop.jsx | 48 ++++++++-------------- 1 file changed, 16 insertions(+), 32 deletions(-) (limited to 'src/lib/product') diff --git a/src/lib/product/components/Product/ProductDesktop.jsx b/src/lib/product/components/Product/ProductDesktop.jsx index 25b12911..507d676c 100644 --- a/src/lib/product/components/Product/ProductDesktop.jsx +++ b/src/lib/product/components/Product/ProductDesktop.jsx @@ -28,7 +28,8 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => { const [addCartAlert, setAddCartAlert] = useState(false) const [promotionType, setPromotionType] = useState(false) - const [promotionList, setPromotionList] = useState(null) + const [promotionActiveId, setPromotionActiveId] = useState(null) + const [quantity, setQuantity] = useState(null) const getLowestPrice = useCallback(() => { const prices = product.variants.map((variant) => variant.price) @@ -38,18 +39,6 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => { return lowest }, [product]) - useEffect(() => { - if(product.variants.length == 1){ - const id = product.variants[0].id - const listProgram = async () => { - const programs = await getPromotionProgram({id}) - setPromotionList(programs) - console.log('list program', promotionList) - } - listProgram() - } - },[]) - useEffect(() => { const lowest = getLowestPrice() setLowestPrice(lowest) @@ -60,6 +49,9 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => { const variantQuantityRefs = useRef([]) const setVariantQuantityRef = (variantId) => (element) => { + if (element) { + setQuantity(element.value) + } variantQuantityRefs.current[variantId] = element } @@ -82,6 +74,7 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => { updateItemCart({ productId: variantId, quantity, + programLineId:promotionActiveId, selected: true }) setAddCartAlert(true) @@ -183,7 +176,12 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => { {product.variants.length <= 1 && (
- +
)} @@ -260,16 +258,6 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => { )} - {/*
- -
*/} {product.variants.length > 1 ? (