AI Product Description Generator
Module 22 · ai · intermediate
published.js
// Mark the draft published only if Shopify returned the product (with its id).
const db = $getWorkflowStaticData('global');
const item = $input.first().json;
const x = $('Apply Decision').first().json;
const d = db.drafts[x.product_id];
if (x.dry_run) return [{ json: { found: true, product_id: x.product_id, published: false, dry_run: true, body_html: x.body_html, tags: x.tags } }];
const ok = Boolean(item.id) && String(item.id) === String(x.product_id);
if (ok) { d.state = 'published'; d.published_at = new Date().toISOString(); d.last_error = null; }
else d.last_error = String(item.error?.message ?? item.error ?? 'Shopify returned no product (check the Shopify credential)').slice(0, 300);
return [{ json: { found: true, product_id: x.product_id, published: ok, state: d.state, edited: x.edited, error: ok ? null : d.last_error } }];