/**
  * Execute Task
  * @return bool
  */
 public function execute()
 {
     $this->out('  >> Email Task', 1, Shell::VERBOSE);
     /**
      * Exit if no message id
      */
     if (empty($this->message_id) || empty($this->ddb)) {
         $this->out('     Failed. No Message id.');
         return false;
     }
     $message_data = $this->ddb->getData($this->message_id);
     /**
      * Exit if no data
      */
     if (empty($message_data)) {
         $this->out('     Failed. No Message data.', 1, Shell::NORMAL);
         return false;
     }
     $payload = $message_data['payload'];
     $to = $payload['to'];
     $locale = $payload['locale'];
     $data = $payload['email_data'];
     $template = $payload['template'];
     $tag = $payload['tag'];
     $subject = $payload['subject'];
     $emailOptions = $payload['email_options'];
     try {
         /**
          * Send user email
          */
         $this->out('     Sending Email.', 1, Shell::VERBOSE);
         $this->sendEmail($data, $to, $locale, $template, $tag, $subject, $emailOptions);
     } catch (Exception $e) {
         $this->out('     Failed.');
         CakeLog::error('CRITICAL: Error encountered in Email Task');
         CakeLog::error($e->getMessage());
         return false;
     }
     $this->out('     Done.', 1, Shell::VERBOSE);
     return true;
 }
 /**
  * Sends an email to the queue to make sure email sends don't hold up http requests on the site.
  * @param $emailData
  * @param $templateName
  * @param $to
  * @param $subjectBlockName
  * @param $tag
  * @param $locale
  * @param null $emailOptions
  * @return bool|\Guzzle\Service\Resource\Model|string
  * @throws Exception
  */
 public static function queueEmail($emailData, $templateName, $to, $subjectBlockName, $tag, $locale, $emailOptions = null)
 {
     $to = trim($to);
     if (Sqs::useQueue()) {
         $data = ['to' => $to, 'locale' => $locale, 'template' => $templateName, 'tag' => $tag, 'subject' => $subjectBlockName, 'email_data' => $emailData, 'email_options' => $emailOptions];
         if (!defined('EMAIL_QUEUE_DB') || !defined('EMAIL_QUEUE_SQS')) {
             CakeLog::error("Email Queue Table name or SQS Url not found.");
             return false;
         }
         $ddb = new Ddb(EMAIL_QUEUE_DB);
         $sqs = new Sqs(EMAIL_QUEUE_SQS);
         // save to DDB
         $details_id = $ddb->guid();
         $result = $ddb->saveData($details_id, $data);
         // send to SQS
         $sqs->send($details_id);
         return $result;
     } else {
         $result = YouniqueEmail::sendEmail($emailData, $templateName, $to, $subjectBlockName, $tag, $locale, false, $emailOptions);
         return $result;
     }
 }
Exemple #3
0
 /**
  * Send Tracking Email from net suite DataFlow 5
  *
  * @see DataFlowFiveTask
  * @param $shipment_id
  * @return bool|\Guzzle\Service\Resource\Model
  */
 public function sendCustomerTrackingEmail($shipment_id)
 {
     $this->OrderShipment = ClassRegistry::init('OrderShipment');
     $record = $this->OrderShipment->find('first', ['contain' => ['OrderShipment', 'Order'], 'conditions' => ['OrderShipment.id' => $shipment_id]]);
     if ($record['OrderShipment']['tracking_number'] && $record['OrderShipment']['carrier']) {
         $tracking_url = $this->OrderShipment->getTrackingLink($record['OrderShipment']['tracking_number'], $record['OrderShipment']['carrier']);
     } else {
         $tracking_url = '';
     }
     //to try to avoid sending too many emails, check the order status.
     if ($record['Order']['order_status_id'] == Order::STATUS_SHIPPED) {
         return false;
     }
     $charm_order = false;
     if ((string) $record['Order']['order_type_id'] == '8') {
         $charm_order = true;
     }
     $customer_name = $record['OrderShipment']['first_name'] . " " . $record['OrderShipment']['last_name'];
     if (!$charm_order) {
         $email_data = ["name" => $customer_name, "order_id" => $record['OrderShipment']['order_id'], "tracking_number" => $record['OrderShipment']['tracking_number'], "tracking_url" => $tracking_url, "country_id" => $record['OrderShipment']['country_id']];
         $customers_user_id = $record['Order']['user_id'];
         $this->User = ClassRegistry::init('User');
         $userLocale = $this->User->userLocale($customers_user_id);
         $locale = $userLocale['User']['locale'] ? $userLocale['User']['locale'] : "en_US";
         $data = ['to' => $record['OrderShipment']['email_address'], 'locale' => $locale, 'template' => 'en_us_tracking_numbers', 'tag' => 'purchase-page', 'subject' => 'email order tracking', 'email_data' => $email_data];
         if (!defined('EMAIL_QUEUE_DB') || !defined('EMAIL_QUEUE_SQS')) {
             CakeLog::error("Email Queue Table name or SQS Url not found.");
             return false;
         }
         $ddb = new Ddb(EMAIL_QUEUE_DB);
         $sqs = new Sqs(EMAIL_QUEUE_SQS);
         // save to DDB
         $details_id = $ddb->guid();
         $result = $ddb->saveData($details_id, $data);
         // send to SQS
         $sqs->send($details_id);
         return $result;
     }
     return false;
 }