-
Notifications
You must be signed in to change notification settings - Fork 21
Feat [Shopify]: Internationalization Support for Shopify Loaders and Queries #1371
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
Open
yuriassuncx
wants to merge
22
commits into
deco-cx:main
Choose a base branch
from
yuriassuncx:feat-shopify/inContext
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
5e586d0
feat: internationalization support for shopify loaders and queries
yuriassuncx 5cc3c6d
chore: files generated
yuriassuncx ce35c85
feat: exclude prop added to sitemap
yuriassuncx f0178dd
fix: new improvements suggested by coderrabit
yuriassuncx 0ae284a
refactor: improve code readability and maintainability across multiplβ¦
yuriassuncx 0220c31
fix: remove unnecessary countryCode variable from cart loader
yuriassuncx 1110e3a
Merge branch 'main' into feat-shopify/inContext
yuriassuncx 5f8bb0b
chore: remove unused Product import from loaders
yuriassuncx fff74a8
feat: update Cart and GetCart types to include buyerIdentity field
yuriassuncx 879386d
Merge branch 'deco-cx:main' into feat-shopify/inContext
yuriassuncx 23ac61e
feat: update Shopify API version to 2026-04 in GraphQL client endpoints
yuriassuncx 7b3310f
feat: update cache strategy and enhance cacheKey with language and coβ¦
yuriassuncx 07475f5
feat: enhance ProductList loader with improved error handling and logβ¦
yuriassuncx d69fb4f
feat: update ProductDetailsPage loader to use slug directly and improβ¦
yuriassuncx 079e1a6
feat: format GraphQL query variables for better readability in Producβ¦
yuriassuncx 6b4356f
feat: improve error logging in fetchSafe function to include responseβ¦
yuriassuncx 1dca706
feat: improve error handling in fetchSafe by logging response text onβ¦
yuriassuncx 614bc45
fix: ensure newline at end of file in fetch.ts
yuriassuncx dfb7401
feat: enhance CreateCart mutation to include languageCode and countryβ¦
yuriassuncx 22a54d4
feat: simplify CreateCart mutation by removing unnecessary variables β¦
yuriassuncx 8261a27
fix: correct cart ID handling in loader and ensure proper encoding inβ¦
yuriassuncx c9ff9c2
feat: enhance cache key generation by including metafields and sortinβ¦
yuriassuncx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,12 +3,14 @@ import { AppContext } from "../../shopify/mod.ts"; | |
| import { toProductPage } from "../../shopify/utils/transform.ts"; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Trailing numeric segments in product handles are always stripped and treated as SKU ids, which will break lookups for handles that legitimately end with numbers. Prompt for AI agents |
||
| import type { RequestURLParam } from "../../website/functions/requestToParam.ts"; | ||
| import { | ||
| CountryCode, | ||
| GetProductQuery, | ||
| GetProductQueryVariables, | ||
| HasMetafieldsMetafieldsArgs, | ||
| LanguageCode, | ||
| } from "../utils/storefront/storefront.graphql.gen.ts"; | ||
| import { GetProduct } from "../utils/storefront/queries.ts"; | ||
| import { Metafield } from "../utils/types.ts"; | ||
| import { LanguageContextArgs, Metafield } from "../utils/types.ts"; | ||
|
|
||
| export interface Props { | ||
| slug: RequestURLParam; | ||
|
|
@@ -17,6 +19,18 @@ export interface Props { | |
| * @description search for metafields | ||
| */ | ||
| metafields?: Metafield[]; | ||
| /** | ||
| * @title Language Code | ||
| * @description Language code for the storefront API | ||
| * @example "EN" for English, "FR" for French, etc. | ||
| */ | ||
| languageCode?: LanguageCode; | ||
| /** | ||
| * @title Country Code | ||
| * @description Country code for the storefront API | ||
| * @example "US" for United States, "FR" for France, etc. | ||
| */ | ||
| countryCode?: CountryCode; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -29,7 +43,7 @@ const loader = async ( | |
| ctx: AppContext, | ||
| ): Promise<ProductDetailsPage | null> => { | ||
| const { storefront } = ctx; | ||
| const { slug } = props; | ||
| const { slug, languageCode = "PT", countryCode = "BR" } = props; | ||
| const metafields = props.metafields || []; | ||
|
|
||
| const splitted = slug?.split("-"); | ||
|
|
@@ -39,9 +53,9 @@ const loader = async ( | |
|
|
||
| const data = await storefront.query< | ||
| GetProductQuery, | ||
| GetProductQueryVariables & HasMetafieldsMetafieldsArgs | ||
| GetProductQueryVariables & HasMetafieldsMetafieldsArgs & LanguageContextArgs | ||
| >({ | ||
| variables: { handle, identifiers: metafields }, | ||
| variables: { handle, identifiers: metafields, languageCode, countryCode }, | ||
| ...GetProduct, | ||
| }); | ||
|
|
||
|
|
@@ -52,15 +66,33 @@ const loader = async ( | |
| return toProductPage(data.product, new URL(_req.url), maybeSkuId); | ||
| }; | ||
|
|
||
| export const cache = "no-cache"; | ||
| export const cache = "stale-while-revalidate"; | ||
|
|
||
| export const cacheKey = (props: Props, req: Request): string => { | ||
| const { slug } = props; | ||
| const searchParams = new URLSearchParams({ | ||
| slug, | ||
| }); | ||
| const { slug, languageCode = "PT", countryCode = "BR", metafields } = props; | ||
|
|
||
| const searchParams = new URLSearchParams(); | ||
|
|
||
| // Core parameters | ||
| searchParams.append("slug", slug); | ||
| searchParams.append("languageCode", languageCode); | ||
| searchParams.append("countryCode", countryCode); | ||
|
|
||
| // Add metafields to cache key if they exist | ||
| if (metafields?.length) { | ||
| const metafieldsKey = metafields | ||
| .map((m) => `${m.namespace}.${m.key}`) | ||
| .sort() | ||
| .join(","); | ||
| searchParams.append("metafields", metafieldsKey); | ||
| } | ||
|
|
||
| // Sort parameters for consistent cache keys | ||
| searchParams.sort(); | ||
|
|
||
| const url = new URL(req.url); | ||
| url.search = searchParams.toString(); | ||
|
|
||
| return url.href; | ||
| }; | ||
|
|
||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.