@@ -2,17 +2,36 @@ import { AppContext } from "../mod.ts";
2
2
import { getCartCookie , setCartCookie } from "../utils/cart.ts" ;
3
3
import { CreateCart , GetCart } from "../utils/storefront/queries.ts" ;
4
4
import {
5
+ CountryCode ,
5
6
CreateCartMutation ,
6
7
CreateCartMutationVariables ,
7
8
GetCartQuery ,
8
9
GetCartQueryVariables ,
10
+ LanguageCode ,
9
11
} 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
+ }
10
28
11
29
const loader = async (
12
- _props : unknown ,
30
+ props : Props ,
13
31
req : Request ,
14
32
ctx : AppContext ,
15
33
) : Promise < GetCartQuery [ "cart" ] > => {
34
+ const { languageCode = "PT" , countryCode = "BR" } = props ;
16
35
const { storefront } = ctx ;
17
36
const maybeCartId = getCartCookie ( req . headers ) ;
18
37
@@ -25,8 +44,11 @@ const loader = async (
25
44
throw new Error ( "Missing cart id" ) ;
26
45
}
27
46
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 } ,
30
52
...GetCart ,
31
53
} ) . then ( ( data ) => data . cart ) ;
32
54
0 commit comments