Skip to content

Commit

Permalink
Merge branch 'main' into feat/myaccountvtex
Browse files Browse the repository at this point in the history
  • Loading branch information
soutofernando committed Dec 23, 2024
2 parents a1a55f8 + b03f5ca commit c8dc4b1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
26 changes: 26 additions & 0 deletions vtex/utils/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import type {
LegacyProduct as LegacyProductVTEX,
OrderForm,
PageType as PageTypeVTEX,
PickupHolidays,
PickupPoint,
Product as ProductVTEX,
ProductInventoryData,
Expand Down Expand Up @@ -1120,6 +1121,23 @@ function toHoursSpecification(hours: Hours): OpeningHoursSpecification {
};
}

function toSpecialHoursSpecification(
holiday: PickupHolidays,
): OpeningHoursSpecification {
const dateHoliday = new Date(holiday.date ?? "");
// VTEX provide date in ISO format, at 00h on the day
const validThrough = dateHoliday.setDate(dateHoliday.getDate() + 1)
.toString();

return {
"@type": "OpeningHoursSpecification",
opens: holiday.hourBegin,
closes: holiday.hourEnd,
validFrom: holiday.date,
validThrough,
};
}

function isPickupPointVCS(
pickupPoint: PickupPoint | PickupPointVCS,
): pickupPoint is PickupPointVCS {
Expand All @@ -1135,12 +1153,16 @@ export function toPlace(
latitude,
longitude,
openingHoursSpecification,
specialOpeningHoursSpecification,
} = isPickupPointVCS(pickupPoint)
? {
name: pickupPoint.name,
country: pickupPoint.address?.country?.acronym,
latitude: pickupPoint.address?.location?.latitude,
longitude: pickupPoint.address?.location?.longitude,
specialOpeningHoursSpecification: pickupPoint.pickupHolidays?.map(
toSpecialHoursSpecification,
),
openingHoursSpecification: pickupPoint.businessHours?.map(
toHoursSpecification,
),
Expand All @@ -1150,6 +1172,9 @@ export function toPlace(
country: pickupPoint.address?.country,
latitude: pickupPoint.address?.geoCoordinates[0],
longitude: pickupPoint.address?.geoCoordinates[1],
specialOpeningHoursSpecification: pickupPoint.pickupHolidays?.map(
toSpecialHoursSpecification,
),
openingHoursSpecification: pickupPoint.businessHours?.map((
{ ClosingTime, DayOfWeek, OpeningTime },
) =>
Expand All @@ -1175,6 +1200,7 @@ export function toPlace(
latitude,
longitude,
name,
specialOpeningHoursSpecification,
openingHoursSpecification,
additionalProperty: [{
"@type": "PropertyValue",
Expand Down
7 changes: 7 additions & 0 deletions vtex/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -513,12 +513,19 @@ export interface PickupStoreInfo {
dockId: null;
}

export interface PickupHolidays {
date?: string;
hourBegin?: string;
hourEnd?: string;
}

export interface PickupPoint {
friendlyName: string;
address: Address;
additionalInfo: string;
id: string;
businessHours: BusinessHour[];
pickupHolidays?: PickupHolidays[];
}

export interface BusinessHour {
Expand Down

0 comments on commit c8dc4b1

Please sign in to comment.