Fix price sorting error by filtering null values before sort

Prevents "TypeError: a is null" when comparing prices.
This commit is contained in:
carmenmaymo 2025-05-19 16:13:32 +02:00
parent f038cbc2b0
commit 0eb2f1258a
No known key found for this signature in database
GPG key ID: 6023F686B0F3102E

View file

@ -162,12 +162,16 @@ class SingleProductBootstrap {
},
]
.map( ( f ) => f() )
.sort((a, b) => {
if (parseInt(a.replace(/\D/g, '')) < parseInt(b.replace(/\D/g, '')) ) {
return 1;
}
return -1;
})
.filter( ( val ) => val !== null && val !== undefined )
.sort( ( a, b ) => {
if (
parseInt( a.replace( /\D/g, '' ) ) <
parseInt( b.replace( /\D/g, '' ) )
) {
return 1;
}
return -1;
} )
.find( ( val ) => val );
if ( typeof priceText === 'undefined' ) {