Skip to content

Cookbook recipe: markets #2869

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

Conversation

ruggishop
Copy link
Contributor

WHY are these changes introduced?

Fixes #0000

WHAT is this pull request doing?

HOW to test your changes?

Post-merge steps

Checklist

  • I've read the Contributing Guidelines
  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've added a changeset if this PR contains user-facing or noteworthy changes
  • I've added tests to cover my changes
  • I've added or updated the documentation

Copy link
Contributor

shopify bot commented Apr 17, 2025

Oxygen deployed a preview of your feat/cookbook-recipe-markets branch. Details:

Storefront Status Preview link Deployment details Last update (UTC)
third-party-queries-caching ✅ Successful (Logs) Preview deployment Inspect deployment April 17, 2025 5:03 PM
metaobjects ✅ Successful (Logs) Preview deployment Inspect deployment April 17, 2025 5:04 PM
classic-remix ✅ Successful (Logs) Preview deployment Inspect deployment April 17, 2025 5:03 PM
Skeleton (skeleton.hydrogen.shop) ✅ Successful (Logs) Preview deployment Inspect deployment April 17, 2025 5:03 PM
custom-cart-method ✅ Successful (Logs) Preview deployment Inspect deployment April 17, 2025 5:03 PM

Learn more about Hydrogen's GitHub integration.

Comment on lines +105 to +106
- i18n: {language: 'EN', country: 'US'},
+ i18n,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something to remember, almost no new sites will have this code, because how they select markets changes it.

Comment on lines +139 to +145
+ if (
+ args.params.locale != null &&
+ args.params.locale.length !== 2 &&
+ countries[args.params.locale] == null
+ ) {
+ throw new Response(null, {status: 404});
+ }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this happen sooner, inside getLocaleFromRequest?

>
- <PageLayout {...data}>{children}</PageLayout>
+ <PageLayout
+ key={`${data.selectedLocale.language}-${data.selectedLocale.country}`}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

Comment on lines +9 to +48
export function CountrySelector() {
const [root] = useMatches();
const selectedLocale = (root.data as RootData).selectedLocale;
const {pathname, search} = useLocation();

const [countries, setCountries] = useState<Record<string, Locale> | null>(
null,
);

// Get available countries list
useEffect(() => {
fetch('/api/countries')
.then((res) => res.json())
.then((data) => setCountries(data as Countries));
}, []);

const strippedPathname =
selectedLocale.pathPrefix != null
? pathname.replace(selectedLocale.pathPrefix, '')
: pathname;

const [open, setOpen] = useState(false);
const toggleOpen = useCallback(() => setOpen((open) => !open), []);

return (
<div>
<button onClick={toggleOpen}>{selectedLocale.label}</button>
<div style={{position: 'relative'}}>
{open && countries != null && (
<CountryPicker
countries={countries}
selectedLocale={selectedLocale}
strippedPathname={strippedPathname}
search={search}
/>
)}
</div>
</div>
);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me this is overly complex for just getting people started. Even the /countries data route. If you only have 3 locales, why do you need to make this dedicated resource route?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to use a native popover or dialog element if we end up with this sorta UX.

});
}

const protocol = process.env.NODE_ENV === 'development' ? 'http' : 'https';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we can make this assumption. You can host an app for local dev through a tunnel with --customer-account-push__unstable, which will be on https

Comment on lines +44 to +52
// Update cart buyer's country code if there is a cart id
if (cartId) {
await updateCartBuyerIdentity(context, {
cartId,
buyerIdentity: {
countryCode,
},
});
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tested this flow? I can't get the cart to show localized prices at all.

Comment on lines +112 to +122
const PRODUCT_HANDLE_QUERY = `#graphql
query ProductHandle(
$id: ID!
$country: CountryCode
$language: LanguageCode
) @inContext(country: $country, language: $language) {
product(id: $id) {
handle
}
}
` as const;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this is old

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants