Skip to content

Commit

Permalink
Product variations (#2157)
Browse files Browse the repository at this point in the history
      <img width="466" alt="Screenshot 2024-11-11 at 11 56 49 PM"
src="https://github.com/user-attachments/assets/e13c3af5-a339-4813-bfcd-f53e51527cb4">
  • Loading branch information
rrrliu authored Nov 11, 2024
1 parent 1b15bb1 commit 0ac1684
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,24 @@ const VALID_PRETIX_EVENT_SETTINGS: GenericPretixEventSettings = {
attendee_emails_required: true
};

const VARIATION_NUMBER_TO_VARIATION_NAME: Record<number, string> = {
2: "S",
3: "M",
4: "L",
5: "XL",
6: "XXL",
7: "S",
8: "M",
9: "L",
10: "XL",
11: "XXL",
12: "S",
13: "M",
14: "L",
15: "XL",
16: "XXL"
};

/**
* Class encapsulating the complete set of behaviors that a {@link Pipeline} which
* loads data from Pretix is capable of.
Expand Down Expand Up @@ -391,6 +409,10 @@ export class PretixPipeline implements BasePipeline {
name: ticket.full_name,
eventId: ticket.event.genericIssuanceId,
productId: ticket.product.genericIssuanceId,
variationName: ticket.variation
? VARIATION_NUMBER_TO_VARIATION_NAME[ticket.variation] ??
`Unknown (${ticket.variation})`
: null,
// Use the event ID as the "namespace" when hashing the position ID.
// The event ID is a UUID that is part of our configuration, and is
// globally unique. The position ID is not globally unique, but is
Expand Down Expand Up @@ -890,7 +912,8 @@ export class PretixPipeline implements BasePipeline {
secret,
checkins,
answers,
addon_to
addon_to,
variation
} = position;

const product = products.get(item.toString());
Expand Down Expand Up @@ -959,7 +982,8 @@ export class PretixPipeline implements BasePipeline {
secret,
pretix_checkin_timestamp,
order_code: order.code,
addon_to_position_id: addon_to?.toString() ?? null
addon_to_position_id: addon_to?.toString() ?? null,
variation
});
}
}
Expand Down Expand Up @@ -2271,6 +2295,9 @@ export class PretixPipeline implements BasePipeline {
private atomToTicketName(atom: PretixAtom): string {
const event = this.getEventById(atom.eventId);
const product = this.getProductById(event, atom.productId);
if (atom.variationName) {
return `${product.name} (${atom.variationName})`;
}
return product.name;
}

Expand Down Expand Up @@ -2419,6 +2446,7 @@ export interface PretixTicket {
secret: string;
order_code: string;
position_id: string;
variation: number | null;
pretix_checkin_timestamp: Date | null;
addon_to_position_id: string | null;
}
Expand All @@ -2431,6 +2459,7 @@ export interface PretixAtom extends PipelineAtom {
secret: string;
timestampConsumed: Date | null;
isConsumed: boolean;
variationName: string | null;
parentAtomId: string | null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,7 @@ export class GenericPretixDataMocker {
subevent: subEventId,
secret: this.randomPositionSecret(),
checkins: [],
variation: null,
answers,
addon_to: null
};
Expand Down
1 change: 1 addition & 0 deletions packages/lib/passport-interface/src/genericPretixTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const GenericPretixPositionSchema = z.object({
secret: z.string(),
checkins: z.array(GenericPretixCheckinSchema),
addon_to: z.number().nullable(), // id of the position this is an add-on to
variation: z.number().nullable(), // id of the purchased variation
answers: z.array(GenericPretixAnswerSchema).optional()
});

Expand Down

0 comments on commit 0ac1684

Please sign in to comment.