/** * emailing admin and or running custom code to update newsletter status * @param DataObject $order Order * @return Boolean **/ public function doStep(Order $order) { $billingAddress = $order->BillingAddress(); $member = $order->Member(); if ($member && $billingAddress) { $recipient = Recipient::get()->filter(array("Email" => $billingAddress->Email))->first(); if (!$recipient) { $recipient = Recipient::create(); $recipient->Email = $billingAddress->Email; } $recipient->FirstName = $billingAddress->FirstName; $recipient->Surname = $billingAddress->Surname; $recipient->write(); $mailingListToAdd = $member->MailingLists(); DB::query("DELETE FROM MailingList_Recipients WHERE RecipientID = " . $recipient->ID . ";"); if ($mailingListToAdd->count()) { $recipientsMailingLists = $recipient->MailingLists(); $recipientsMailingLists->addMany($mailingListToAdd->map("ID", "ID")->toArray()); if ($this->SendMessageToAdmin) { $member = $order->Member(); if ($member) { if ($member->NewsletterSignup) { $from = Order_Email::get_from_email(); $subject = _t("NewsletterSignup.NEWSLETTERREGISTRATIONUPDATE", "newsletter registration update"); $billingAddressOutput = ""; if ($billingAddress) { $billingAddressOutput = $billingAddress->renderWith("Order_AddressBilling"); } $body = "\n\t\t\t\t\t\t\t\t" . _t("NewsletterSignup.EMAIL", "Email") . ": <strong>" . $member->Email . "</strong>" . "<br /><br />" . _t("NewsletterSignup.SIGNUP", "Signed Up") . ": <strong>" . ($member->NewsletterSignup ? _t("NewsletterSignup.YES", "Yes") : _t("NewsletterSignup.NO", "No")) . "</strong>" . "<br /><br />" . $billingAddressOutput; $email = new Email($from, $to = Order_Email::get_from_email(), $subject, $body); $email->send(); //copy! if ($this->SendCopyTo) { $email = new Email($from, $to = $this->SendCopyTo, $subject, $body); $email->send(); } } //this can be used to connect with third parties (e.g. ) } } } $this->extend("updateNewsletterStatus", $member, $recipient); } return true; }
/** * Create a valid test recipient */ protected static function createTestRecipient(array $attributes = array()) { self::authorizeFromEnv(); return Recipient::create($attributes + array('name' => 'PHP Test', 'type' => 'individual', 'tax_id' => '000000000', 'bank_account' => array('country' => 'US', 'routing_number' => '110000000', 'account_number' => '000123456789'))); }