From cfdfdd4973bfd8721eeeda5f6b07c968deb30099 Mon Sep 17 00:00:00 2001 From: Bret Little Date: Mon, 5 Jun 2023 18:01:08 -0400 Subject: [PATCH 1/3] Make `` use country code from `` --- .changeset/chilly-dogs-sneeze.md | 5 +++++ .../src/components/CartProvider/CartProvider.client.tsx | 9 ++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 .changeset/chilly-dogs-sneeze.md diff --git a/.changeset/chilly-dogs-sneeze.md b/.changeset/chilly-dogs-sneeze.md new file mode 100644 index 0000000000..2539a19369 --- /dev/null +++ b/.changeset/chilly-dogs-sneeze.md @@ -0,0 +1,5 @@ +--- +'@shopify/hydrogen': patch +--- + +Fix the `` to by default pull localization from ``. You can still override the countryCode by passing a prop directly to ``. Resolves https://github.com/Shopify/hydrogen/issues/622 diff --git a/packages/hydrogen/src/components/CartProvider/CartProvider.client.tsx b/packages/hydrogen/src/components/CartProvider/CartProvider.client.tsx index 4a9fda40ff..6d840fbac8 100644 --- a/packages/hydrogen/src/components/CartProvider/CartProvider.client.tsx +++ b/packages/hydrogen/src/components/CartProvider/CartProvider.client.tsx @@ -34,6 +34,7 @@ import {CartNoteUpdateMutationVariables} from './graphql/CartNoteUpdateMutation. import {useCartAPIStateMachine} from './useCartAPIStateMachine.client.js'; import {CART_ID_STORAGE_KEY} from './constants.js'; import {ClientAnalytics} from '../../foundation/Analytics/ClientAnalytics.js'; +import {useLocalization, useShop} from '../../client.js'; export function CartProvider({ children, @@ -57,7 +58,7 @@ export function CartProvider({ data: cart, cartFragment = defaultCartFragment, customerAccessToken, - countryCode = CountryCode.Us, + countryCode, }: { /** Any `ReactNode` elements. */ children: React.ReactNode; @@ -104,6 +105,12 @@ export function CartProvider({ /** The ISO country code for i18n. */ countryCode?: CountryCode; }) { + const {country} = useLocalization(); + + countryCode = ( + (countryCode as string) ?? country.isoCode + ).toUpperCase() as CountryCode; + if (countryCode) countryCode = countryCode.toUpperCase() as CountryCode; const [prevCountryCode, setPrevCountryCode] = useState(countryCode); const [prevCustomerAccessToken, setPrevCustomerAccessToken] = From aa418c1118d48c028a464a866843812469f6f332 Mon Sep 17 00:00:00 2001 From: Bret Little Date: Mon, 5 Jun 2023 18:05:11 -0400 Subject: [PATCH 2/3] Oops I did it again --- .../src/components/CartProvider/CartProvider.client.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/hydrogen/src/components/CartProvider/CartProvider.client.tsx b/packages/hydrogen/src/components/CartProvider/CartProvider.client.tsx index 6d840fbac8..29f0bb84b2 100644 --- a/packages/hydrogen/src/components/CartProvider/CartProvider.client.tsx +++ b/packages/hydrogen/src/components/CartProvider/CartProvider.client.tsx @@ -34,7 +34,7 @@ import {CartNoteUpdateMutationVariables} from './graphql/CartNoteUpdateMutation. import {useCartAPIStateMachine} from './useCartAPIStateMachine.client.js'; import {CART_ID_STORAGE_KEY} from './constants.js'; import {ClientAnalytics} from '../../foundation/Analytics/ClientAnalytics.js'; -import {useLocalization, useShop} from '../../client.js'; +import {useLocalization} from '../../client.js'; export function CartProvider({ children, From 3df0a2c68da5351ac23005a8cd9e94479ab0ce9c Mon Sep 17 00:00:00 2001 From: Bret Little Date: Mon, 5 Jun 2023 18:27:17 -0400 Subject: [PATCH 3/3] Fixy --- .../src/components/CartProvider/CartProvider.client.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/hydrogen/src/components/CartProvider/CartProvider.client.tsx b/packages/hydrogen/src/components/CartProvider/CartProvider.client.tsx index 29f0bb84b2..801acadf99 100644 --- a/packages/hydrogen/src/components/CartProvider/CartProvider.client.tsx +++ b/packages/hydrogen/src/components/CartProvider/CartProvider.client.tsx @@ -34,7 +34,7 @@ import {CartNoteUpdateMutationVariables} from './graphql/CartNoteUpdateMutation. import {useCartAPIStateMachine} from './useCartAPIStateMachine.client.js'; import {CART_ID_STORAGE_KEY} from './constants.js'; import {ClientAnalytics} from '../../foundation/Analytics/ClientAnalytics.js'; -import {useLocalization} from '../../client.js'; +import {useLocalization} from '../../hooks/useLocalization/useLocalization.js'; export function CartProvider({ children,