@@ -1583,6 +1583,28 @@ class ConfiguratorPage {
15831583 return ;
15841584 }
15851585
1586+ // Filter out duplicates based on vehicle_code, color_code, and year_code
1587+ const uniqueStockMap = new Map ( ) ;
1588+ const filteredStockData = stockData . filter ( stockItem => {
1589+ if ( ! stockItem . vehicle_code || ! stockItem . color_code || ! stockItem . year_code ) {
1590+ return true ; // Keep items without these properties
1591+ }
1592+
1593+ const uniqueKey = `${ stockItem . vehicle_code } -${ stockItem . color_code } -${ stockItem . year_code } ` ;
1594+
1595+ if ( ! uniqueStockMap . has ( uniqueKey ) ) {
1596+ uniqueStockMap . set ( uniqueKey , true ) ;
1597+ return true ; // Keep first occurrence
1598+ }
1599+
1600+ return false ; // Skip duplicates
1601+ } ) ;
1602+
1603+ console . log ( `Filtered ${ stockData . length } stock items to ${ filteredStockData . length } unique items` ) ;
1604+
1605+ // Update the stored stock data to use filtered data
1606+ this . stockData = filteredStockData ;
1607+
15861608 // Show the section
15871609 stockSection . style . display = 'block' ;
15881610
@@ -1602,17 +1624,17 @@ class ConfiguratorPage {
16021624 const clonedItems = listContainer . querySelectorAll ( '.w-dyn-item.cloned' ) ;
16031625 clonedItems . forEach ( item => item . remove ( ) ) ;
16041626
1605- // Create cards for each stock item
1606- stockData . forEach ( stockItem => {
1627+ // Create cards for each unique stock item
1628+ filteredStockData . forEach ( stockItem => {
16071629 if ( ! stockItem . config ) return ;
16081630
16091631 const card = templateItem . cloneNode ( true ) ;
16101632 card . classList . add ( 'cloned' ) ;
16111633 card . style . display = 'block' ;
1612-
1634+
16131635 // Add VIN identifier to maintain card-data relationship
16141636 card . setAttribute ( 'data-vin' , stockItem . vin ) ;
1615-
1637+
16161638 // Find color option
16171639 const colorOption = stockItem . config . color_options ?. find (
16181640 opt => opt . code === stockItem . color_code
0 commit comments