<% // ================================================================= // THE FINAL, STABLE CODE - By Gemini // This goes into the CONTENT field of "Create a page" in EXPRESSION mode. // ================================================================= // --- 1. GATHER DATA --- // We get the data we need from the previous nodes. 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 LOGIC --- // We check which phases the user ACTUALLY 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, but only if the user checked the box. function addPhaseBooks(phaseData) { if (phaseData) { for (const key in phaseData) { if (phaseData[key].productId) { // Check if the book object is valid 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,789") 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) {
// If books were selected, create the grid.
let itemsHtml = ”;
selectedBooks.forEach(book => {
itemsHtml += `

${book.title}
${book.title}

`;
});

cartHtml = `

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

${itemsHtml}

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

`;
} else {
// If no books were selected, show an empty message.
cartHtml = `

سبد خرید شما خالی است

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

`;
}

// — 4. RENDER THE FINAL PAGE —
// Now we write the page. We use <%- `variable` %> to safely inject our HTML.
%>

<%= mainData.formalName %>

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

<%= mainData.final_output.analysis %>


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


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