Skip to content

Commit

Permalink
Merge pull request PrestaShop#607 from boherm/fix-zero-qty-in-cart
Browse files Browse the repository at this point in the history
Delete product in cart when we set zero qty and submit with Enter key
  • Loading branch information
nicosomb authored Mar 15, 2024
2 parents a5f1476 + 6ec8f3d commit 4e202d9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/js/components/useQuantityInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,19 @@ const useQuantityInput: Theme.QuantityInput.Function = (
}

if (event.key === ENTER_KEY) {
updateQuantity(qtyInputGroup, 1);
if (qtyInput.value === '0') {
const targetItem = qtyInput.closest(cartSelectorMap.productItem);
const removeButton = targetItem?.querySelector(cartSelectorMap.removeFromCartLink) as HTMLElement
| null;

if (removeButton) {
removeButton.click();
} else {
updateQuantity(qtyInputGroup, 1);
}
} else {
updateQuantity(qtyInputGroup, 1);
}
}

if (event.key === ESCAPE_KEY) {
Expand Down
2 changes: 2 additions & 0 deletions src/js/constants/selectors-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export const cart = {
promoCode: '#promo-code',
deleteLinkAction: 'delete-from-cart',
productQuantity: '.cart__items .js-quantity-button',
productItem: '.cart__item',
removeFromCartLink: '.remove-from-cart',
};

export const blockcart = {
Expand Down

0 comments on commit 4e202d9

Please sign in to comment.