diff --git a/react/components/SKUSelector/components/SKUSelector.tsx b/react/components/SKUSelector/components/SKUSelector.tsx index d99f9b4e9..c3619fa73 100644 --- a/react/components/SKUSelector/components/SKUSelector.tsx +++ b/react/components/SKUSelector/components/SKUSelector.tsx @@ -122,10 +122,9 @@ interface AvailableVariationParams { } export const orderItemsByAvailability = ( - item1: SelectorProductItem, + item1: SelectorProductItem, item2: SelectorProductItem ) => { - const isAvailableItem1 = isSkuAvailable(item1) const isAvailableItem2 = isSkuAvailable(item2) @@ -140,17 +139,15 @@ export const orderItemsByAvailability = ( const defaultSellerItem1 = getDefaultSeller(item1.sellers) const defaultSellerItem2 = getDefaultSeller(item2.sellers) - const availabilityItem1 = defaultSellerItem1 + const availabilityItem1 = defaultSellerItem1 ? defaultSellerItem1.commertialOffer.AvailableQuantity : 0 - const availabilityItem2 = defaultSellerItem2 + const availabilityItem2 = defaultSellerItem2 ? defaultSellerItem2.commertialOffer.AvailableQuantity : 0 return availabilityItem2 - availabilityItem1 - } - const parseOptionNameToDisplayOption = ({ selectedVariations, @@ -193,8 +190,8 @@ const parseOptionNameToDisplayOption = // This is a valid combination option const possibleItemsOrderedByAvailability = - possibleItems.length > 1 - ? possibleItems.sort(orderItemsByAvailability) + possibleItems.length > 1 + ? possibleItems.sort(orderItemsByAvailability) : possibleItems const [item] = possibleItemsOrderedByAvailability