Skip to content

Commit 4e202d9

Browse files
authored
Merge pull request PrestaShop#607 from boherm/fix-zero-qty-in-cart
Delete product in cart when we set zero qty and submit with Enter key
2 parents a5f1476 + 6ec8f3d commit 4e202d9

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/js/components/useQuantityInput.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,19 @@ const useQuantityInput: Theme.QuantityInput.Function = (
6464
}
6565

6666
if (event.key === ENTER_KEY) {
67-
updateQuantity(qtyInputGroup, 1);
67+
if (qtyInput.value === '0') {
68+
const targetItem = qtyInput.closest(cartSelectorMap.productItem);
69+
const removeButton = targetItem?.querySelector(cartSelectorMap.removeFromCartLink) as HTMLElement
70+
| null;
71+
72+
if (removeButton) {
73+
removeButton.click();
74+
} else {
75+
updateQuantity(qtyInputGroup, 1);
76+
}
77+
} else {
78+
updateQuantity(qtyInputGroup, 1);
79+
}
6880
}
6981

7082
if (event.key === ESCAPE_KEY) {

src/js/constants/selectors-map.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ export const cart = {
3838
promoCode: '#promo-code',
3939
deleteLinkAction: 'delete-from-cart',
4040
productQuantity: '.cart__items .js-quantity-button',
41+
productItem: '.cart__item',
42+
removeFromCartLink: '.remove-from-cart',
4143
};
4244

4345
export const blockcart = {

0 commit comments

Comments
 (0)