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 `
`;
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 = `
${ 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 (!item.has_variants && !item.in_stock && settings.show_stock_availability) {
return `