ChatCrawlersearch across public Telegram Open the app
R

ReactJS Indonesia

сообщение · 2025-06-30 14:42 UTC
T
Replymessage unavailable
const [cartData, setCartData] = useState(JSON.parse(localStorage.getItem('cart')) || []); const addToCart = (product, variant=null) => { // let updateCart = [...cartData]; let updateCart = []; // kalo cartnya empty if (cartData.length === 0) { updateCart.push({ product_id: product.id, title: product.title, qty: 1, image_url: product.image_url || '', price: variant ? variant.price : product.price, weight: variant ? variant.weight : null, // ini penting! product_variants_id: variant ? variant.variant_id : null, }); } else { if (variant != null) { const isProductExist = updateCart.find(item => item.product_id === product.id && item.product_variants_id === variant.variant_id ); if (isProductExist) { updateCart = updateCart.map(item => item.product_id === product.id && item.product_variants_id === variant.variant_id ? { ...item, qty: item.qty + 1 } : item ); } else { updateCart.push({ product_id: product.id, product_variants_id: variant.variant_id, price: variant.price, title: product.title, qty: 1, image_url: product.image_url || '', size: variant.weight, }); } } else { const isProductExist = updateCart.find(item => item.product_id === product.id && item.product_variants_id === null ); if (isProductExist) { updateCart = updateCart.map(item => item.product_id === product.id && item.product_variants_id === null ? { ...item, qty: item.qty + 1 } : item ); } else { updateCart.push({ product_id: product.id, product_variants_id: null, price: product.price, title: product.title, qty: 1, image_url: product.image_url || '', size: null, }); } } } // setCartData(updateCart); setCartData([...cartData, updateCart]); localStorage.setItem('cart', JSON.stringify(updateCart)); };

Вся лента · оригинал в Telegram

Open in Telegram Каталог площадок Искать в ChatCrawler

A snapshot of an open public feed from the search index ChatCrawler — “Google for public Telegram”; refreshed as the venue is crawled. Times are UTC.

Public content only, official Telegram API. About · FAQ · What we do not do · Remove a page · Catalog