diff options
Diffstat (limited to 'src')
| -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 |
