erpnext.ProductGrid = class { /* Options: - items: Items - settings: E Commerce Settings - products_section: Products Wrapper - preference: If preference is not grid view, render but hide */ constructor(options) { Object.assign(this, options); if (this.preference !== "Grid 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 > 90 ? title.substr(0, 90) + "..." : title; html += `
`; html += me.get_image_html(item, title); html += me.get_card_body_html(item, title, me.settings); html += `
`; }); let $product_wrapper = this.products_section; $product_wrapper.append(html); } get_image_html(item, title) { let image = item.website_image || item.image; if (image) { return `
${ title }
`; } else { return `
${ frappe.get_abbr(title) }
`; } } get_card_body_html(item, title, settings) { let body_html = `
`; body_html += this.get_title(item, title); // get floating elements if (!item.has_variants) { if (settings.enable_wishlist) { body_html += this.get_wishlist_icon(item); } if (settings.enabled) { body_html += this.get_cart_indicator(item); } } body_html += `
`; body_html += `
${ item.item_group || '' }
`; if (item.formatted_price) { body_html += this.get_price_html(item); } body_html += this.get_stock_availability(item, settings); body_html += this.get_primary_button(item, settings); body_html += `
`; // close div on line 49 return body_html; } get_title(item, title) { let title_html = `
${ title || '' }
`; return title_html; } get_wishlist_icon(item) { let icon_class = item.wished ? "wished" : "not-wished"; return `
`; } get_cart_indicator(item) { return `
1
`; } get_price_html(item) { let price_html = `
${ item.formatted_price || '' } `; if (item.formatted_mrp) { price_html += ` ${ item.formatted_mrp ? item.formatted_mrp.replace(/ +/g, "") : "" } ${ item.discount } OFF `; } price_html += `
`; return price_html; } get_stock_availability(item, settings) { if (settings.show_stock_availability && !item.has_variants) { if (item.on_backorder) { return ` ${ __("Available on backorder") } `; } else if (!item.in_stock) { return ` ${ __("Out of stock") } `; } } 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 `
${ settings.enable_checkout ? __('Add to Cart') : __('Add to Quote') }
${ settings.enable_checkout ? __('Go to Cart') : __('Go to Quote') }
`; } else { return ``; } } };