From fd50180ac301916c6feb5e93598f3fc59ecb78a8 Mon Sep 17 00:00:00 2001 From: FIN-IT_AndriFP Date: Mon, 5 Jan 2026 10:41:39 +0700 Subject: (andri) get desc variant product from magento --- .../modules/product-detail/components/ProductDetail.tsx | 11 ++++++++++- src/pages/api/magento-product.ts | 12 +++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src-migrate/modules/product-detail/components/ProductDetail.tsx b/src-migrate/modules/product-detail/components/ProductDetail.tsx index 82b99697..4cc082d8 100644 --- a/src-migrate/modules/product-detail/components/ProductDetail.tsx +++ b/src-migrate/modules/product-detail/components/ProductDetail.tsx @@ -71,6 +71,7 @@ const ProductDetail = ({ product }: Props) => { const [specsMatrix, setSpecsMatrix] = useState([]); const [upsellIds, setUpsellIds] = useState([]); const [relatedIds, setRelatedIds] = useState([]); + const [descriptionMap, setDescriptionMap] = useState>({}); const [loadingSpecs, setLoadingSpecs] = useState(false); @@ -174,6 +175,10 @@ const ProductDetail = ({ product }: Props) => { setSpecsMatrix([]); } + if (data.descriptions){ + setDescriptionMap(data.descriptions); + } + // 2. Upsell & Related if (data.upsell_ids && Array.isArray(data.upsell_ids)) setUpsellIds(data.upsell_ids); else setUpsellIds([]); @@ -319,6 +324,10 @@ const ProductDetail = ({ product }: Props) => { setMainImage(allImages[i] || ''); }; + const activeMagentoDesc = selectedVariant?.id ? descriptionMap[String(selectedVariant.id)] : ''; + const finalDescription = activeMagentoDesc || product.description || 'Deskripsi produk tidak tersedia.'; + const cleanDescription = finalDescription === '


' ? 'Deskripsi produk tidak tersedia.' : finalDescription; + return ( <>
@@ -455,7 +464,7 @@ const ProductDetail = ({ product }: Props) => { {/* DESKRIPSI */}
-

' ? '

Lorem ipsum dolor sit amet.

' : product.description, }} /> +
diff --git a/src/pages/api/magento-product.ts b/src/pages/api/magento-product.ts index 297f0ebc..ef5fd3bc 100644 --- a/src/pages/api/magento-product.ts +++ b/src/pages/api/magento-product.ts @@ -103,6 +103,15 @@ export default async function handler( matrix.push(row); }); + // Deskripsi produk per varian + const descriptions:Record = {}; + items.forEach((p: any) => { + const descAttr = p.custom_attributes.find((a: any) => a.attribute_code === 'description' || a.attribute_code === 'short_description'); + descriptions[p.sku] = descAttr ? descAttr.value : ''; + }); + + + // ===================================================================== // 3. AMBIL LINKS (UPSELL & RELATED) DARI MAIN VARIANT SAJA // ===================================================================== @@ -126,7 +135,8 @@ export default async function handler( res.status(200).json({ specsMatrix: matrix, upsell_ids: upsellIds, - related_ids: relatedIds + related_ids: relatedIds, + descriptions: descriptions }); } catch (error) { -- cgit v1.2.3