Skip to content

Commit

Permalink
Merge pull request #436 from adamreisnz/issue-433
Browse files Browse the repository at this point in the history
Convert plain data to personalization class instance
  • Loading branch information
thinkingserious authored Aug 31, 2017
2 parents 27adfce + c7e9797 commit 1e1512c
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions packages/helpers/classes/mail.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,13 @@ class Mail {
* Add personalization
*/
addPersonalization(personalization) {

//Convert to class if needed
if (!(personalization instanceof Personalization)) {
personalization = new Personalization(personalization);
}

//Apply substitutions and push to array
this.applySubstitutions(personalization);
this.personalizations.push(personalization);
}
Expand Down Expand Up @@ -275,8 +282,10 @@ class Mail {
* Helper which applies globally set substitutions to personalizations
*/
applySubstitutions(personalization) {
personalization.reverseMergeSubstitutions(this.substitutions);
personalization.setSubstitutionWrappers(this.substitutionWrappers);
if (personalization instanceof Personalization) {
personalization.reverseMergeSubstitutions(this.substitutions);
personalization.setSubstitutionWrappers(this.substitutionWrappers);
}
}

/**
Expand Down

0 comments on commit 1e1512c

Please sign in to comment.