diff options
| author | FIN-IT_AndriFP <andrifebriyadiputra@gmail.com> | 2026-01-14 09:24:22 +0700 |
|---|---|---|
| committer | FIN-IT_AndriFP <andrifebriyadiputra@gmail.com> | 2026-01-14 09:24:22 +0700 |
| commit | a891c880bb7dc8b2ff141ea015490283ea6278fd (patch) | |
| tree | bf8afb0201941ef761a0bf2ebffec59219d44e84 /src/pages/api/magento-product.ts | |
| parent | 13a6ccd99722464342942eeb7fbc73c2f0f27542 (diff) | |
| parent | 2843980c8bfe25d67bd70e176c546b5e2fe66975 (diff) | |
(andri) fix merge
Diffstat (limited to 'src/pages/api/magento-product.ts')
| -rw-r--r-- | src/pages/api/magento-product.ts | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/src/pages/api/magento-product.ts b/src/pages/api/magento-product.ts index 4e963844..f61daf69 100644 --- a/src/pages/api/magento-product.ts +++ b/src/pages/api/magento-product.ts @@ -87,20 +87,31 @@ export default async function handler( // Susun Matrix // Struktur: { code, label, values: { [sku]: value } } const matrix: any[] = []; + Array.from(allAttributeCodes).forEach((code) => { const row: any = { code: code, label: labelsMap[code], - values: {} // Key = SKU/ID Variant, Value = Isi Atribut + values: {} }; + let hasData = false; + items.forEach((p: any) => { const attr = p.custom_attributes.find((a: any) => a.attribute_code === code); - // Simpan value berdasarkan SKU (ID Variant dari Odoo) - row.values[p.sku] = attr ? attr.value : '-'; + let rawVal = attr && attr.value !== null ? String(attr.value).trim() : ''; + if (rawVal.length >= 2 && rawVal.startsWith('"') && rawVal.endsWith('"')) { + rawVal = rawVal.slice(1, -1).trim(); + } + if (rawVal !== '' && rawVal !== '-') { + hasData = true; + } + row.values[p.sku] = rawVal; }); - matrix.push(row); + if (hasData) { + matrix.push(row); + } }); // Deskripsi produk per varian |
