Skip to content

Commit 83ee56c

Browse files
committed
feat: update GetCart and ListProducts queries to include languageCode and countryCode for localization
1 parent 9e7aac5 commit 83ee56c

File tree

2 files changed

+240
-167
lines changed

2 files changed

+240
-167
lines changed

shopify/loaders/cart.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,36 @@ import { AppContext } from "../mod.ts";
22
import { getCartCookie, setCartCookie } from "../utils/cart.ts";
33
import { CreateCart, GetCart } from "../utils/storefront/queries.ts";
44
import {
5+
CountryCode,
56
CreateCartMutation,
67
CreateCartMutationVariables,
78
GetCartQuery,
89
GetCartQueryVariables,
10+
LanguageCode,
911
} from "../utils/storefront/storefront.graphql.gen.ts";
12+
import { LanguageContextArgs } from "../utils/types.ts";
13+
14+
export interface Props {
15+
/**
16+
* @title Language Code
17+
* @description Language code for the storefront API
18+
* @example "EN" for English, "FR" for French, etc.
19+
*/
20+
languageCode?: LanguageCode;
21+
/**
22+
* @title Country Code
23+
* @description Country code for the storefront API
24+
* @example "US" for United States, "FR" for France, etc.
25+
*/
26+
countryCode?: CountryCode;
27+
}
1028

1129
const loader = async (
12-
_props: unknown,
30+
props: Props,
1331
req: Request,
1432
ctx: AppContext,
1533
): Promise<GetCartQuery["cart"]> => {
34+
const { languageCode = "PT", countryCode = "BR" } = props;
1635
const { storefront } = ctx;
1736
const maybeCartId = getCartCookie(req.headers);
1837

@@ -25,8 +44,11 @@ const loader = async (
2544
throw new Error("Missing cart id");
2645
}
2746

28-
const cart = await storefront.query<GetCartQuery, GetCartQueryVariables>({
29-
variables: { id: decodeURIComponent(cartId) },
47+
const cart = await storefront.query<
48+
GetCartQuery,
49+
GetCartQueryVariables & LanguageContextArgs
50+
>({
51+
variables: { id: decodeURIComponent(cartId), languageCode, countryCode },
3052
...GetCart,
3153
}).then((data) => data.cart);
3254

0 commit comments

Comments
 (0)