feat: set checkout languageCode based on user locale
Some checks failed
Build and Deploy / build (push) Has been cancelled

- Add languageCode to checkout store state
- Add setLanguageCode action to store
- Pass languageCode when creating checkout
- Header component sets language code from useLocale hook
- Enables multi-language order confirmation emails
This commit is contained in:
Unchained
2026-03-28 12:31:34 +02:00
parent ee574cb736
commit 5ec0e6c92c
2 changed files with 24 additions and 11 deletions

View File

@@ -5,7 +5,7 @@ import Link from "next/link";
import Image from "next/image";
import { usePathname } from "next/navigation";
import { AnimatePresence, motion } from "framer-motion";
import { useTranslations } from "next-intl";
import { useTranslations, useLocale } from "next-intl";
import { useSaleorCheckoutStore } from "@/stores/saleorCheckoutStore";
import { User, ShoppingBag, Menu, X, Globe } from "lucide-react";
import CartDrawer from "@/components/cart/CartDrawer";
@@ -16,14 +16,15 @@ interface HeaderProps {
locale?: string;
}
export default function Header({ locale = "sr" }: HeaderProps) {
export default function Header({ locale: propLocale = "sr" }: HeaderProps) {
const t = useTranslations("Header");
const pathname = usePathname();
const dropdownRef = useRef<HTMLDivElement>(null);
const [mobileMenuOpen, setMobileMenuOpen] = useState(false);
const [scrolled, setScrolled] = useState(false);
const [langDropdownOpen, setLangDropdownOpen] = useState(false);
const { getLineCount, toggleCart, initCheckout } = useSaleorCheckoutStore();
const { getLineCount, toggleCart, initCheckout, setLanguageCode } = useSaleorCheckoutStore();
const locale = useLocale();
const itemCount = getLineCount();
const currentLocale = isValidLocale(locale) ? LOCALE_CONFIG[locale] : LOCALE_CONFIG.sr;
@@ -58,6 +59,13 @@ export default function Header({ locale = "sr" }: HeaderProps) {
initCheckout();
}, [initCheckout]);
// Set language code for checkout based on current locale
useEffect(() => {
if (locale) {
setLanguageCode(locale);
}
}, [locale, setLanguageCode]);
useEffect(() => {
const handleScroll = () => {
setScrolled(window.scrollY > 50);