2021-05-17 15:14:41 +00:00
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
2021-05-24 20:05:22 +00:00
|
|
|
this.products_section.empty();
|
2021-05-17 15:14:41 +00:00
|
|
|
this.make();
|
|
|
|
}
|
|
|
|
|
|
|
|
make() {
|
|
|
|
let me = this;
|
|
|
|
let html = `<br><br>`;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2021-07-11 21:58:33 +00:00
|
|
|
html += `<div class='row list-row w-100'>`;
|
|
|
|
html += me.get_image_html(item, title, me.settings);
|
2021-05-17 15:14:41 +00:00
|
|
|
html += me.get_row_body_html(item, title, me.settings);
|
|
|
|
html += `</div>`;
|
2021-05-17 15:57:42 +00:00
|
|
|
});
|
2021-05-17 15:14:41 +00:00
|
|
|
|
|
|
|
let $product_wrapper = this.products_section;
|
|
|
|
$product_wrapper.append(html);
|
|
|
|
}
|
|
|
|
|
2021-07-11 21:58:33 +00:00
|
|
|
get_image_html(item, title, settings) {
|
2021-05-17 15:14:41 +00:00
|
|
|
let image = item.website_image || item.image;
|
2021-07-11 21:58:33 +00:00
|
|
|
let wishlist_enabled = !item.has_variants && settings.enable_wishlist;
|
|
|
|
let image_html = ``;
|
2021-05-17 15:14:41 +00:00
|
|
|
|
2021-05-17 15:57:42 +00:00
|
|
|
if (image) {
|
2021-07-11 21:58:33 +00:00
|
|
|
image_html += `
|
2021-05-27 13:23:11 +00:00
|
|
|
<div class="col-2 border text-center rounded list-image">
|
2021-05-17 15:14:41 +00:00
|
|
|
<a class="product-link product-list-link" href="/${ item.route || '#' }">
|
|
|
|
<img itemprop="image" class="website-image h-100 w-100" alt="${ title }"
|
|
|
|
src="${ image }">
|
|
|
|
</a>
|
2021-07-11 21:58:33 +00:00
|
|
|
${ wishlist_enabled ? this.get_wishlist_icon(item): '' }
|
2021-05-17 15:14:41 +00:00
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
} else {
|
2021-07-11 21:58:33 +00:00
|
|
|
image_html += `
|
2021-06-08 14:10:26 +00:00
|
|
|
<div class="col-2 border text-center rounded list-image">
|
|
|
|
<a class="product-link product-list-link" href="/${ item.route || '#' }"
|
|
|
|
style="text-decoration: none">
|
|
|
|
<div class="card-img-top no-image-list">
|
|
|
|
${ frappe.get_abbr(title) }
|
|
|
|
</div>
|
|
|
|
</a>
|
2021-07-11 21:58:33 +00:00
|
|
|
${ wishlist_enabled ? this.get_wishlist_icon(item): '' }
|
2021-06-08 14:10:26 +00:00
|
|
|
</div>
|
2021-05-17 15:14:41 +00:00
|
|
|
`;
|
|
|
|
}
|
2021-07-11 21:58:33 +00:00
|
|
|
|
|
|
|
return image_html;
|
2021-05-17 15:14:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get_row_body_html(item, title, settings) {
|
2021-07-11 21:58:33 +00:00
|
|
|
let body_html = `<div class='col-10 text-left'>`;
|
2021-05-17 15:14:41 +00:00
|
|
|
body_html += this.get_title_html(item, title, settings);
|
|
|
|
body_html += this.get_item_details(item, settings);
|
|
|
|
body_html += `</div>`;
|
|
|
|
return body_html;
|
|
|
|
}
|
|
|
|
|
|
|
|
get_title_html(item, title, settings) {
|
|
|
|
let title_html = `<div style="display: flex; margin-left: -15px;">`;
|
|
|
|
title_html += `
|
|
|
|
<div class="col-8" style="margin-right: -15px;">
|
|
|
|
<a class="" href="/${ item.route || '#' }"
|
|
|
|
style="color: var(--gray-800); font-weight: 500;">
|
|
|
|
${ title }
|
|
|
|
</a>
|
2021-07-11 21:58:33 +00:00
|
|
|
</div>
|
2021-05-17 15:14:41 +00:00
|
|
|
`;
|
|
|
|
|
2021-07-11 21:58:33 +00:00
|
|
|
if (settings.enabled) {
|
2021-05-17 15:14:41 +00:00
|
|
|
title_html += `<div class="col-4" style="display:flex">`;
|
|
|
|
title_html += this.get_primary_button(item, settings);
|
|
|
|
title_html += `</div>`;
|
|
|
|
}
|
|
|
|
title_html += `</div>`;
|
|
|
|
|
|
|
|
return title_html;
|
|
|
|
}
|
|
|
|
|
2021-07-11 21:58:33 +00:00
|
|
|
get_item_details(item, settings) {
|
2021-05-17 15:14:41 +00:00
|
|
|
let details = `
|
|
|
|
<p class="product-code">
|
2021-07-11 21:58:33 +00:00
|
|
|
${ item.item_group } | Item Code : ${ item.item_code }
|
2021-05-17 15:14:41 +00:00
|
|
|
</p>
|
2021-07-11 21:58:33 +00:00
|
|
|
<div class="mt-2" style="color: var(--gray-600) !important; font-size: 13px;">
|
2021-07-08 07:22:57 +00:00
|
|
|
${ item.short_description || '' }
|
2021-05-17 15:14:41 +00:00
|
|
|
</div>
|
|
|
|
<div class="product-price">
|
|
|
|
${ item.formatted_price || '' }
|
|
|
|
`;
|
|
|
|
|
2021-05-17 15:57:42 +00:00
|
|
|
if (item.formatted_mrp) {
|
2021-05-17 15:14:41 +00:00
|
|
|
details += `
|
2021-07-11 21:58:33 +00:00
|
|
|
<small class="striked-price">
|
|
|
|
<s>${ item.formatted_mrp ? item.formatted_mrp.replace(/ +/g, "") : "" }</s>
|
2021-05-17 15:14:41 +00:00
|
|
|
</small>
|
2021-07-11 21:58:33 +00:00
|
|
|
<small class="ml-1 product-info-green">
|
2021-05-17 15:14:41 +00:00
|
|
|
${ item.discount } OFF
|
|
|
|
</small>
|
|
|
|
`;
|
|
|
|
}
|
2021-07-11 21:58:33 +00:00
|
|
|
|
|
|
|
details += this.get_stock_availability(item, settings);
|
2021-05-17 15:14:41 +00:00
|
|
|
details += `</div>`;
|
|
|
|
|
|
|
|
return details;
|
|
|
|
}
|
|
|
|
|
2021-07-11 21:58:33 +00:00
|
|
|
get_stock_availability(item, settings) {
|
|
|
|
if (!item.has_variants && !item.in_stock && settings.show_stock_availability) {
|
2021-07-13 20:06:50 +00:00
|
|
|
return `
|
|
|
|
<br>
|
|
|
|
<span class="out-of-stock mt-2">${ __("Out of stock") }</span>
|
|
|
|
`;
|
2021-07-11 21:58:33 +00:00
|
|
|
}
|
|
|
|
return ``;
|
|
|
|
}
|
|
|
|
|
2021-05-17 15:14:41 +00:00
|
|
|
get_wishlist_icon(item) {
|
|
|
|
let icon_class = item.wished ? "wished" : "not-wished";
|
|
|
|
|
|
|
|
return `
|
2021-07-11 21:58:33 +00:00
|
|
|
<div class="like-action-list ${ item.wished ? "like-action-wished" : ''}"
|
2021-05-17 15:14:41 +00:00
|
|
|
data-item-code="${ item.item_code }"
|
|
|
|
data-price="${ item.price || '' }"
|
|
|
|
data-formatted-price="${ item.formatted_price || '' }">
|
|
|
|
<svg class="icon sm">
|
|
|
|
<use class="${ icon_class } wish-icon" href="#icon-heart"></use>
|
|
|
|
</svg>
|
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
|
|
|
|
get_primary_button(item, settings) {
|
|
|
|
if (item.has_variants) {
|
|
|
|
return `
|
|
|
|
<a href="/${ item.route || '#' }">
|
2021-07-11 21:58:33 +00:00
|
|
|
<div class="btn btn-sm btn-explore-variants btn"
|
|
|
|
style="margin-bottom: 0; max-height: 30px; float: right;
|
|
|
|
padding: 0.25rem 1rem; min-width: 135px;">
|
2021-05-17 15:14:41 +00:00
|
|
|
${ __('Explore') }
|
|
|
|
</div>
|
|
|
|
</a>
|
|
|
|
`;
|
2021-07-11 21:58:33 +00:00
|
|
|
} else if (settings.enabled && (settings.allow_items_not_in_stock || item.in_stock)) {
|
2021-05-17 15:14:41 +00:00
|
|
|
return `
|
|
|
|
<div id="${ item.name }" class="btn
|
2021-07-11 21:58:33 +00:00
|
|
|
btn-sm btn-primary btn-add-to-cart-list
|
|
|
|
${ item.in_cart ? 'hidden' : '' }"
|
2021-05-17 15:14:41 +00:00
|
|
|
data-item-code="${ item.item_code }"
|
2021-07-11 21:58:33 +00:00
|
|
|
style="margin-bottom: 0; margin-top: 0px !important; max-height: 30px; float: right;
|
|
|
|
padding: 0.25rem 1rem; min-width: 135px;">
|
|
|
|
<span class="mr-2">
|
|
|
|
<svg class="icon icon-md">
|
|
|
|
<use href="#icon-assets"></use>
|
|
|
|
</svg>
|
|
|
|
</span>
|
2021-05-17 15:14:41 +00:00
|
|
|
${ __('Add to Cart') }
|
|
|
|
</div>
|
2021-07-11 21:58:33 +00:00
|
|
|
|
|
|
|
<div class="cart-indicator ${item.in_cart ? '' : 'hidden'}" style="position: unset;">
|
|
|
|
1
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<a href="/cart">
|
|
|
|
<div id="${ item.name }" class="btn
|
|
|
|
btn-sm btn-primary btn-add-to-cart-list
|
|
|
|
ml-4 go-to-cart
|
|
|
|
${ item.in_cart ? '' : 'hidden' }"
|
|
|
|
data-item-code="${ item.item_code }"
|
|
|
|
style="padding: 0.25rem 1rem; min-width: 135px;">
|
|
|
|
${ __('Go to Cart') }
|
|
|
|
</div>
|
|
|
|
</a>
|
2021-05-17 15:14:41 +00:00
|
|
|
`;
|
2021-06-01 07:14:49 +00:00
|
|
|
} else {
|
|
|
|
return ``;
|
2021-05-17 15:14:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-17 15:57:42 +00:00
|
|
|
};
|