${(function(){
const product = data.product;
const avail_variants = product.variants.filter(function(variant){
return variant.available;
});
const selected_variant = avail_variants.length ? avail_variants[0] : product.variants[0];
return `
`
})()}
${(function() {
const judgeIsNone = function(status){ return status && status !== 'None' ? status : '-' }
const hasValueData = Object.keys(data).reduce((newObj, key) => {
if (data[key] !== "") {
newObj[key] = data[key];
}
return newObj;
}, {});
const keyFilter = keyPrefix => key => key.indexOf(keyPrefix) > -1;
const filterAndSort = (sourceCols, targetCols) => sourceCols
.filter(item => targetCols.includes(item))
.sort((a, b) => sourceCols.indexOf(a) - sourceCols.indexOf(b));
let keys = Object.keys(hasValueData);
let odCols = keys.filter(keyFilter('prescription_od'));
let osCols = keys.filter(keyFilter('prescription_os'));
let allOdTableCols = ["prescription_od_bc", "prescription_od_dia", "prescription_od_sph", "prescription_od_cyl", "prescription_od_axis", "prescription_od_add"];
let allOsTableCols = ["prescription_os_bc", "prescription_os_dia", "prescription_os_sph", "prescription_os_cyl", "prescription_os_axis", "prescription_os_add"];
let dominantCols = odCols.length > osCols.length ? allOdTableCols : allOsTableCols;
let tableCols = filterAndSort(dominantCols, odCols.length > osCols.length ? odCols : osCols);
let odTableCols = filterAndSort(allOdTableCols, odCols);
let osTableCols = filterAndSort(allOsTableCols, osCols);
if(data.process_type === 'contact_lens') {
return `
${
odTableCols.map((key, index) => {
const value = data[key];
const prefix = value.charAt(0);
if (['+', '-'].indexOf(prefix) > -1) {
const num = value.slice(1);
return `
`
} else {
return `
${
osTableCols.map((key, index) => {
const value = data[key];
const prefix = value.charAt(0);
if (['+', '-'].indexOf(prefix) > -1) {
const num = value.slice(1);
return `
`
} else {
return `
: ${data.birth_year}
`
} else {
return `
${data.prescription_type !== "reading_no_lens" ?`
`:''}
${data.is_prism?`
`:''}
${data.ocular_height ?`
` : '' }
${data.birth_year ?`
` : ''}
`
} })()}
${
tableCols.map((key, index) => {
return `
`
}).join('')
}
${prefix}
${num}
${judgeIsNone(data[key])}
`
}
}).join('')
}
${prefix}
${num}
${judgeIsNone(data[key])}
`
}
}).join('')
}
${data.birth_year}
${judgeIsNone(data.prescription_od_sph)}
${judgeIsNone(data.prescription_od_cyl)}
${judgeIsNone(data.prescription_od_axis)}
${judgeIsNone(data.prescription_od_add)}
${judgeIsNone(data.prescription_os_sph)}
${judgeIsNone(data.prescription_os_cyl)}
${judgeIsNone(data.prescription_os_axis)}
${judgeIsNone(data.prescription_os_add)}
${data.prescription_pd ? judgeIsNone(data.prescription_pd):` ${judgeIsNone(data.prescription_pd_r)}( )${judgeIsNone(data.prescription_pd_l)}( )
`}
${judgeIsNone(data.prescription_od_pv)}
${judgeIsNone(data.prescription_od_bd)}
${judgeIsNone(data.prescription_od_pv_r)}
${judgeIsNone(data.prescription_od_bd_r)}
${judgeIsNone(data.prescription_os_pv)}
${judgeIsNone(data.prescription_os_bd)}
${judgeIsNone(data.prescription_os_pv_r)}
${judgeIsNone(data.prescription_os_bd_r)}
${data.ocular_height}
${data.birth_year}
${(function(){
const selected_variant = data.product && data.product.selected_variant || {};
const selectedPrice = selected_variant.trunk_price || selected_variant.price;
const selectedCompareAtPrice = selected_variant.compare_at_price;
const summaryImg = selected_variant.image?.src ? selected_variant.image : data.product?.image;
return `
`
}())}
${data.product?data.product.title : ''}
${selected_variant.option1}
/ ${selected_variant.option2}
/ ${selected_variant.option3}
Cart
-
${(function() {
const properties = JSON.parse(item.properties?.replace(/&(quot);/ig,'"') || '{}');
const prescriptionType = properties && properties['Prescription Type'];
const isLensProcess = !!(properties?._lens_processing_id);
const isContact = prescriptionType?.includes('Contact');
const variantName = item.options.map(option => option.value).join(' / ').trim();
return `
${item.product_title} ${item.product_title}Details${(function(){ return isContact ? `${(function() { const editBtnText = isContact? 'Edit Prescription' : ' Edit Prescription and Lenses'; return properties?._lens_processing_id ? ` ` : `` })()}${(function() { const properties = JSON.parse(item.properties.replace(/&(quot);/ig,'"') || '{}'); if (!properties['_steps']) { return ''; } const isNewSpec = properties['_steps'].find(v => !!v.title); if (isNewSpec) { return '' } return item.parsedProperties.map(propertie => { return `${(function(){ const properties = JSON.parse(item.properties.replace(/&(quot);/ig,'"') || '{}'); if (!properties['_steps']) { return ''; } const isNewSpec = properties['_steps'].find(v => !!v.title); if (!isNewSpec) { return '' } return properties['_steps'].map((step, index) => { step.price = Number(step.price) || 0; if (step.step_type === 'prescription_type') { let prescriptionTable = ''; if (properties['Prescription Type'].includes('Reading') && !properties['Submission Method']) { prescriptionTable = `${(function(){ if(!propertie){ return ``; } const name = propertie.name; if(name == 'Prescription Type'){ const types = ['Single Vision','Reading','Progressive','Non-Prescription','Bifocal','Frame Only','Contact']; let title = types.filter(v=>propertie.value.toLowerCase().includes(v.toLowerCase()))[0]||""; let prescriptionTypeTitle = JSON.parse(item.properties?.replace(/&(quot);/ig,'"') || '{}')._prescription_type_title; let amount = propertie.value.replace(title,'').trim().replace(/[^\d\.]/g,''); const i18nTitle = { "Single Vision": "Single Vision", "Reading": "Reading", "Progressive": "Progressive", "Non-Prescription": "Non-Prescription", "Bifocal": "Bifocal", "Contact": "Contact", }[title] || title; return `` }).join(''); })()}${i18nTitle}${prescriptionTypeTitle}${submissionMethodTitle}Prescription File:`; } else{ return `${submissionMethodTitle}`; } } else{ return ``; } })()}
${(function() { if(!propertie){ return `` } let image = item.parsedProperties.find(v=>v.name == "Prescription File"); let prescriptionSrc = ""; if(Boolean(image)){ prescriptionSrc = image.value; } const birth_year = propertie.name == 'Birth Year' ? propertie.value : ''; const isManualUpload = propertie.name == 'Submission Method' && propertie.value.includes('Enter prescription manually'); if(isManualUpload) { return ` Prescription File:` } else { return `` } })()}`; } const types = ['Single Vision','Reading','Progressive','Non-Prescription','Bifocal','Frame Only', 'Contact']; let title = types.filter(v=>properties['Prescription Type'].toLowerCase().includes(v.toLowerCase()))[0]||""; let prescriptionTypeTitle = JSON.parse(item.properties?.replace(/&(quot);/ig,'"') || '{}')._prescription_type_title; let amount = properties['Prescription Type'].replace(title,'').trim().replace(/[^\d\.]/g,''); const i18nTitle = { "Single Vision": "Single Vision", "Reading": "Reading", "Progressive": "Progressive", "Non-Prescription": "Non-Prescription", "Bifocal": "Bifocal", "Contact": "Contact", }[title] || [title]; return ` ${i18nTitle}${step.title}${prescriptionTable} ` } if (step.step_type === 'submit_method') { if (properties['Submission Method'].includes('Enter prescription manually')) { let prismContent = ''; if (properties['Prism OS'] && properties['Prism OD']) { prismContent = `${step.title}${prismContent}Prescription File:` } if (properties['Submission Method'].includes('Upload')) { return `Prescription File:` } if (properties['Submission Method'].includes('Email later')) { return `${step.title}` } } if (step.step_type === 'lens') { return `${step.title}` } return `${step.title}` }).join(''); }())}Quantity X${item.quantity}Subtotal${item.product_title}`; } const types = ['Single Vision','Reading','Progressive','Non-Prescription','Bifocal','Frame Only', 'Contact']; let title = types.filter(v=>properties['Prescription Type'].toLowerCase().includes(v.toLowerCase()))[0]||""; let prescriptionTypeTitle = JSON.parse(item.properties?.replace(/&(quot);/ig,'"') || '{}')._prescription_type_title; let amount = properties['Prescription Type'].replace(title,'').trim().replace(/[^\d\.]/g,''); const i18nTitle = { "Single Vision": "Single Vision", "Reading": "Reading", "Progressive": "Progressive", "Non-Prescription": "Non-Prescription", "Bifocal": "Bifocal", "Contact": "Contact", }[title] || [title]; return ` ${i18nTitle}${step.title}${prescriptionTable} ` } if (step.step_type === 'submit_method') { if (properties['Submission Method'].includes('Enter prescription manually')) { let prismContent = ''; if (properties['Prism OS'] && properties['Prism OD']) { prismContent = `${step.title}${prismContent}Prescription File:` } if (properties['Submission Method'].includes('Upload')) { return `Prescription File:` } if (properties['Submission Method'].includes('Email later')) { return `${step.title}` } } if (step.step_type === 'lens') { return `${step.title}` } return `${step.title}` }).join(''); }())}${(function(){ const properties = JSON.parse(item.properties.replace(/&(quot);/ig,'"') || '{}'); if (!properties['_steps']) { return ''; } const isNewSpec = properties['_steps'].find(v => !!v.title); if (isNewSpec) { return ''; } return item.parsedProperties.map(propertie => { return `${(function(){ if(!propertie){ return ``; } const name = propertie.name; if(name == 'Prescription Type'){ const types = ['Single Vision','Reading','Progressive','Non-Prescription','Bifocal','Frame Only']; let title = types.filter(v=>propertie.value.toLowerCase().includes(v.toLowerCase()))[0]||""; let prescriptionTypeTitle = JSON.parse(item.properties?.replace(/&(quot);/ig,'"') || '{}')._prescription_type_title; let amount = propertie.value.replace(title,'').trim().replace(/[^\d\.]/g,''); const i18nTitle = { "Single Vision": "Single Vision", "Reading": "Reading", "Progressive": "Progressive", "Non-Prescription": "Non-Prescription", "Bifocal": "Bifocal", "Contact": "Contact", }[title] || title; return `` }).join('') })()}${i18nTitle}${prescriptionTypeTitle}${submissionMethodTitle}Prescription File:`; } else{ return `${submissionMethodTitle}`; } } else if(name == 'Lens'){ const elipseStr = (str) => { if (str.length > 30) { return str.slice(0, 30) + '...'; } return str; }; let stepItems = propertie.value.split(';'); stepItems = stepItems.slice(0,stepItems.length-1); let formatItems = stepItems.map(v=>{ let stepTitle = v.split(' - ')[0]||""; let stepOptionStr = v.replace(`${stepTitle} - `,''); let optionTitle = stepOptionStr; let amount = ""; let index = stepOptionStr.lastIndexOf(':'); optionTitle = index == -1 ? stepOptionStr : stepOptionStr.slice(0, index); amount = index == -1 ? '0' : stepOptionStr.slice(index+1).trim(); return { stepTitle: elipseStr(stepTitle), optionTitle: optionTitle, amount } }); formatItems = formatItems.filter(v=>Boolean(v.optionTitle)); return `${data.optionTitle} ${(()=>{ let amount = data.amount.trim().replace(/[^\d\.]/g,''); return ``; })()} ${(function() { if(!propertie){ return `` } let image = item.parsedProperties.find(v=>v.name == "Prescription File"); let prescriptionSrc = ""; if(Boolean(image)){ prescriptionSrc = image.value; } const isManualUpload = propertie.name == 'Submission Method' && propertie.value.includes('Enter prescription manually'); if(isManualUpload) { return ` Prescription File:` } else{ return `` } })()}Quantity X${item.quantity}Subtotal${item.options.map(option => option.value).join(' / ')}
${variantName} (
) ${propertie.value != '' && propertie.value != 'Frame Only' ? `${isContact ? `` : ` `}: ${function(){ const types = ['Single Vision','Reading','Progressive','Non-Prescription','Bifocal','Contact']; let title = types.filter(v=>propertie.value.toLowerCase().includes(v.toLowerCase()))[0]||""; const i18nTitle = { "Single Vision": "Single Vision", "Reading": "Reading", "Progressive": "Progressive", "Non-Prescription": "Non-Prescription", "Bifocal": "Bifocal", "Contact": "Contact", }[title] || title; return ` ${i18nTitle} `; }()}${(function() { const properties = JSON.parse(item.properties.replace(/&(quot);/ig,'"') || '{}'); if (!properties['_steps']) { return ''; } const isNewSpec = properties['_steps'].find(v => !!v.title); if (isNewSpec) { return '' } return item.parsedProperties.map(propertie => { return `${(function(){ const properties = JSON.parse(item.properties.replace(/&(quot);/ig,'"') || '{}'); if (!properties['_steps']) { return ''; } const isNewSpec = properties['_steps'].find(v => !!v.title); if (!isNewSpec) { return '' } return properties['_steps'].map((step, index) => { step.price = Number(step.price) || 0; if (step.step_type === 'prescription_type') { let prescriptionTable = ''; if (properties['Prescription Type'].includes('Reading') && !properties['Submission Method']) { prescriptionTable = `${(function(){ if(!propertie){ return `` } const name = propertie.name; if(name == 'Prescription Type'){ const types = ['Contact']; let title = types.filter(v=>propertie.value.toLowerCase().includes(v.toLowerCase()))[0]||""; let prescriptionTypeTitle = JSON.parse(item.properties?.replace(/&(quot);/ig,'"') || '{}')._prescription_type_title; let amount = propertie.value.replace(title,'').trim().replace(/[^\d\.]/g,''); const i18nTitle = { "Single Vision": "Single Vision", "Reading": "Reading", "Progressive": "Progressive", "Non-Prescription": "Non-Prescription", "Bifocal": "Bifocal", "Contact": "Contact", }[title] || title; return `` }).join(''); })()}${prescriptionTypeTitle}: ${i18nTitle}${submissionMethodTitle}` } else if (isUpload){ return `Prescription File:` } else{ return `${submissionMethodTitle}` } } else{ return `` } })()}${(function() { if(!propertie){ return `` } let image = item.parsedProperties.find(v=>v.name == "Prescription File"); let prescriptionSrc = ""; if(Boolean(image)){ prescriptionSrc = image.value; } const birth_year = propertie.name == 'Birth Year' ? propertie.value : ''; const isManualUpload = propertie.name == 'Submission Method' && propertie.value.includes('Enter prescription manually'); if(isManualUpload) { return ` Prescription File:` }else{ return `` } })()}`; } return ` ${step.title}${prescriptionTable} ` } if (step.step_type === 'submit_method') { if (properties['Submission Method'].includes('Enter prescription manually')) { let prismContent = ''; if (properties['Prism OS'] && properties['Prism OD']) { prismContent = `${step.title}${prismContent}Prescription File:` } if (properties['Submission Method'].includes('Upload')) { return `Prescription File:` } if (properties['Submission Method'].includes('Email later')) { return `${step.title}` } } return `${step.title}` }).join(''); }())} ${(function() { const properties = JSON.parse(item.properties.replace(/&(quot);/ig,'"') || '{}'); return properties?._lens_processing_id ? `Edit Prescription`; } return ` ${step.title}${prescriptionTable} ` } if (step.step_type === 'submit_method') { if (properties['Submission Method'].includes('Enter prescription manually')) { let prismContent = ''; if (properties['Prism OS'] && properties['Prism OD']) { prismContent = `${step.title}${prismContent}Prescription File:` } if (properties['Submission Method'].includes('Upload')) { return `Prescription File:` } if (properties['Submission Method'].includes('Email later')) { return `${step.title}` } } return `${step.title}` }).join(''); }())}${(function(){ const properties = JSON.parse(item.properties.replace(/&(quot);/ig,'"') || '{}'); if (!properties['_steps']) { return ''; } const isNewSpec = properties['_steps'].find(v => !!v.title); if (isNewSpec) { return ''; } return item.parsedProperties.map(propertie => { return `${(function() { const properties = JSON.parse(item.properties.replace(/&(quot);/ig,'"') || '{}'); return properties?._lens_processing_id ? `${(function(){ if(!propertie){ return `` } const name = propertie.name; if(name == 'Prescription Type'){ const types = ['Single Vision','Reading','Progressive','Non-Prescription','Bifocal','Frame Only']; let title = types.filter(v=>propertie.value.toLowerCase().includes(v.toLowerCase()))[0]||""; let prescriptionTypeTitle = JSON.parse(item.properties?.replace(/&(quot);/ig,'"') || '{}')._prescription_type_title; let amount = propertie.value.replace(title,'').trim().replace(/[^\d\.]/g,''); const i18nTitle = { "Single Vision": "Single Vision", "Reading": "Reading", "Progressive": "Progressive", "Non-Prescription": "Non-Prescription", "Bifocal": "Bifocal", "Contact": "Contact", }[title] || title; return `` }).join(''); })()}${prescriptionTypeTitle}: ${i18nTitle}${submissionMethodTitle}Prescription File:` } else{ return `${submissionMethodTitle}` } } else if(name == 'Lens'){ const elipseStr = (str) => { if (str.length > 30) { return str.slice(0, 30) + '...'; } return str; }; let stepItems = propertie.value.split(';'); stepItems = stepItems.slice(0,stepItems.length-1); let formatItems = stepItems.map(v=>{ let stepTitle = v.split(' - ')[0]||""; let stepOptionStr = v.replace(`${stepTitle} - `,''); let optionTitle = stepOptionStr; let amount = ""; let index = stepOptionStr.lastIndexOf(':'); optionTitle = index == -1 ? stepOptionStr : stepOptionStr.slice(0, index); amount = index == -1 ? '0' : stepOptionStr.slice(index+1).trim(); return { stepTitle: elipseStr(stepTitle), optionTitle: optionTitle, amount } }); formatItems = formatItems.filter(v=>Boolean(v.optionTitle)); return `${data.optionTitle} ${(()=>{ let amount = data.amount.trim().replace(/[^\d\.]/g,''); return `` } else{ return `` } })()}`; })()} ${(function() { if(!propertie){ return `` } let image = item.parsedProperties.find(v=>v.name == "Prescription File"); let prescriptionSrc = ""; if(Boolean(image)){ prescriptionSrc = image.value; } const isManualUpload = propertie.name == 'Submission Method' && propertie.value.includes('Enter prescription manually'); if(isManualUpload) { return ` Prescription File:` } else{ return `` } })()}Edit Prescription${function(){ const types = ['Single Vision','Reading','Progressive','Non-Prescription','Bifocal','Frame Only','Contact']; let title = types.filter(v=>propertie.value.toLowerCase().includes(v.toLowerCase()))[0]||""; const i18nTitle = { "Single Vision": "Single Vision", "Reading": "Reading", "Progressive": "Progressive", "Non-Prescription": "Non-Prescription", "Bifocal": "Bifocal", "Contact": "Contact", }[title] || title; return title != '' && title != 'Frame Only' ? ` ${isContact ? `` : ` `}: ${i18nTitle}` : ''; }()}Free giftMixed Lot${(function(){ const odQty = properties._od_qty; const osQty = properties._os_qty; return isContact? `*${item.quantity}${item.item_text}SubtotalSubtotal (${item.quantity} ${parseInt(item.quantity) > 1 ? `` : ` `}) ${discount_item.title} ) ${item.item_text}${discount_item.title} )
${(function(){
var total_price = data.total_price;
var postageFreeAmount = 10;
var freeAmount = (postageFreeAmount - total_price).toFixed(2);
var isFreeShipping = freeAmount <= 0;
var rate = Math.min(total_price / postageFreeAmount * 100, 100).toFixed(2);
var freeShoppingTips = "Spend {{ amount }} more and get free shipping!".replace('{{ amount }}', ` `);
return `
`
})()}
Shipping
Free
${freeShoppingTips}
${rate}%
Discount
-
${data.invalid_msg}
Total:
Taxes and shipping calculated at checkout
Your shopping bag is empty
Continue shopping