@@ -13,8 +13,6 @@ document.addEventListener('DOMContentLoaded', function () { // On document load,
1313} ) ;
1414
1515function addToCart ( id ) { // Add product to cart function
16- console . log ( `Tu as ajouté le produit ${ id } ` ) ; // Console log the product i
17-
1816 let product = getProductDetails ( Number ( id ) ) ; // Get the product details
1917
2018 if ( product . stock <= 0 ) { // If stock is 0 or less
@@ -24,7 +22,6 @@ function addToCart(id) { // Add product to cart function
2422 product . stock -- ; // Decrease 1 to the product in cart
2523 document . querySelector ( `.stock-${ product . id } ` ) . innerHTML = product . stock ; // Display the new stock
2624 }
27-
2825 // Check if product is already in cart
2926 const productCartName = `inCart-${ product . id } ` ; // Set the product cart name
3027 let cart = localStorage . getItem ( productCartName ) ; // Get the product cart
@@ -35,7 +32,6 @@ function addToCart(id) { // Add product to cart function
3532 localStorage . setItem ( productCartName , JSON . stringify ( cart ) ) ; // Set the product cart
3633
3734 // Update the cart
38- console . log ( product . slug + '-inCart' ) ; // Console log the product slug
3935 document . querySelector ( `.${ product . slug } -inCart` ) . innerHTML = cart . productsInCart ; // Update the product in cart
4036
4137 } else { // If the product cart doesn't exist
@@ -50,7 +46,7 @@ function addToCart(id) { // Add product to cart function
5046}
5147
5248////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
53- // All Functions
49+ // All Functions UwU
5450////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
5551
5652function notification ( message , type = 'success' ) { // Function to show notification
@@ -142,7 +138,6 @@ document.addEventListener('click', function (e) { // On click, execute the follo
142138
143139 if ( getItem !== null ) { // Check if the product is already in the cart
144140 COURSES [ i ] . stock += getItem . productsInCart ; // Increment the quantity of the product in stock
145- console . log ( "Stock " + COURSES [ i ] . stock ) ;
146141
147142 document . querySelector ( `.stock-${ COURSES [ i ] . id } ` ) . innerHTML = COURSES [ i ] . stock ; // Display the new stock
148143 }
@@ -158,31 +153,30 @@ document.addEventListener('click', function (e) { // On click, execute the follo
158153 // your cart //
159154 //-------------------------------------------------//
160155
161- let idTrash = e . target . parentNode . parentNode . dataset . id ; // Get the product id
162- let product = getProductDetails ( Number ( idTrash ) ) ; // Get the product details
156+ let product = getProductDetails ( Number ( e . target . parentNode . parentNode . dataset . id ) ) ; // Get the product details
163157
164158 product . stock ++ ; // Add 1 to the product stock
165- document . querySelector ( `.stock-${ idTrash } ` ) . innerHTML = product . stock ; // Display the new stock
159+ document . querySelector ( `.stock-${ product . id } ` ) . innerHTML = product . stock ; // Display the new stock
166160
167- let getItem = JSON . parse ( localStorage . getItem ( `inCart-${ idTrash } ` ) ) ; // See how many times the product is in the cart
161+ let getItem = JSON . parse ( localStorage . getItem ( `inCart-${ product . id } ` ) ) ; // See how many times the product is in the cart
168162
169163 if ( getItem . productsInCart <= 1 ) { // If only 1 product is in the cart
170- localStorage . removeItem ( `inCart-${ idTrash } ` ) ; // Remove the product from the localStorage
164+ localStorage . removeItem ( `inCart-${ product . id } ` ) ; // Remove the product from the localStorage
171165 document . querySelector ( `.${ e . target . parentNode . parentNode . classList [ 0 ] } ` ) . remove ( ) ; // Remove the product from the cart
172166 notification ( `${ product . title } à totalement été supprimé du panier` , `danger` ) ; // Alert the user with notification
173167 } else { // Otherwise
174168 getItem . productsInCart -- ; // Decrease 1 to the product in cart
175- localStorage . setItem ( `inCart-${ idTrash } ` , JSON . stringify ( getItem ) ) ; // Remove the product from the localStorage
169+ localStorage . setItem ( `inCart-${ product . id } ` , JSON . stringify ( getItem ) ) ; // Remove the product from the localStorage
176170 document . querySelector ( `.${ product . slug } -inCart` ) . innerHTML = getItem . productsInCart ; // Remove the product from the cart
177171 notification ( `1 cours "${ product . title } " à été supprimé du panier` , `danger` ) ; // Alert the user with notification
178172 }
179173 } else if ( e . target . classList . contains ( 'noteOrdre' ) ) { // If the user clicks on the noteOrdre button, execuse the following code
180- filtre ( "noteCroissant" ) ;
174+ filtre ( "noteCroissant" ) ; // Sort the products by note
181175 } else if ( e . target . classList . contains ( 'noteDesordre' ) ) { // If the user clicks on the noteDesordre button, execuse the following code
182- filtre ( "noteDecroissant" ) ;
176+ filtre ( "noteDecroissant" ) ; // Sort the products by note
183177 } else if ( e . target . classList . contains ( 'prixOrdre' ) ) { // If the user clicks on the prixOrdre button, execuse the following code
184- filtre ( "prixCroissant" ) ;
178+ filtre ( "prixCroissant" ) ; // Sort the products by price
185179 } else if ( e . target . classList . contains ( 'prixDesordre' ) ) { // If the user clicks on the prixDesordre button, execuse the following code
186- filtre ( "prixDecroissant" ) ;
180+ filtre ( "prixDecroissant" ) ; // Sort the products by price
187181 }
188182} ) ;
0 commit comments