top of page

Kenya AB TOP Thiriku

Arabica

kenya-ab-top-thiriku

import wixLocation from 'wix-location'; $w.onReady(function () { const titleFromSlug = (slug) => { if (!slug) return ''; return String(slug) .replace(/-/g, ' ') .replace(/ny/gi, 'NY') .replace(/scr/gi, 'Scr.') .replace(/s s/gi, 's.s.') .replace(/w/g, (c) => c.toUpperCase()); }; const copyPlainFields = (source) => { const plain = {}; if (!source) return plain; Object.keys(source).forEach((key) => { const value = source[key]; if (value === null || value === undefined) return; const type = typeof value; if (type === 'string' || type === 'number' || type === 'boolean') { plain[key] = value; return; } if (type === 'object') { if (value.src) plain[key] = value.src; else if (value.url) plain[key] = value.url; else if (value.fileUrl) plain[key] = value.fileUrl; else if (value.alt) plain[key] = value.alt; } }); return plain; }; const getCurrentDatasetItem = () => { const ids = ['#dynamicDataset', '#dynamicDataset1', '#dataset1', '#greenCoffeeDataset']; for (let i = 0; i < ids.length; i += 1) { try { const dataset = $w(ids[i]); if (dataset && typeof dataset.getCurrentItem === 'function') { return { dataset, item: dataset.getCurrentItem() }; } } catch (err) { // Try the next possible dataset ID. } } return { dataset: null, item: {} }; }; const normaliseCoffeeItem = (item) => { const plain = copyPlainFields(item); const path = wixLocation.path || []; const slug = plain.slug || plain['link-green-coffee-inventory-title'] || plain['link-green-coffee-inventory'] || path[path.length - 1] || ''; plain.slug = String(slug || ''); plain.title = plain.title || plain.coffeeNameFull || plain.coffeeName || plain.name || plain.productName || titleFromSlug(plain.slug); plain.coffeeNameFull = plain.coffeeNameFull || plain.title; plain.origin = plain.origin || plain.country || plain.countryOfOrigin || (plain.slug.split('-')[0] ? titleFromSlug(plain.slug.split('-')[0]) : ''); plain.producer = plain.producer || plain.farm || plain.supplier || ''; plain.region = plain.region || plain.location || ''; plain.process = plain.process || plain.processing || ''; plain.grade = plain.grade || plain.screenSize || ''; plain.availableBags = plain.availableBags || plain.stock || plain.bags || plain.quantity || ''; plain.bagSize = plain.bagSize || '60 kg'; plain.warehouse = plain.warehouse || 'Hamburg, Germany'; plain.marketStatus = plain.marketStatus || plain.status || 'IN STOCK'; plain.price = plain.price || plain.priceIndication || 'On Request'; return plain; }; const sendCurrentCoffeeToLayout = () => { try { const current = getCurrentDatasetItem(); const plainItem = normaliseCoffeeItem(current.item); const safeItem = JSON.parse(JSON.stringify(plainItem)); $w('#html14').postMessage({ item: safeItem }); console.log('Green coffee item sent to layout:', plainItem.title); } catch (err) { console.warn('Green coffee item layout data was not ready yet', err); } }; const current = getCurrentDatasetItem(); if (current.dataset && typeof current.dataset.onReady === 'function') { current.dataset.onReady(() => { sendCurrentCoffeeToLayout(); [300, 900, 1800, 3000, 5000].forEach((delay) => setTimeout(sendCurrentCoffeeToLayout, delay)); }); } [300, 900, 1800, 3000, 5000].forEach((delay) => setTimeout(sendCurrentCoffeeToLayout, delay)); try { $w('#backButton').onClick(() => wixLocation.to('/green-coffee')); } catch (err) { // The visible Back link remains connected in the editor when #backButton is not present. } });

wix-secrets-backend

bottom of page