@@ -80,46 +80,52 @@ function changeCatalogMenueFunction(event) {
8080 }
8181}
8282
83- //?: ืืื ืกืช ืืืฆืจืื ืืชืื ื'ืืืกืื ืืงืืืื ืืืคื ืืขืื
84- fetch ( '../assets/products.json' )
85- . then ( response => response . json ( ) )
86- . then ( products => {
87- // ืืืืงืช ืืืืช ืืืฆืจืื ืืืชืจ
88- let productsNumbersTotal = 0 ;
89- const productsNumbers = products . forEach ( product => productsNumbersTotal ++ ) ;
90- const total_products = document . querySelector ( '.total_products' ) ;
91- if ( total_products )
92- total_products . textContent = `Discover ${ productsNumbersTotal } exlusive motorcyles` ;
93-
94- // ืกืื ืื ืืืืฆืจืื ืืคื ืืคืืคืืืจืืืช ืืืืืื ืืืืชืจ
95- const topPopularProducts = products
96- . sort ( ( a , b ) => b . popularity - a . popularity ) // ืืืื ืืืืืื ืื ืืื
97- . slice ( 0 , 4 ) ; // ืืงืืืช ืจืง 4 ืจืืฉืื ืื
98-
99- // ืื ืืืช ืืจืืืกืื ืจืง ืขืืืจ ืืคืืคืืืจืืื
100- topPopularProducts . forEach ( product => {
101- createProductCardItemElement ( product ) ; // ืื ืืคืื ืงืฆืื ืฉืื ืฉืืืฆืจืช ืืช ืืืจืืืก
102- } ) ;
103-
104- // ืืืืง ืื ืื ืืฃ ืืืฆืจ ืืคื ืืชืืืช URL
105- if ( window . location . href . includes ( 'product%20page.html' ) ) {
106- const urlId = window . location . href . split ( '=' ) [ 2 ] . split ( '&' ) [ 0 ] ;
107- const product = products . find ( productId => productId . id === urlId ) ;
108- if ( product ) {
109- createProductPage ( product ) ;
110- } else {
111- console . warn ( 'Not found product with id:' , urlId ) ;
112- }
113- }
83+ //?: ืืฉืื ืฉื ืืืจืืข ืฉืืจืขื ื ืืช ืืืคืื
84+ document . addEventListener ( 'DOMContentLoaded' , ( ) => {
85+ //?: ืืื ืกืช ืืืฆืจืื ืืชืื ื'ืืืกืื ืืงืืืื ืืืคื ืืขืื
86+ fetch ( '../assets/products.json' )
87+ . then ( response => response . json ( ) )
88+ . then ( products => {
89+ // ืืืืงืช ืืืืช ืืืฆืจืื ืืืชืจ
90+ let productsNumbersTotal = 0 ;
91+ products . forEach ( ( ) => productsNumbersTotal ++ ) ;
92+ const total_products = document . querySelector ( '.total_products' ) ;
93+ if ( total_products )
94+ total_products . textContent = `Discover ${ productsNumbersTotal } exlusive motorcyles` ;
95+
96+ // ืกืื ืื ืืืืฆืจืื ืืคื ืืคืืคืืืจืืืช ืืืืืื ืืืืชืจ
97+ const topPopularProducts = products
98+ . sort ( ( a , b ) => b . popularity - a . popularity ) // ืืืื ืืืืืื ืื ืืื
99+ . slice ( 0 , 4 ) ; // ืืงืืืช ืจืง 4 ืจืืฉืื ืื
100+
101+ // ืื ืืืช ืืจืืืกืื ืจืง ืขืืืจ ืืคืืคืืืจืืื (ืืืฃ ืืืืช)
102+ topPopularProducts . forEach ( product => {
103+ createProductCardItemElement ( product ) ; // ืื ืืคืื ืงืฆืื ืฉืื ืฉืืืฆืจืช ืืช ืืืจืืืก
104+ } ) ;
105+
106+ // ืืืืง ืื ืื ืืฃ ืืืฆืจ ืืคื ืืชืืืช URL
107+ if ( window . location . href . includes ( 'product%20page.html' ) ) {
108+ const urlId = window . location . href . split ( '=' ) [ 2 ] . split ( '&' ) [ 0 ] ;
109+ const product = products . find ( p => p . id === urlId ) ;
110+ if ( product ) {
111+ createProductPage ( product ) ;
112+ } else {
113+ console . warn ( 'Not found product with id:' , urlId ) ;
114+ }
115+ }
116+ // ืื ืื ืื ืืฃ ืืืฆืจ โ ืืืฆืจืื ืืช ืื ืืจืืืกื ืืงืืืื (ืืืฃ ืงืืืื)
117+ else if ( window . location . href . includes ( 'catalog.html' ) ) {
118+ products . forEach ( product => {
119+ creator ( product ) ;
120+ } ) ;
121+ }
122+ } )
123+ . catch ( error => console . error ( 'Error loading JSON:' , error ) ) ;
114124
115- // ืื ืื ืื ืืฃ ืืืฆืจ โ ืืืฆืจืื ืืช ืื ืืจืืืกื ืืงืืืื
116- else {
117- products . forEach ( product => {
118- creator ( product ) ;
119- } ) ;
120- }
121- } )
122- . catch ( error => console . error ( 'Error loading JSON:' , error ) ) ;
125+ // ืืขืื ืช ืืืขืืคืื ืืขืืื ืืืืืงืื ืกืืืจื' ืืื ืืฃ
126+ loadWishlistFromLocalStorage ( ) ;
127+ loadCartFromLocalStorage ( ) ;
128+ } ) ;
123129
124130//TODO: ืคืื ืงืฆืื ืจืืฉืืช ืฉื ืื ืื ืฉืคืืขื ืืืจื ืงืืืช ืื ืชืื ืื
125131function creator ( product ) {
@@ -489,18 +495,6 @@ function updateWishlistHearts() {
489495 } ) ;
490496}
491497
492- //?: ืืฉืื ืฉื ืืืจืืข ืฉืืจืขื ื ืืช ืืืคืื
493- document . addEventListener ( 'DOMContentLoaded' , ( ) => {
494- loadWishlistFromLocalStorage ( ) ;
495- loadCartFromLocalStorage ( ) ;
496-
497- //TODO: ืืืืงืช ืืชืืืช ืืงืจืืื ืืคืื ืงืฆืื ืืื ืืืช ืืฃ ืืืฆืจ
498- if ( window . location . href . includes ( 'product%20page.html' ) ) {
499- const urlId = window . location . href . split ( '=' ) [ 2 ] . split ( '&' ) [ 0 ] ;
500- createProductPage ( product ) ;
501- }
502- } ) ;
503-
504498//TODO: ืคืื ืงืฆืื ืฉืฉืืืคืช ืืืืืืจืื ืืช ืื ืชืื ืื ืฉื ืืืืฆืจืื ืืืืื ืช ืคืื ืงืฆืื ืฉืืื ื ืืืชื ืืืืขืืคืื
505499function loadWishlistFromLocalStorage ( ) {
506500 const wishlist = JSON . parse ( localStorage . getItem ( 'wishlist' ) ) || [ ] ;
0 commit comments