+ {option.values.map((value) => {
+ const optionNameLowerCase = option.name.toLowerCase();
+ const optionSearchParams = new URLSearchParams(searchParams.toString());
- optionSearchParams.set(optionNameLowerCase, value);
+ optionSearchParams.set(optionNameLowerCase, value);
- // In order to determine if an option is available for sale, we need to:
- //
- // 1. Filter out all other param state
- // 2. Filter out invalid options
- // 3. Check if the option combination is available for sale
- //
- // This is the "magic" that will cross check possible variant combinations and preemptively
- // disable combinations that are not available. For example, if the color gray is only available in size medium,
- // then all other sizes should be disabled.
- const filtered = Array.from(optionSearchParams.entries()).filter(
- ([key, value]) =>
- options.find(
- (option) =>
- option.name.toLowerCase() === key && option.values.includes(value)
- )
- );
-
- const isAvailableForSale = combinations.find((combination) =>
- filtered.every(
- ([key, value]) =>
- combination[key] === value && combination.availableForSale
+ // In order to determine if an option is available for sale, we need to:
+ //
+ // 1. Filter out all other param state
+ // 2. Filter out invalid options
+ // 3. Check if the option combination is available for sale
+ //
+ // This is the "magic" that will cross check possible variant combinations and preemptively
+ // disable combinations that are not available. For example, if the color gray is only available in size medium,
+ // then all other sizes should be disabled.
+ const filtered = Array.from(optionSearchParams.entries()).filter(
+ ([key, value]) =>
+ options.find(
+ (option) =>
+ option.name.toLowerCase() === key && option.values.includes(value)
)
- );
+ );
- const variant = isAvailableForSale
- ? variantsById[isAvailableForSale.id]
- : undefined;
+ const isAvailableForSale = combinations.find((combination) =>
+ filtered.every(
+ ([key, value]) =>
+ combination[key] === value && combination.availableForSale
+ )
+ );
- const coreChargeOptions = [
- variant?.waiverAvailable && {
- label: 'Core Waiver',
- value: CORE_WAIVER,
- price: { amount: 0, currencyCode: variant?.price.currencyCode }
- },
- variant?.coreVariantId &&
- variant.coreCharge && {
- label: 'Core Charge',
- value: variant.coreVariantId,
- price: variant.coreCharge
- }
- ].filter(Boolean) as CoreChargeOption[];
+ const variant = isAvailableForSale
+ ? variantsById[isAvailableForSale.id]
+ : undefined;
- // preset the first core charge option if not set
- coreChargeOptions[0] &&
- optionSearchParams.set(CORE_VARIANT_ID_KEY, coreChargeOptions[0].value);
+ const coreChargeOptions = [
+ variant?.waiverAvailable && {
+ label: 'Core Waiver',
+ value: CORE_WAIVER,
+ price: { amount: 0, currencyCode: variant?.price.currencyCode }
+ },
+ variant?.coreVariantId &&
+ variant.coreCharge && {
+ label: 'Core Charge',
+ value: variant.coreVariantId,
+ price: variant.coreCharge
+ }
+ ].filter(Boolean) as CoreChargeOption[];
- const optionUrl = createUrl(pathname, optionSearchParams);
+ // preset the first core charge option if not set
+ coreChargeOptions[0] &&
+ optionSearchParams.set(CORE_VARIANT_ID_KEY, coreChargeOptions[0].value);
- // The option is active if it's in the url params.
- const isActive = searchParams.get(optionNameLowerCase) === value;
+ const optionUrl = createUrl(pathname, optionSearchParams);
- return (
-