Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(pos): rendering of broken image on pos #25872

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion erpnext/selling/page/point_of_sale/pos_item_cart.js
Expand Up @@ -636,13 +636,23 @@ erpnext.PointOfSale.ItemCart = class {
function get_item_image_html() {
const { image, item_name } = item_data;
if (image) {
return `<div class="item-image"><img src="${image}" alt="${image}""></div>`;
return `
<div class="item-image">
<img
onerror="cur_pos.cart.handle_broken_image(this)"
src="${image}" alt="${frappe.get_abbr(item_name)}"">
</div>`;
} else {
return `<div class="item-image item-abbr">${frappe.get_abbr(item_name)}</div>`;
}
}
}

handle_broken_image($img) {
const item_abbr = $($img).attr('alt');
$($img).parent().replaceWith(`<div class="item-image item-abbr">${item_abbr}</div>`);
}

scroll_to_item($item) {
if ($item.length === 0) return;
const scrollTop = $item.offset().top - this.$cart_items_wrapper.offset().top + this.$cart_items_wrapper.scrollTop();
Expand Down
11 changes: 10 additions & 1 deletion erpnext/selling/page/point_of_sale/pos_item_selector.js
Expand Up @@ -94,7 +94,11 @@ erpnext.PointOfSale.ItemSelector = class {
<span class="indicator-pill whitespace-nowrap ${indicator_color}">${qty_to_display}</span>
</div>
<div class="flex items-center justify-center h-32 border-b-grey text-6xl text-grey-100">
<img class="h-full" src="${item_image}" alt="${frappe.get_abbr(item.item_name)}" style="object-fit: cover;">
<img
onerror="cur_pos.item_selector.handle_broken_image(this)"
class="h-full" src="${item_image}"
alt="${frappe.get_abbr(item.item_name)}"
style="object-fit: cover;">
</div>`;
} else {
return `<div class="item-qty-pill">
Expand Down Expand Up @@ -122,6 +126,11 @@ erpnext.PointOfSale.ItemSelector = class {
);
}

handle_broken_image($img) {
const item_abbr = $($img).attr('alt');
$($img).parent().replaceWith(`<div class="item-display abbr">${item_abbr}</div>`);
}

make_search_bar() {
const me = this;
const doc = me.events.get_frm().doc;
Expand Down