Skip to content

Commit 817e9ce

Browse files
committed
cart part 2.5 bug fix on 0 items on mobile when delete price
1 parent b03427d commit 817e9ce

1 file changed

Lines changed: 24 additions & 2 deletions

File tree

โ€Žmoto ride.jsโ€Ž

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -655,20 +655,35 @@ function createCartItemElement(cartProductData) {
655655
const pricePerItem = document.createElement('li');
656656
pricePerItem.classList.add('cart_price_per_item')
657657
pricePerItem.textContent = `${cartProductData.finalPrice.toLocaleString('he-IL', { minimumFractionDigits: 2, maximumFractionDigits: 2 })} $`;
658+
658659
// ืชื™ื‘ืช ื›ืžื•ืช ืœื‘ื—ื™ืจืช ืžืกืคืจ ื™ื—ื™ื“ื•ืช
659660
const quantityItem = document.createElement('li');
661+
let quantity = parseInt(cartProductData.quantity);
662+
if (!quantity || quantity < 1) quantity = 1; // ืชื™ืงื•ืŸ ื›ืžื•ืช ืœื ื—ื•ืงื™ืช
663+
664+
// ืฉืžื™ืจื” ื—ื•ื–ืจืช ืœืื•ื‘ื™ื™ืงื˜
665+
cartProductData.quantity = quantity;
666+
660667
const quantityInput = document.createElement('input');
661668
quantityInput.type = 'number';
662-
quantityInput.value = cartProductData.quantity || 1;
669+
quantityInput.value = quantity;
663670
quantityInput.min = 1;
664671
quantityInput.classList.add('chosen_product_input');
672+
673+
//TODO: ืžื•ื ืข ื”ื›ื ืกืช ืชื•ื•ื™ื ืœื ื—ื•ืงื™ื™ื (ืžืงืœื“ืช ื‘ื˜ืœืคื•ืŸ/ื“ืคื“ืคืŸ)
674+
quantityInput.addEventListener('keydown', function (e) {
675+
if (e.key === '-' || e.key === '.' || e.key === 'e') {
676+
e.preventDefault();
677+
}
678+
});
679+
665680
quantityItem.appendChild(quantityInput);
666681

667682
// ืžื—ื™ืจ ื›ื•ืœืœ (ืžื—ื™ืจ ืœื™ื—ื™ื“ื” * ื›ืžื•ืช)
668683
const totalItem = document.createElement('li');
669684
totalItem.classList.add('cart_item_total_price');
670685
const totalPrice = cartProductData.finalPrice;
671-
totalItem.textContent = `${(cartProductData.finalPrice * cartProductData.quantity).toLocaleString('he-IL', { minimumFractionDigits: 2, maximumFractionDigits: 2 })} $`;
686+
totalItem.textContent = `${(cartProductData.finalPrice * quantity).toLocaleString('he-IL', { minimumFractionDigits: 2, maximumFractionDigits: 2 })} $`;
672687
// ื—ื™ื‘ื•ืจ ื›ืœ ืฉื•ืจื•ืช ื”ืžื™ื“ืข ืœืจืฉื™ืžื”
673688
detailsList.appendChild(nameItem);
674689
detailsList.appendChild(pricePerItem);
@@ -734,6 +749,13 @@ function addCartQuantityEventListeners() {
734749
function cartQuantity(event) {
735750
const quantityInput = event.currentTarget;
736751
const quantityValue = Number(quantityInput.value);
752+
753+
// ืชื™ืงื•ืŸ ืขืจืš ืœื ื—ื•ืงื™ - ืื ืจื™ืง, ืืคืก, ืื• ืคื—ื•ืช ืž-1, ื ืงื‘ืข ืœ-1
754+
if (!quantityValue || quantityValue < 1) {
755+
quantityValue = 1;
756+
quantityInput.value = quantityValue; // ืžื—ื–ื™ืจ ืืช ื”ืฉื“ื” ืœืขืจืš ื—ื•ืงื™
757+
}
758+
737759
const productBox = quantityInput.closest('.chosen_product_list');
738760

739761
if (!productBox) return;

0 commit comments

Comments
ย (0)