Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions webshop/public/js/product_ui/grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ webshop.ProductGrid = class {

get_image_html(item, title) {
let image = item.website_image;
let badges_html = this.get_badges_html(item);

if (image) {
return `
<div class="card-img-container">
${badges_html}
<a href="/${ item.route || '#' }" style="text-decoration: none;">
<img itemprop="image" class="card-img" src="${ image }" alt="${ title }">
</a>
Expand All @@ -48,6 +50,7 @@ webshop.ProductGrid = class {
} else {
return `
<div class="card-img-container">
${badges_html}
<a href="/${ item.route || '#' }" style="text-decoration: none;">
<div class="card-img-top no-image">
${ frappe.get_abbr(title) }
Expand All @@ -58,6 +61,22 @@ webshop.ProductGrid = class {
}
}

get_badges_html(item) {
let badges = '';

// Add discount badge if product has a discount
if (item.discount && item.formatted_mrp) {
badges += `<div class="discount-badge">${item.discount}</div>`;
}

// Add out of stock badge
if (!item.in_stock && !item.on_backorder) {
badges += `<div class="out-of-stock-badge">${__("Out of Stock")}</div>`;
}

return badges;
}

get_card_body_html(item, title, settings) {
let body_html = `
<div class="card-body text-left card-body-flex" style="width:100%">
Expand Down
18 changes: 16 additions & 2 deletions webshop/public/js/product_ui/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ webshop.ProductList = class {
get_image_html(item, title, settings) {
let image = item.website_image;
let wishlist_enabled = !item.has_variants && settings.enable_wishlist;
let badges_html = this.get_badges_html(item);
let image_html = ``;

if (image) {
image_html += `
<div class="col-2 border text-center rounded list-image">
<div class="col-2 border text-center rounded list-image" style="position: relative;">
${badges_html}
<a class="product-link product-list-link" href="/${ item.route || '#' }">
<img itemprop="image" class="website-image h-100 w-100" alt="${ title }"
src="${ image }">
Expand All @@ -51,7 +53,8 @@ webshop.ProductList = class {
`;
} else {
image_html += `
<div class="col-2 border text-center rounded list-image">
<div class="col-2 border text-center rounded list-image" style="position: relative;">
${badges_html}
<a class="product-link product-list-link" href="/${ item.route || '#' }"
style="text-decoration: none">
<div class="card-img-top no-image-list">
Expand All @@ -66,6 +69,17 @@ webshop.ProductList = class {
return image_html;
}

get_badges_html(item) {
let badges = '';

// Add discount badge if product has a discount
if (item.discount && item.formatted_mrp) {
badges += `<div class="discount-badge" style="top: 8px; right: 8px;">${item.discount}</div>`;
}

return badges;
}

get_row_body_html(item, title, settings) {
let body_html = `<div class='col-10 text-left'>`;
body_html += this.get_title_html(item, title, settings);
Expand Down
Loading