@@ -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() {
734749function 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