Search for a command to run...
In this guide, you'll learn how to enable the storefront's built-in DaData address autocomplete for checkout, or add a provider of your own for another country or service.
Address input on the checkout's address step is a pluggable provider, not a fixed set of fields. The storefront ships one real provider, DaData for Russian addresses, plus a plain address field as the fallback and a manual entry mode the buyer can switch to at any point.
reads the active provider from an environment variable and switches on it:
src/modules/common/components/address-autocomplete/index.tsx1const renderAutocomplete = () => {2 switch (true) {3 case isDaData(addressAutocompleteProvider):4 return <DaDataAddressInput {...props} />5 default:6 return <PlainAddressInput {...props} />7 }8}
and both come from . Any value other than , including an unset variable, falls through to (), which renders a single address field with no autocomplete at all.
Whichever provider is active, also renders a checkbox that lets the visitor switch to manual entry immediately. The checkbox swaps the provider for , four plain inputs for address, postal code, city, and province. As a result, autocomplete never blocks someone whose address doesn't match what the provider expects.
Set two environment variables in :
apps/storefront/.env.local1NEXT_PUBLIC_ADDRESS_AUTOCOMPLETE_PROVIDER=dadata2NEXT_PUBLIC_ADDRESS_AUTOCOMPLETE_PROVIDER_API_KEY=
Get the API key from your DaData account. () passes it directly to 's component, which only suggests Russian addresses.
Every provider component takes the same props, in, out:
src/modules/common/components/address-autocomplete/types.ts1export type AddressFields = {2 address_1: string3 postal_code: string4 city: string5 province: string6}78export type AddressAutocompleteProps = {9 values: AddressFields10 onChange: (fields: AddressFields) => void11 required?: boolean12}
To add a provider for another country or service:
You can model a new provider's props and calls on , a working, minimal example. It doesn't call any external API itself.