Skip to content

Commit

Permalink
add header to options
Browse files Browse the repository at this point in the history
  • Loading branch information
lulu committed May 9, 2024
1 parent b66367e commit 1474d18
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,16 @@ I strongly recommend using this plugin in combination with the [Medusa Plugin Se
from: string
/* template id from sendgrid */
templateId: string
/* header line of the email optional */
header?: string
/* number of days to track */
days_to_track?: number
/* subject of the email optional */
subject?: string
localization?: {
[key: string]: {
subject?: string
header?: string
templateId: string
};
}
Expand All @@ -165,6 +168,7 @@ I strongly recommend using this plugin in combination with the [Medusa Plugin Se
localization?: {
[key: string]: {
subject?: string
header?: string
templateId: string
};
}
Expand All @@ -184,6 +188,7 @@ I strongly recommend using this plugin in combination with the [Medusa Plugin Se
localization: {
[key: string]: {
subject?: string
header?: string
templateId: string
};
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "medusa-plugin-abandoned-cart",
"version": "2.0.3",
"version": "2.0.4",
"description": "Medusa plugin for abandoned cart tracking and recovery",
"author": "Lucjan Grzesik (https://github.com/luluhoc)",
"license": "MIT",
Expand Down
9 changes: 7 additions & 2 deletions src/services/abandoned-cart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,9 @@ export default class AbandonedCartService extends TransactionBaseService {
relations: ["items", "region", "shipping_address"],
});

let templateId = this.options_.templateId;
let subject = this.options_.subject;
let templateId = this.options_?.templateId;
let subject = this.options_?.subject;
let header = this.options_?.header;

if (!notNullCartsPromise) {
throw new MedusaError("Not Found", "Cart not found");
Expand All @@ -125,6 +126,7 @@ export default class AbandonedCartService extends TransactionBaseService {
if (localeOptions) {
templateId = localeOptions.templateId;
subject = localeOptions.subject ?? subject;
header = localeOptions.header ?? header;
}
} else if (this.checkTypeOfOptions(this.options_) && interval !== undefined) {
const intervalOptions = this.options_.intervals.find(
Expand All @@ -134,13 +136,15 @@ export default class AbandonedCartService extends TransactionBaseService {
if (intervalOptions) {
templateId = intervalOptions.templateId;
subject = intervalOptions.subject ?? subject;
header = intervalOptions.header ?? header;

if (intervalOptions.localization) {
const localeOptions = intervalOptions.localization[locale];

if (localeOptions) {
templateId = localeOptions.templateId;
subject = localeOptions.subject ?? subject;
header = localeOptions.header ?? header;
}
}
}
Expand All @@ -161,6 +165,7 @@ export default class AbandonedCartService extends TransactionBaseService {
dynamic_template_data: {
...cart,
subject: subject ?? "You left something in your cart",
header: header ?? "You left something in your cart",
},
};

Expand Down
8 changes: 8 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ export interface BasePluginOptions {
from: string
/* template id from sendgrid */
templateId: string
/* header line of the email optional */
header?: string
/* number of days to track */
days_to_track?: number
/* subject of the email optional */
subject?: string
localization?: {
[key: string]: {
subject?: string
header?: string
templateId: string
};
}
Expand All @@ -25,11 +28,13 @@ export interface IntervalOptions {
interval: string | number
/* subject of the email optional */
subject?: string
header?: string
/* template id from sendgrid */
templateId?: string
localization?: {
[key: string]: {
subject?: string
header?: string
templateId: string
};
}
Expand All @@ -49,6 +54,7 @@ export interface ManualAbandonedCart extends BasePluginOptions {
localization: {
[key: string]: {
subject?: string
header?: string
templateId: string
};
}
Expand Down Expand Up @@ -78,4 +84,6 @@ export interface TransformedCart {
abandoned_lastdate?: Date;
abandoned_last_interval?: number;
abandoned_completed_at?: Date;
subject?: string;
header?: string;
}

0 comments on commit 1474d18

Please sign in to comment.