fix: set checkout languageCode to ensure emails are sent in correct language
- Add CHECKOUT_LANGUAGE_CODE_UPDATE mutation to update checkout language - Call language code update before completing checkout - Language code (SR, EN, DE, FR) is now set on checkout before order creation - This ensures order confirmation emails are sent in the customer's language - Update step numbering in checkout flow (now 6 steps total)
This commit is contained in:
@@ -18,6 +18,8 @@ import {
|
|||||||
CHECKOUT_EMAIL_UPDATE,
|
CHECKOUT_EMAIL_UPDATE,
|
||||||
CHECKOUT_METADATA_UPDATE,
|
CHECKOUT_METADATA_UPDATE,
|
||||||
CHECKOUT_SHIPPING_METHOD_UPDATE,
|
CHECKOUT_SHIPPING_METHOD_UPDATE,
|
||||||
|
ORDER_METADATA_UPDATE,
|
||||||
|
CHECKOUT_LANGUAGE_CODE_UPDATE,
|
||||||
} from "@/lib/saleor/mutations/Checkout";
|
} from "@/lib/saleor/mutations/Checkout";
|
||||||
import { PaymentSection } from "./components/PaymentSection";
|
import { PaymentSection } from "./components/PaymentSection";
|
||||||
import { DEFAULT_PAYMENT_METHOD } from "@/lib/config/paymentMethods";
|
import { DEFAULT_PAYMENT_METHOD } from "@/lib/config/paymentMethods";
|
||||||
@@ -313,7 +315,17 @@ export default function CheckoutPage() {
|
|||||||
}
|
}
|
||||||
console.log("Step 1: Email updated successfully");
|
console.log("Step 1: Email updated successfully");
|
||||||
|
|
||||||
console.log("Step 2: Updating billing address...");
|
console.log("Step 2: Updating language code...");
|
||||||
|
await saleorClient.mutate({
|
||||||
|
mutation: CHECKOUT_LANGUAGE_CODE_UPDATE,
|
||||||
|
variables: {
|
||||||
|
checkoutId: checkout.id,
|
||||||
|
languageCode: locale.toUpperCase(),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
console.log("Step 2: Language code updated to", locale.toUpperCase());
|
||||||
|
|
||||||
|
console.log("Step 3: Updating billing address...");
|
||||||
const billingResult = await saleorClient.mutate<BillingAddressUpdateResponse>({
|
const billingResult = await saleorClient.mutate<BillingAddressUpdateResponse>({
|
||||||
mutation: CHECKOUT_BILLING_ADDRESS_UPDATE,
|
mutation: CHECKOUT_BILLING_ADDRESS_UPDATE,
|
||||||
variables: {
|
variables: {
|
||||||
@@ -334,9 +346,9 @@ export default function CheckoutPage() {
|
|||||||
if (billingResult.data?.checkoutBillingAddressUpdate?.errors && billingResult.data.checkoutBillingAddressUpdate.errors.length > 0) {
|
if (billingResult.data?.checkoutBillingAddressUpdate?.errors && billingResult.data.checkoutBillingAddressUpdate.errors.length > 0) {
|
||||||
throw new Error(`Billing address update failed: ${billingResult.data.checkoutBillingAddressUpdate.errors[0].message}`);
|
throw new Error(`Billing address update failed: ${billingResult.data.checkoutBillingAddressUpdate.errors[0].message}`);
|
||||||
}
|
}
|
||||||
console.log("Step 2: Billing address updated successfully");
|
console.log("Step 3: Billing address updated successfully");
|
||||||
|
|
||||||
console.log("Step 3: Setting shipping method...");
|
console.log("Step 4: Setting shipping method...");
|
||||||
const shippingMethodResult = await saleorClient.mutate<ShippingMethodUpdateResponse>({
|
const shippingMethodResult = await saleorClient.mutate<ShippingMethodUpdateResponse>({
|
||||||
mutation: CHECKOUT_SHIPPING_METHOD_UPDATE,
|
mutation: CHECKOUT_SHIPPING_METHOD_UPDATE,
|
||||||
variables: {
|
variables: {
|
||||||
@@ -348,9 +360,9 @@ export default function CheckoutPage() {
|
|||||||
if (shippingMethodResult.data?.checkoutShippingMethodUpdate?.errors && shippingMethodResult.data.checkoutShippingMethodUpdate.errors.length > 0) {
|
if (shippingMethodResult.data?.checkoutShippingMethodUpdate?.errors && shippingMethodResult.data.checkoutShippingMethodUpdate.errors.length > 0) {
|
||||||
throw new Error(`Shipping method update failed: ${shippingMethodResult.data.checkoutShippingMethodUpdate.errors[0].message}`);
|
throw new Error(`Shipping method update failed: ${shippingMethodResult.data.checkoutShippingMethodUpdate.errors[0].message}`);
|
||||||
}
|
}
|
||||||
console.log("Step 3: Shipping method set successfully");
|
console.log("Step 4: Shipping method set successfully");
|
||||||
|
|
||||||
console.log("Step 4: Saving metadata...");
|
console.log("Step 5: Saving metadata...");
|
||||||
const metadataResult = await saleorClient.mutate<MetadataUpdateResponse>({
|
const metadataResult = await saleorClient.mutate<MetadataUpdateResponse>({
|
||||||
mutation: CHECKOUT_METADATA_UPDATE,
|
mutation: CHECKOUT_METADATA_UPDATE,
|
||||||
variables: {
|
variables: {
|
||||||
@@ -367,10 +379,10 @@ export default function CheckoutPage() {
|
|||||||
if (metadataResult.data?.updateMetadata?.errors && metadataResult.data.updateMetadata.errors.length > 0) {
|
if (metadataResult.data?.updateMetadata?.errors && metadataResult.data.updateMetadata.errors.length > 0) {
|
||||||
console.warn("Failed to save phone metadata:", metadataResult.data.updateMetadata.errors);
|
console.warn("Failed to save phone metadata:", metadataResult.data.updateMetadata.errors);
|
||||||
} else {
|
} else {
|
||||||
console.log("Step 4: Phone number saved successfully");
|
console.log("Step 5: Phone number saved successfully");
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("Step 5: Completing checkout...");
|
console.log("Step 6: Completing checkout...");
|
||||||
const completeResult = await saleorClient.mutate<CheckoutCompleteResponse>({
|
const completeResult = await saleorClient.mutate<CheckoutCompleteResponse>({
|
||||||
mutation: CHECKOUT_COMPLETE,
|
mutation: CHECKOUT_COMPLETE,
|
||||||
variables: {
|
variables: {
|
||||||
|
|||||||
@@ -173,3 +173,40 @@ export const CHECKOUT_METADATA_UPDATE = gql`
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
export const ORDER_METADATA_UPDATE = gql`
|
||||||
|
mutation OrderMetadataUpdate($orderId: ID!, $metadata: [MetadataInput!]!) {
|
||||||
|
updateMetadata(id: $orderId, input: $metadata) {
|
||||||
|
item {
|
||||||
|
... on Order {
|
||||||
|
id
|
||||||
|
metadata {
|
||||||
|
key
|
||||||
|
value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
errors {
|
||||||
|
field
|
||||||
|
message
|
||||||
|
code
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
export const CHECKOUT_LANGUAGE_CODE_UPDATE = gql`
|
||||||
|
mutation CheckoutLanguageCodeUpdate($checkoutId: ID!, $languageCode: LanguageCodeEnum!) {
|
||||||
|
checkoutLanguageCodeUpdate(checkoutId: $checkoutId, languageCode: $languageCode) {
|
||||||
|
checkout {
|
||||||
|
id
|
||||||
|
languageCode
|
||||||
|
}
|
||||||
|
errors {
|
||||||
|
field
|
||||||
|
message
|
||||||
|
code
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|||||||
Reference in New Issue
Block a user