@@ -1733,51 +1733,6 @@ class ConfiguratorPage {
17331733 this . updateLoadMoreButton ( ) ;
17341734 }
17351735
1736- sortVisibleCards ( ) {
1737- const listContainer = document . querySelector ( '#models-grid' ) ;
1738- if ( ! listContainer ) return ;
1739-
1740- // Get all cloned cards
1741- const cards = Array . from ( listContainer . querySelectorAll ( '.w-dyn-item.cloned' ) ) ;
1742-
1743- // Create array of cards with their match level
1744- const cardData = cards . map ( card => {
1745- const vin = card . getAttribute ( 'data-vin' ) ;
1746- const stockItem = this . stockData . find ( item => item . vin === vin ) ;
1747-
1748- if ( ! stockItem ) return null ;
1749-
1750- const matchLevel = this . calculateMatchLevel ( stockItem ) ;
1751-
1752- // Update the tag
1753- const tagElement = card . querySelector ( '[data-element="tag"]' ) ;
1754- if ( tagElement ) {
1755- tagElement . textContent = matchLevel ;
1756- }
1757-
1758- return {
1759- card : card ,
1760- matchLevel : matchLevel
1761- } ;
1762- } ) . filter ( item => item !== null ) ;
1763-
1764- // Sort by match level
1765- const matchLevelOrder = {
1766- '完全符合' : 1 ,
1767- '相同車款' : 2 ,
1768- '相似車款' : 3
1769- } ;
1770-
1771- cardData . sort ( ( a , b ) => {
1772- return matchLevelOrder [ a . matchLevel ] - matchLevelOrder [ b . matchLevel ] ;
1773- } ) ;
1774-
1775- // Re-append in sorted order
1776- cardData . forEach ( item => {
1777- listContainer . appendChild ( item . card ) ;
1778- } ) ;
1779- }
1780-
17811736 // Helper method to update card elements
17821737 updateCardElement ( card , selector , value ) {
17831738 const element = card . querySelector ( `[data-element="${ selector } "]` ) ;
@@ -1793,56 +1748,6 @@ class ConfiguratorPage {
17931748 }
17941749 }
17951750
1796- // Create card from template with proper data binding
1797- createStockCardFromTemplate ( template , stockItem ) {
1798- if ( ! stockItem . config ) return null ;
1799-
1800- const newCard = template . cloneNode ( true ) ;
1801-
1802- // Update all elements with data-element attributes
1803- const updateElement = ( selector , value ) => {
1804- const element = newCard . querySelector ( `[data-element="${ selector } "]` ) ;
1805- if ( element ) {
1806- if ( selector === 'image' ) {
1807- element . src = value ;
1808- element . srcset = value ;
1809- } else if ( selector === 'link' ) {
1810- element . href = value ;
1811- } else {
1812- element . textContent = value ;
1813- }
1814- }
1815- } ;
1816-
1817- // Find color option
1818- const colorOption = stockItem . config . color_options ?. find (
1819- opt => opt . code === stockItem . color_code
1820- ) ;
1821-
1822- // Update all elements
1823- updateElement ( 'image' , colorOption ?. final_image ?. [ 0 ] ?. url || 'https://cdn.prod.website-files.com/6735d5a11d254f870165369e/67615937b9e72eb31b06f316_placeholder.webp' ) ;
1824- updateElement ( 'tag' , this . calculateMatchLevel ( stockItem ) ) ;
1825- updateElement ( 'title' , this . currentConfig . model ?. name || '' ) ;
1826- updateElement ( 'trim' , stockItem . config . _trims ?. name || '' ) ;
1827- updateElement ( 'engine' , stockItem . config . _engines ?. name || '' ) ;
1828-
1829- // Calculate and update price
1830- const totalPrice = this . calculateStockTotalPrice ( stockItem ) ;
1831- updateElement ( 'price' , totalPrice . toLocaleString ( ) ) ;
1832-
1833- updateElement ( 'year' , stockItem . config . year_obj ?. [ 0 ] ?. year || '' ) ;
1834- updateElement ( 'color' , colorOption ?. color_name || '' ) ;
1835- updateElement ( 'accessories' , this . getStockAccessoriesText ( stockItem ) ) ;
1836- updateElement ( 'dealer' , this . currentDealerName || '' ) ;
1837-
1838- // Update link
1839- const pathSegments = window . location . pathname . split ( '/' ) ;
1840- const brandSlug = pathSegments [ 1 ] ;
1841- updateElement ( 'link' , `/${ brandSlug } /stock-detail?vin=${ stockItem . vin } ` ) ;
1842-
1843- return newCard ;
1844- }
1845-
18461751 // Helper method to calculate total price
18471752 calculateStockTotalPrice ( stockItem ) {
18481753 const modelsPrice = stockItem . config . _models ?. price || 0 ;
@@ -1865,105 +1770,6 @@ class ConfiguratorPage {
18651770 return '無' ;
18661771 }
18671772
1868- // Add method to create individual stock card
1869- createStockCard ( template , stockItem ) {
1870- if ( ! stockItem . config ) return null ;
1871-
1872- const card = template . cloneNode ( true ) ;
1873- card . classList . remove ( 'w-dyn-item-template' ) ;
1874-
1875- // Update image
1876- const imageEl = card . querySelector ( '[data-element="image"]' ) ;
1877- if ( imageEl && stockItem . config . color_options && stockItem . config . color_options . length > 0 ) {
1878- // Find the matching color option
1879- const colorOption = stockItem . config . color_options . find (
1880- opt => opt . code === stockItem . color_code && opt . final_image && opt . final_image . length > 0
1881- ) ;
1882- if ( colorOption && colorOption . final_image [ 0 ] ) {
1883- imageEl . src = colorOption . final_image [ 0 ] . url ;
1884- imageEl . srcset = colorOption . final_image [ 0 ] . url ;
1885- }
1886- }
1887-
1888- // Update tag based on match level
1889- const tagEl = card . querySelector ( '[data-element="tag"]' ) ;
1890- if ( tagEl ) {
1891- tagEl . textContent = this . calculateMatchLevel ( stockItem ) ;
1892- }
1893-
1894- // Update title (model name)
1895- const titleEl = card . querySelector ( '[data-element="title"]' ) ;
1896- if ( titleEl ) {
1897- titleEl . textContent = this . currentConfig . model ?. name || '' ;
1898- }
1899-
1900- // Update trim
1901- const trimEl = card . querySelector ( '[data-element="trim"]' ) ;
1902- if ( trimEl && stockItem . config . _trims ) {
1903- trimEl . textContent = stockItem . config . _trims . name || '' ;
1904- }
1905-
1906- // Update engine
1907- const engineEl = card . querySelector ( '[data-element="engine"]' ) ;
1908- if ( engineEl && stockItem . config . _engines ) {
1909- engineEl . textContent = stockItem . config . _engines . name || '' ;
1910- }
1911-
1912- // Update price
1913- const priceEl = card . querySelector ( '[data-element="price"]' ) ;
1914- if ( priceEl ) {
1915- // Calculate total price
1916- const modelsPrice = stockItem . config . _models ?. price || 0 ;
1917- const trimPrice = stockItem . config . trim_price || 0 ;
1918- const yearPrice = stockItem . config . year_obj ?. [ 0 ] ?. price || 0 ;
1919- const colorPrice = stockItem . config . color_options ?. find ( c => c . code === stockItem . color_code ) ?. price_adjustment || 0 ;
1920- const totalPrice = modelsPrice + trimPrice + yearPrice + colorPrice ;
1921-
1922- priceEl . textContent = totalPrice . toLocaleString ( ) ;
1923- }
1924-
1925- // Update year
1926- const yearEl = card . querySelector ( '[data-element="year"]' ) ;
1927- if ( yearEl && stockItem . config . year_obj && stockItem . config . year_obj . length > 0 ) {
1928- yearEl . textContent = stockItem . config . year_obj [ 0 ] . year ;
1929- }
1930-
1931- // Update color
1932- const colorEl = card . querySelector ( '[data-element="color"]' ) ;
1933- if ( colorEl ) {
1934- const colorOption = stockItem . config . color_options ?. find ( c => c . code === stockItem . color_code ) ;
1935- colorEl . textContent = colorOption ?. color_name || '' ;
1936- }
1937-
1938- // Update accessories
1939- const accessoriesEl = card . querySelector ( '[data-element="accessories"]' ) ;
1940- if ( accessoriesEl ) {
1941- if ( stockItem . config . accessories_id && stockItem . config . accessories_id . length > 0 ) {
1942- const accessoryNames = stockItem . config . accessories_id . map ( acc => acc . name ) . join ( ', ' ) ;
1943- accessoriesEl . textContent = accessoryNames ;
1944- } else {
1945- accessoriesEl . textContent = '無' ;
1946- }
1947- }
1948-
1949- // Update dealer
1950- const dealerEl = card . querySelector ( '[data-element="dealer"]' ) ;
1951- if ( dealerEl ) {
1952- dealerEl . textContent = this . currentDealerName || '' ;
1953- }
1954-
1955- // Update link
1956- const linkEl = card . querySelector ( '[data-element="link"]' ) ;
1957- if ( linkEl ) {
1958- // Create link to stock detail page or order page
1959- const pathSegments = window . location . pathname . split ( '/' ) ;
1960- const brandSlug = pathSegments [ 1 ] ;
1961- linkEl . href = `/${ brandSlug } /stock-detail?vin=${ stockItem . vin } ` ;
1962- }
1963-
1964- return card ;
1965- }
1966-
19671773 // Add method to calculate match level
19681774 calculateMatchLevel ( stockItem ) {
19691775 // Model is already matched since we're fetching by model
0 commit comments