diff --git a/app/[locale]/about/page.tsx b/app/[locale]/about/page.tsx index a1354a4a0..390b5f766 100644 --- a/app/[locale]/about/page.tsx +++ b/app/[locale]/about/page.tsx @@ -23,7 +23,7 @@ export default async function Page({ params }: { params: { locale?: SupportedLoc let cart; if (cartId) { - cart = await getCart(cartId); + cart = await getCart({ cartId, language: params?.locale?.toUpperCase() }); } const awardsPage = await getPage({ handle: 'awards', language: params?.locale?.toUpperCase() }); diff --git a/app/[locale]/bar/page.tsx b/app/[locale]/bar/page.tsx index 98fe0ea39..179501e0b 100644 --- a/app/[locale]/bar/page.tsx +++ b/app/[locale]/bar/page.tsx @@ -25,7 +25,7 @@ export default async function Page({ params }: { params: { locale?: SupportedLoc let cart; if (cartId) { - cart = await getCart(cartId); + cart = await getCart({ cartId, language: params?.locale?.toUpperCase() }); } return ( diff --git a/app/[locale]/company/page.tsx b/app/[locale]/company/page.tsx index ae9820f10..f9ffadcdf 100644 --- a/app/[locale]/company/page.tsx +++ b/app/[locale]/company/page.tsx @@ -25,7 +25,7 @@ export default async function Page({ params }: { params: { locale?: SupportedLoc let cart; if (cartId) { - cart = await getCart(cartId); + cart = await getCart({ cartId, language: params?.locale?.toUpperCase() }); } return ( diff --git a/app/[locale]/concept/page.tsx b/app/[locale]/concept/page.tsx index e23066ec4..4b9e062af 100644 --- a/app/[locale]/concept/page.tsx +++ b/app/[locale]/concept/page.tsx @@ -25,7 +25,7 @@ export default async function Page({ params }: { params: { locale?: SupportedLoc let cart; if (cartId) { - cart = await getCart(cartId); + cart = await getCart({ cartId, language: params?.locale?.toUpperCase() }); } return ( diff --git a/app/[locale]/disclosures/page.tsx b/app/[locale]/disclosures/page.tsx index 5e4d03468..dd370341a 100644 --- a/app/[locale]/disclosures/page.tsx +++ b/app/[locale]/disclosures/page.tsx @@ -29,7 +29,7 @@ export default async function DisclosuresPage({ let cart; if (cartId) { - cart = await getCart(cartId); + cart = await getCart({ cartId, language: locale?.toUpperCase() }); } return ( diff --git a/app/[locale]/page.tsx b/app/[locale]/page.tsx index 318b6768d..b3a64ccaa 100644 --- a/app/[locale]/page.tsx +++ b/app/[locale]/page.tsx @@ -45,7 +45,9 @@ export default async function HomePage({ let cart; if (cartId) { - cart = await getCart(cartId); + console.debug({ cartId }); + cart = await getCart({ cartId, language: locale?.toUpperCase() }); + console.debug({ cart }); } return ( diff --git a/app/[locale]/privacy/page.tsx b/app/[locale]/privacy/page.tsx index a45c66492..398e23dca 100644 --- a/app/[locale]/privacy/page.tsx +++ b/app/[locale]/privacy/page.tsx @@ -29,7 +29,7 @@ export default async function PrivacyPage({ let cart; if (cartId) { - cart = await getCart(cartId); + cart = await getCart({ cartId, language: locale?.toUpperCase() }); } return ( diff --git a/app/[locale]/product/[handle]/layout.tsx b/app/[locale]/product/[handle]/layout.tsx index a9aebb272..489b7cc69 100644 --- a/app/[locale]/product/[handle]/layout.tsx +++ b/app/[locale]/product/[handle]/layout.tsx @@ -28,7 +28,7 @@ export default async function ProductLayout({ let cart; if (cartId) { - cart = await getCart(cartId); + cart = await getCart({ cartId, language: locale?.toUpperCase() }); } return ( diff --git a/app/[locale]/product/[handle]/page.tsx b/app/[locale]/product/[handle]/page.tsx index 861e60bfd..76350f217 100644 --- a/app/[locale]/product/[handle]/page.tsx +++ b/app/[locale]/product/[handle]/page.tsx @@ -30,8 +30,6 @@ export async function generateMetadata({ language: params?.locale?.toUpperCase() }); - console.debug({ product }); - if (!product) return notFound(); const { url, width, height, altText: alt } = product.featuredImage || {}; diff --git a/app/[locale]/products/page.tsx b/app/[locale]/products/page.tsx index cd18759b1..361cf3d3f 100644 --- a/app/[locale]/products/page.tsx +++ b/app/[locale]/products/page.tsx @@ -29,7 +29,7 @@ export default async function ProductPage({ let cart; if (cartId) { - cart = await getCart(cartId); + cart = await getCart({ cartId, language: locale?.toUpperCase() }); } return ( diff --git a/app/[locale]/shop-list/page.tsx b/app/[locale]/shop-list/page.tsx index e44ad1929..5862f64f2 100644 --- a/app/[locale]/shop-list/page.tsx +++ b/app/[locale]/shop-list/page.tsx @@ -39,7 +39,7 @@ export default async function Page({ params }: { params: { locale?: SupportedLoc let cart; if (cartId) { - cart = await getCart(cartId); + cart = await getCart({ cartId, language: params?.locale?.toUpperCase() }); } const page = await getPage({ handle: 'shop-list', language: params?.locale?.toUpperCase() }); diff --git a/app/[locale]/stories/[handle]/layout.tsx b/app/[locale]/stories/[handle]/layout.tsx index 928cb9df9..cd103bd50 100644 --- a/app/[locale]/stories/[handle]/layout.tsx +++ b/app/[locale]/stories/[handle]/layout.tsx @@ -28,7 +28,7 @@ export default async function BlogLayout({ let cart; if (cartId) { - cart = await getCart(cartId); + cart = await getCart({ cartId, language: locale?.toUpperCase() }); } return ( diff --git a/app/[locale]/stories/page.tsx b/app/[locale]/stories/page.tsx index ac707eb65..9657b0679 100644 --- a/app/[locale]/stories/page.tsx +++ b/app/[locale]/stories/page.tsx @@ -28,7 +28,7 @@ export default async function StoriesPage({ let cart; if (cartId) { - cart = await getCart(cartId); + cart = await getCart({ cartId, language: locale?.toUpperCase() }); } return ( diff --git a/app/[locale]/terms/page.tsx b/app/[locale]/terms/page.tsx index 123c2e28a..cedcc1a5c 100644 --- a/app/[locale]/terms/page.tsx +++ b/app/[locale]/terms/page.tsx @@ -27,7 +27,7 @@ export default async function TermsPage({ let cart; if (cartId) { - cart = await getCart(cartId); + cart = await getCart({ cartId, language: locale?.toUpperCase() }); } return ( diff --git a/components/cart/actions.ts b/components/cart/actions.ts index 40a74789d..f91dbbe98 100644 --- a/components/cart/actions.ts +++ b/components/cart/actions.ts @@ -1,14 +1,21 @@ 'use server'; +import { SupportedLocale } from 'components/layout/navbar/language-control'; import { addToCart, createCart, getCart, removeFromCart, updateCart } from 'lib/shopify'; import { cookies } from 'next/headers'; -export const addItem = async (variantId: string | undefined): Promise => { +export const addItem = async ({ + variantId, + locale +}: { + variantId: string | undefined; + locale?: string; +}): Promise => { let cartId = cookies().get('cartId')?.value; let cart; if (cartId) { - cart = await getCart(cartId); + cart = await getCart({ cartId, language: locale?.toUpperCase() }); } if (!cartId || !cart) { @@ -30,16 +37,18 @@ export const addItem = async (variantId: string | undefined): Promise => { let cartId = cookies().get('cartId')?.value; let cart; if (cartId) { - cart = await getCart(cartId); + cart = await getCart({ cartId, language: locale?.toUpperCase() }); } if (!cartId || !cart) { diff --git a/components/cart/add-many-to-cart.tsx b/components/cart/add-many-to-cart.tsx index 6b375904f..5ab28d6bd 100644 --- a/components/cart/add-many-to-cart.tsx +++ b/components/cart/add-many-to-cart.tsx @@ -2,9 +2,10 @@ import { ChevronDownIcon, ChevronUpIcon } from '@heroicons/react/24/outline'; import clsx from 'clsx'; +import { SupportedLocale } from 'components/layout/navbar/language-control'; import LoadingDots from 'components/loading-dots'; import { ProductVariant } from 'lib/shopify/types'; -import { useTranslations } from 'next-intl'; +import { useLocale, useTranslations } from 'next-intl'; import { useRouter, useSearchParams } from 'next/navigation'; import { useState, useTransition } from 'react'; import { addItems } from './actions'; @@ -20,6 +21,7 @@ export function AddManyToCart({ }) { const router = useRouter(); const searchParams = useSearchParams(); + const locale = useLocale(); const t = useTranslations('Index'); const [currentQuantity, setCurrentQuantity] = useState(quantity); @@ -83,7 +85,8 @@ export function AddManyToCart({ startTransition(async () => { const error = await addItems({ variantId: selectedVariantId, - quantity: currentQuantity + quantity: currentQuantity, + locale: locale as SupportedLocale }); if (error) { diff --git a/components/cart/index.tsx b/components/cart/index.tsx index 3e250ba93..3ed3c037d 100644 --- a/components/cart/index.tsx +++ b/components/cart/index.tsx @@ -1,13 +1,14 @@ +import { SupportedLocale } from 'components/layout/navbar/language-control'; import { getCart } from 'lib/shopify'; import { cookies } from 'next/headers'; import CartModal from './modal'; -export default async function Cart() { +export default async function Cart({ locale }: { locale?: SupportedLocale }) { const cartId = cookies().get('cartId')?.value; let cart; if (cartId) { - cart = await getCart(cartId); + cart = await getCart({ cartId, language: locale?.toUpperCase() }); } return ; diff --git a/lib/shopify/queries/cart.ts b/lib/shopify/queries/cart.ts index 044e47f66..f26745d50 100644 --- a/lib/shopify/queries/cart.ts +++ b/lib/shopify/queries/cart.ts @@ -1,7 +1,8 @@ import cartFragment from '../fragments/cart'; export const getCartQuery = /* GraphQL */ ` - query getCart($cartId: ID!) { + query getCart($cartId: ID!, $country: CountryCode, $language: LanguageCode) + @inContext(country: $country, language: $language) { cart(id: $cartId) { ...cart } diff --git a/lib/shopify/types.ts b/lib/shopify/types.ts index cd7696c85..caec6e4ae 100644 --- a/lib/shopify/types.ts +++ b/lib/shopify/types.ts @@ -176,6 +176,8 @@ export type ShopifyCartOperation = { }; variables: { cartId: string; + language?: string; + country?: string; }; };