erpnext.ProductList = class { /* Options: - items: Items - settings: E Commerce Settings - products_section: Products Wrapper - preference: If preference is not list view, render but hide */ constructor(options) { Object.assign(this, options); if (this.preference !== "List View") { this.products_section.addClass("hidden"); } this.products_section.empty(); this.make(); } make() { let me = this; let html = `

`; this.items.forEach(item => { let title = item.web_item_name || item.item_name || item.item_code || ""; title = title.length > 200 ? title.substr(0, 200) + "..." : title; html += `
`; html += me.get_image_html(item, title, me.settings); html += me.get_row_body_html(item, title, me.settings); html += `
`; }); let $product_wrapper = this.products_section; $product_wrapper.append(html); } get_image_html(item, title, settings) { let image = item.website_image || item.image; let wishlist_enabled = !item.has_variants && settings.enable_wishlist; let image_html = ``; if (image) { image_html += `
${ title } ${ wishlist_enabled ? this.get_wishlist_icon(item): '' }
`; } else { image_html += `
${ frappe.get_abbr(title) }
${ wishlist_enabled ? this.get_wishlist_icon(item): '' }
`; } return image_html; } get_row_body_html(item, title, settings) { let body_html = `
`; body_html += this.get_title_html(item, title, settings); body_html += this.get_item_details(item, settings); body_html += `
`; return body_html; } get_title_html(item, title, settings) { let title_html = `
`; title_html += `
${ title }
`; if (settings.enabled) { title_html += `
`; title_html += this.get_primary_button(item, settings); title_html += `
`; } title_html += `
`; return title_html; } get_item_details(item, settings) { let details = `

${ item.item_group } | Item Code : ${ item.item_code }

${ item.short_description || '' }
${ item.formatted_price || '' } `; if (item.formatted_mrp) { details += ` ${ item.formatted_mrp ? item.formatted_mrp.replace(/ +/g, "") : "" } ${ item.discount } OFF `; } details += this.get_stock_availability(item, settings); details += `
`; return details; } get_stock_availability(item, settings) { if (!item.has_variants && !item.in_stock && settings.show_stock_availability) { return `
${ __("Out of stock") } `; } return ``; } get_wishlist_icon(item) { let icon_class = item.wished ? "wished" : "not-wished"; return `
`; } get_primary_button(item, settings) { if (item.has_variants) { return `
${ __('Explore') }
`; } else if (settings.enabled && (settings.allow_items_not_in_stock || item.in_stock)) { return `
${ __('Add to Cart') }
1
${ __('Go to Cart') }
`; } else { return ``; } } };