public function run($request)
 {
     foreach (FollowUpEmail::get() as $followUp) {
         /** @var FollowUpEmail $followUp */
         if ($followUp->Active) {
             $followUp->sendToApplicableOrders(function ($msg) {
                 if (Director::is_cli()) {
                     echo $msg . "\n";
                 } else {
                     echo $msg . "<br>\n";
                 }
             });
         }
     }
 }
 /**
  * @param SS_HTTPRequest $request
  * @return SS_HTTPResponse
  */
 public function claim(SS_HTTPRequest $request)
 {
     /** @var Order $order */
     $order = Order::get()->byID($request->param('ID'));
     $hash = $request->param('OtherID');
     $realHash = FollowUpEmail::generate_hash($order);
     if (!$order || !$order->exists() || empty($hash) || $hash !== $realHash) {
         $this->httpError(404);
     }
     // Require a login if the order is attached to an account
     if ($order->MemberID && $order->MemberID != Member::currentUserID()) {
         return Security::permissionFailure($this->owner, _t('ShopEmail.NotYourOrder', 'You must log in to access this order.'));
     }
     // Otherwise if all is good, proceed to checkout
     ShoppingCart::singleton()->setCurrent($order);
     return $this->redirect(CheckoutPage::get()->first()->Link());
 }
 /**
  * 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;
     }
 }