'use client'; import Price from 'components/price'; import { CORE_VARIANT_ID_KEY, CORE_WAIVER } from 'lib/constants'; import { CoreChargeOption, ProductVariant } from 'lib/shopify/types'; import { cn, createUrl } from 'lib/utils'; import { usePathname, useRouter, useSearchParams } from 'next/navigation'; type CoreChargeProps = { variants: ProductVariant[]; }; const CoreCharge = ({ variants }: CoreChargeProps) => { const searchParams = useSearchParams(); const pathname = usePathname(); const router = useRouter(); const optionSearchParams = new URLSearchParams(searchParams); const coreVariantIdSearchParam = optionSearchParams.get(CORE_VARIANT_ID_KEY); const variant = variants.find((variant: ProductVariant) => variant.selectedOptions.every( (option) => option.value === optionSearchParams.get(option.name.toLowerCase()) ) ); const { coreCharge, waiverAvailable, coreVariantId } = variant ?? {}; const handleSelectCoreChargeOption = (coreVariantId: string) => { optionSearchParams.set(CORE_VARIANT_ID_KEY, coreVariantId); const newUrl = createUrl(pathname, optionSearchParams); router.replace(newUrl, { scroll: false }); }; const coreChargeOptions = [ waiverAvailable && { label: 'Core Waiver', value: CORE_WAIVER, price: { amount: 0, currencyCode: variant?.price.currencyCode } }, coreVariantId && coreCharge && { label: 'Core Charge', value: coreVariantId, price: coreCharge } ].filter(Boolean) as CoreChargeOption[]; if (!optionSearchParams.has(CORE_VARIANT_ID_KEY) && coreChargeOptions.length > 0) { handleSelectCoreChargeOption((coreChargeOptions[0] as CoreChargeOption).value); } return (
The core charge is a refundable deposit that is added to the price of the part. This charge ensures that the old, worn-out part is returned to the supplier for proper disposal or recycling. When you return the old part, you'll receive a refund of the core charge.