Skip to content

Commit

Permalink
Rework quantity error when same variant present in the cart twice
Browse files Browse the repository at this point in the history
  • Loading branch information
mironov committed Jun 8, 2024
1 parent d745429 commit f3bb45e
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions assets/cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,17 +184,19 @@ class CartItems extends HTMLElement {
section.selector
);
});
const updatedLine = parsedState.items.find((item) => item.variant_id === parseInt(variantId));
const updatedValue = updatedLine ? updatedLine.quantity : undefined;
let message = '';
if (items.length === parsedState.items.length && updatedLine && updatedValue !== parseInt(quantityElement.value)) {
if (typeof updatedValue === 'undefined') {
message = window.cartStrings.error;
} else {
message = window.cartStrings.quantityError.replace('[quantity]', updatedValue);
const updatedLine = parsedState.items[line - 1];
if (updatedLine && updatedLine.variant_id === parseInt(variantId)) {
const updatedValue = updatedLine ? updatedLine.quantity : undefined;
let message = '';
if (updatedValue !== parseInt(quantityElement.value)) {
if (typeof updatedValue === 'undefined') {
message = window.cartStrings.error;
} else {
message = window.cartStrings.quantityError.replace('[quantity]', updatedValue);
}
}
this.updateLiveRegions(line, message);
}
this.updateLiveRegions(line, message);

const lineItem =
document.getElementById(`CartItem-${line}`) || document.getElementById(`CartDrawer-Item-${line}`);
Expand Down

0 comments on commit f3bb45e

Please sign in to comment.