import wixLocation from 'wix-location'; import { session } from 'wix-storage'; $w.onReady(function () { //Load CSV data (Replace this with your actual CSV data) const csvData = `Item #,Part #,Description,Qty (Set),Price 1,CBC162012,BRASS BUSHING 1" X 1-1/4" X 1-1/2",2,5.00 2,EW203202,BRASS THRUST WASHER,4,5.00 3,K08-219-9D,"12" X 2" HUB & DRUM (COMPLETE)",2,5.00 3.1,K08-219-9B,"12" X 2" HUB & DRUM (COMPLETE) *OPT*",2,5.00 3.2,15366415 STL CP,"ASSEMBLY 17.5" HUB & DRUM *OPT*",2,5.00 4,K23-181-00,ELECTRIC BRAKE ASSEMBLY RH (COMPLETE),1,5.00 5,K23-180-00,ELECTRIC BRAKE ASSEMBLY LH (COMPLETE),1,5.00 6,010-036-00,GREASE SEAL 2-1/4" SHAFT (DOUBLE LIP),1,5.00 7,031-030-02,INNER BEARING CONE 25580,1,5.00 8,031-030-01,INNER BEARING CUP 25520,1,5.00 9,008-219-04,HUB & DRUM w/ BEARING CUPS & 1/2" STUDS,1,5.00 9.1,15366415 STL CP,ASSEMBLY 17.5" HUB & DRUM,1,5.00 10,031-017-01,OUTER BEARING CUP 14276,1,5.00 11,031-017-02,OUTER BEARING CONE 14125A,1,5.00 12,005-027-00,SPINDLE WASHER 1" X 2" OD,1,5.00 13,006-176-00,SPINDLE NUT 1"-14,1,5.00 14,019-002-00,COTTER PIN,1,5.00 15,006-191-00,SPECIAL JAM NUT,1,5.00 16,006-190-00,RETAINER - SPINDLE NUT,1,5.00 17,021-039-00,GREASE CAP FOR 14125A BEARING,1,5.00 17.1,021-043-01,GREASE CAP FOR E-Z Lube *OPT*,1,5.00 18,085-001-00,RUBBER PLUG FOR E-Z Lube *OPT*,1,5.00`; // Function to parse CSV data into an array of objects function parseCSV(csv) { const lines = csv.split('\n'); const headers = lines[0].split(','); return lines.slice(1).map(line => { const values = line.split(','); return headers.reduce((obj, header, index) => { obj[header.trim()] = values[index] ? values[index].trim() : ''; return obj; }, {}); }); } //Generate HTML table code from CSV data function generateTableHTML(data) { let tableHTML = ''; for (const header in data[0]) { tableHTML += ``; } tableHTML += ''; data.forEach(row => { tableHTML += ''; for (const key in row) { tableHTML += ``; } tableHTML += ``; tableHTML += ''; }); tableHTML += '
${header}Order Qty
${row[key]}
'; return tableHTML; } // Function to add the HTML to the HTML iFrame function addTableToIframe(html){ $w('#html1').postMessage(html) } const parsedData = parseCSV(csvData); const tableHtml = generateTableHTML(parsedData) addTableToIframe(tableHtml) $w('#button1').onClick(function (){ const selectedItems = []; const tableRows = $w('#html1').children[0].contentDocument.querySelectorAll('table tbody tr'); tableRows.forEach(row => { const cells = row.querySelectorAll('td'); const partNumber = cells[1].textContent const quantityInput = row.querySelector('.quantityInput'); const quantity = Number(quantityInput.value) if(quantity > 0){ selectedItems.push({ partNumber: partNumber, quantity: quantity, price: cells[4].textContent, }); } }); // Get existing cart from session storage let cart = JSON.parse(session.getItem('cart') || '[]'); // Concatenate new items with existing cart cart = cart.concat(selectedItems); // Update session storage with the new cart items session.setItem('cart', JSON.stringify(cart)); // Redirect to Order Summary page wixLocation.to('/order-summary'); }) });
top of page
bottom of page