/** * 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; }
/** * request approval: sends email to shop admin to request approval. */ function requestapproval($data, $form, $request) { if ($this->member) { $email = new Email(); $email->setTo(Order_Email::get_from_email()); $email->setSubject(_t("EcommerceCorporateAccount.REQUESTINGACCOUNTAPPROVE", "A request for an account approval from ") . $this->member->Email); $email->setTemplate('EcommerceCorporateGroupApprovalRequest'); $config = SiteConfig::current_site_config(); $ecommerceConfig = EcommerceDBConfig::current_ecommerce_db_config(); $email->populateTemplate(array('SiteConfig' => $config, 'EcommerceConfig' => $ecommerceConfig, 'Member' => $this->member)); $email->send(); $form->sessionMessage(_t('EcommerceCorporateAccount.REQUESTHASBEENSENT', 'The request has been sent.'), 'good'); Director::redirectBack(); } else { $form->sessionMessage(_t('EcommerceCorporateAccount.REQUESTCOULDNOTBESEND', 'The request could not be sent.'), 'bad'); Director::redirectBack(); } }
/** * Send a mail of the order to the client (and another to the admin). * * @param String $emailClass - the class name of the email you wish to send * @param String $subject - email subject * @param Boolean $copyToAdmin - true by default, whether it should send a copy to the admin * @param Boolean $resend - sends the email even it has been sent before. * @param Boolean $adminOnly - sends the email to the ADMIN ONLY. * * @return Boolean TRUE for success, FALSE for failure (not tested) */ protected function sendEmail($emailClass, $subject, $message, $resend = false, $adminOnly = false) { if (!$message) { $emailableLogs = DataObject::get('OrderStatusLog', "\"OrderID\" = {$this->ID} AND \"InternalUseOnly\" = 0", "\"Created\" DESC", null, 1); if ($emailableLogs) { $latestEmailableLog = $emailableLogs->First(); $message = $latestEmailableLog->Note; } } $replacementArray = array("Message" => $message); $replacementArray["Order"] = $this; $replacementArray["EmailLogo"] = $this->EcomConfig()->EmailLogo(); $replacementArray["ShopPhysicalAddress"] = $this->EcomConfig()->ShopPhysicalAddress; $from = Order_Email::get_from_email(); //why are we using this email and NOT the member.EMAIL? //for historical reasons???? if ($adminOnly) { $to = Order_Email::get_from_email(); } else { $to = $this->OrderEmail(); } if ($from && $to) { $email = new $emailClass(); if (!$email instanceof Email) { user_error("No correct email class provided.", E_USER_ERROR); } $email->setFrom($from); $email->setTo($to); $email->setSubject($subject); $email->populateTemplate($replacementArray); return $email->send(null, $this, $resend); } return false; }
/** * returns the order formatted as an email * @param String $message - the additional message * @param String $emailClassName - template to use. * @return array (Message, Order, EmailLogo, ShopPhysicalAddress) */ public function renderOrderInEmailFormat($message = "", $emailClassName) { $arrayData = $this->createReplacementArrayForEmail($message); Config::nest(); Config::inst()->update('SSViewer', 'theme_enabled', true); $html = $arrayData->renderWith($emailClassName); Config::unnest(); return Order_Email::emogrify_html($html); }
/** * * @param Null|String $messageID - ID for the message, you can leave this blank * @param Boolean $returnBodyOnly - rather than sending the email, only return the HTML BODY * @return Boolean - TRUE for success and FALSE for failure. */ public function send($messageID = null, $returnBodyOnly = false) { if (!$this->order) { user_error("Must set the order (Order_Email::setOrder()) before the message is sent (Order_Email::send()).", E_USER_NOTICE); } if (!$this->subject) { $this->subject = self::get_subject(); } $this->subject = str_replace("[OrderNumber]", $this->order->ID, $this->subject); if (!$this->hasBeenSent() || $this->resend) { if (EcommerceConfig::get("Order_Email", "copy_to_admin_for_all_emails") && $this->to != Order_Email::get_from_email()) { $this->setBcc(Order_Email::get_from_email()); } //last chance to adjust $this->extend("adjustOrderEmailSending", $this, $order); if ($returnBodyOnly) { return $this->Body(); } if (EcommerceConfig::get("Order_Email", "send_all_emails_plain")) { $result = parent::sendPlain($messageID); } else { $result = parent::send($messageID); } $this->createRecord($result); return $result; } }
/** * standard SS Method * Sends an email to the member letting her / him know that the account has been approved. */ function onAfterWrite() { if ($this->owner->isApprovedCorporateCustomer()) { if (!$this->owner->ApprovalEmailSent) { $config = SiteConfig::current_site_config(); $ecommerceConfig = EcommerceDBConfig::current_ecommerce_db_config(); $email = new Email(); $email->setTo($this->owner->Email); $email->setSubject(_t("EcommerceCorporateAccount.ACCOUNTAPPROVEDFOR", "Account approved for ") . $config->Title); $email->setBcc(Order_Email::get_from_email()); $email->setTemplate('EcommerceCorporateGroupApprovalEmail'); $email->populateTemplate(array('SiteConfig' => $config, 'EcommerceConfig' => $ecommerceConfig, 'Member' => $this->owner)); $email->send(); $this->owner->ApprovalEmailSent = 1; $this->owner->write(); } } }
function notify($member, $type = "added", $error = false) { $errorString = $error ? " ERROR: " : "OK"; if ($member instanceof Member) { $name = $member->getName(); } else { $name = "--- COULD NOT SAVE ---"; } $email = new Email($from = Order_Email::get_from_email(), $to = Order_Email::get_from_email(), $subject = "A Merchant has been " . $type . ": " . $name, $body = "A Merchant has been " . $type . ": " . $name . ", result: " . $errorString); return $email->send(); }