Skip to content

Commit

Permalink
feat: add vtex telephone (#1021)
Browse files Browse the repository at this point in the history
  • Loading branch information
IncognitaDev authored Feb 25, 2025
1 parent 1b93509 commit eb78dca
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 2 additions & 0 deletions commerce/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,8 @@ export interface Person extends Omit<Thing, "@type"> {
image?: ImageObject[] | null;
/** The Tax / Fiscal ID of the organization or person, e.g. the TIN in the US or the CIF/NIF in Spain. */
taxID?: string;
/** The telephone number. */
telephone?: string;
}
// NON SCHEMA.ORG Compliant. Should be removed ASAP
export interface Author extends Omit<Thing, "@type"> {
Expand Down
13 changes: 9 additions & 4 deletions vtex/loaders/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ interface User {
profilePicture?: string;
gender?: string;
document?: string;
homePhone?: string;
businessPhone?: string;
}

async function loader(
Expand All @@ -26,7 +28,7 @@ async function loader(
}

const query =
"query getUserProfile { profile { id userId email firstName lastName profilePicture gender document }}";
"query getUserProfile { profile { id userId email firstName lastName profilePicture gender document homePhone businessPhone }}";

try {
const { profile: user } = await io.query<{ profile: User }, null>(
Expand All @@ -40,9 +42,12 @@ async function loader(
givenName: user.firstName,
familyName: user.lastName,
taxID: user?.document?.replace(/[^\d]/g, ""),
gender: user.gender === "f"
? "https://schema.org/Female"
: "https://schema.org/Male",
gender: user.gender
? user.gender === "f"
? "https://schema.org/Female"
: "https://schema.org/Male"
: undefined,
telephone: user.homePhone ?? user.businessPhone,
};
} catch (_) {
return null;
Expand Down

0 comments on commit eb78dca

Please sign in to comment.