<% // ================================================================= // THE FOOLPROOF, SINGLE-NODE SOLUTION - By Gemini // This entire block goes into the "Content" field of the "Create a page" node. // You MUST enable Expression mode for this field. // ================================================================= // --- 1. GATHER ALL DATA FROM PREVIOUS NODES --- // We pull data directly from any node we need, right here. const webhookData = $('Webhook').first().json.body; const mainData = $('Code in JavaScript (Lookup in sheet)').first().json; const coupon = $('HTTP Request (coupon)').first().json.code.toString().trim(); // --- 2. APPLY THE LOGIC --- // We check which phases the user selected in the form. const addPhase1 = webhookData.add_phase_1 === 'true' || webhookData.add_phase_1 === true; const addPhase2 = webhookData.add_phase_2 === 'true' || webhookData.add_phase_2 === true; const addPhase3 = webhookData.add_phase_3 === 'true' || webhookData.add_phase_3 === true; const selectedBooks = []; const final_product_ids = []; const allPhases = mainData.final_output.study_plan; // This function adds books from a phase to our 'selectedBooks' list. function addPhaseBooks(phaseData) { if (phaseData) { for (const key in phaseData) { if (phaseData[key] && phaseData[key].productId) { selectedBooks.push(phaseData[key]); final_product_ids.push(phaseData[key].productId); } } } } if (addPhase1) addPhaseBooks(allPhases.phase_1); if (addPhase2) addPhaseBooks(allPhases.phase_2); if (addPhase3) addPhaseBooks(allPhases.phase_3); // This creates the product ID string (e.g., "123,456") for the purchase links. const final_ids_string = final_product_ids.join(','); // --- 3. BUILD THE CART HTML --- // We build the HTML for the final cart section in a variable. let cartHtml = ''; if (selectedBooks.length > 0) {
let itemsHtml = ”;
selectedBooks.forEach(book => {
// We use the data we gathered to build each item.
itemsHtml += `

${book.title || ''}
${book.title || ”}

`;
});

cartHtml = `

جزئیات سیر مطالعاتی انتخابی شما:

${itemsHtml}

این یک لیست ثابت از سیر مطالعاتی شماست. برای تکمیل سفارش، روی بنر خرید در بالا کلیک کنید.

`;
} else {
cartHtml = `

شما هیچ فازی را برای افزودن به سبد خرید انتخاب نکرده‌اید.

`;
}

// — 4. RENDER THE FINAL PAGE —
// Now we start the visible HTML part of the page.
%>

<%= mainData.formalName %>

💡 تحلیل هوشمند

<%= mainData.final_output.analysis %>


<%= allPhases.phase_1.book_3.title %>


<%= allPhases.phase_1.book_4.title %>