public function onAfterWrite() { try { if ($this->owner->isChanged('ID') || $this->owner->isChanged('Email') || $this->owner->isChanged('MemberID') || $this->owner->isChanged('FirstName') || $this->owner->isChanged('Surname')) { $data = CustomerDataExtractor::inst()->extract($this->owner); SS_Log::log("Adding/updating mailing list user: "******"Unable to add {$data['Email']} to mailing list: " . $e->getMessage(), SS_Log::WARN); } }
/** * Constructs an email object for the given order (if possible) * @param Order $order * @return Email|null */ public function getEmailForOrder(Order $order) { $data = CustomerDataExtractor::inst()->extract($order); $emailAddress = $data['Email']; // Send to admin? if ($this->To === self::TO_ADMIN) { $emailAddress = FollowUpEmail::config()->admin_email; if (empty($emailAddress)) { $emailAddress = Email::config()->admin_email; } } // Send the email if possible if (!empty($emailAddress)) { // fill in some additional templating $data = $this->performSubstitutions($data, $order); // build the email $email = new Email(); $email->setFrom(Email::config()->admin_email); $email->setTo($emailAddress); $email->setSubject($this->Subject); $body = $this->customise($data)->renderWith(array('FollowUpEmail')); foreach ($data as $k => $v) { $body = str_replace(array('http://{{{' . $k . '}}}', '{{{' . $k . '}}}'), array($v, $v), $body); } $email->setBody($body); return $email; } else { return null; } }