/** * Send all emails from email list * * @see self::$_emailInfos * * @return Bronto_Email_Model_Template_Mailer */ public function send() { // If using the 'Do Not Send' option, just return $this and be done. if ($this->getTemplateId() == 'nosend') { return $this; } // Try loading template $emailTemplate = Mage::getModel('bronto_email/template'); $emailTemplate->load($this->getTemplateId()); // If sending through bronto is not enabled, push through parent if (!Mage::helper('bronto_email')->canSendBronto($emailTemplate)) { return parent::send(); } $message = new Bronto_Api_Model_Message(); $message->withId($emailTemplate->getBrontoMessageId()); // Send all emails from corresponding list while (!empty($this->_emailInfos)) { $emailInfo = array_pop($this->_emailInfos); // Handle "Bcc" recepients of the current email if ($emailTemplate->getTemplateSendType() == 'magento') { $emailTemplate->addBcc($emailInfo->getBccEmails()); } else { foreach ($emailInfo->getBccEmails() as $bcc) { $emailInfo->addTo($bcc); } } // Set required design parameters and delegate email sending to Mage_Core_Model_Email_Template $emailTemplate->setDesignConfig(array('area' => 'frontend', 'store' => $this->getStoreId()))->sendTransactional($message, $this->getSender(), $emailInfo->getToEmails(), $emailInfo->getToNames(), $this->getTemplateParams(), $this->getStoreId()); } return $this; }
/** * Send transactional email to recipient * * @param int $templateId * @param string|array $sender Sender information, can be declared as part of config path * @param string $email Recipient email * @param string $name Recipient name * @param array $vars Variables which can be used in template * @param int|null $storeId * * @return Mage_Core_Model_Email_Template */ public function sendTransactional($templateId, $sender, $email, $name, $vars = array(), $storeId = null) { // If Template ID is 'nosend', then simply return false if ($templateId == 'nosend') { return false; } // If not set to go through Bronto, fall through to magento sending if (!Mage::helper($this->_helper)->canSendBronto($this, $storeId)) { return parent::sendTransactional($templateId, $sender, $email, $name, $vars, $storeId); } else { // If module enabled and template ID is not an instance of the api row, see if we can pull an instance if (!$templateId instanceof Bronto_Api_Model_Message) { $emailTemplate = Mage::getModel('bronto_email/template')->setDesignConfig($this->getDesignConfig()->getData()); // If $templateId is numeric, load template by ID, else is default and should send through Magento if (is_numeric($templateId)) { $emailTemplate->load($templateId); } else { $this->setTemplateSendType('magento'); return parent::sendTransactional($templateId, $sender, $email, $name, $vars, $storeId); } // If Template doesn't have a Bronto Message ID, send through magento if (!$emailTemplate->getBrontoMessageId() || is_null($emailTemplate->getBrontoMessageId())) { return parent::sendTransactional($templateId, $sender, $email, $name, $vars, $storeId); } $message = new Bronto_Api_Model_Message(); $message->withId($emailTemplate->getBrontoMessageId()); // Send through main template model $emailTemplate->sendTransactional($message, $sender, $email, $name, $vars, $storeId); return $this->setSentSuccess($emailTemplate->getSentSuccess()); } else { $this->setBrontoMessageId($templateId->id); } } // Start the send process $this->setSentSuccess(false); if ($storeId === null && $this->getDesignConfig()->getStore()) { $storeId = $this->getDesignConfig()->getStore(); } // If $sender is not array, it is a reference to a config setting, otherwise it should have 'name' and 'email' if (!is_array($sender)) { $this->setSenderName(Mage::getStoreConfig('trans_email/ident_' . $sender . '/name', $storeId)); $this->setSenderEmail(Mage::getStoreConfig('trans_email/ident_' . $sender . '/email', $storeId)); } else { $this->setSenderName($sender['name']); $this->setSenderEmail($sender['email']); } // If store is not set, set it if (!isset($vars['store'])) { $vars['store'] = Mage::app()->getStore($storeId); } // Check for Sales Rules if (!isset($vars['coupon']) && ($rule = $this->_getSalesRule($storeId))) { try { /** @var Mage_SalesRule_Model_Coupon $coupon */ $coupon = $rule->acquireCoupon(); if ($coupon) { $vars['coupon'] = $coupon; } } catch (Exception $e) { Mage::helper($this->_helper)->writeError(' Failed loading Sales Rule with ID: ' . $rule->getId()); } } // Send $this->setSentSuccess($this->send($email, $name, $vars)); return $this; }
/** * Sends the desired message transactionally * * @param Bronto_Reviews_Model_Process_Context $context * @param Bronto_Reviews_Model_Message $postMessage * @param mixed */ protected function _sendMessage($context, $postMessage) { $order = $context->getOrder(); $postType = $context->getPostType(); $storeId = $order->getStoreId(); $sender = $this->_helper->getPostEmailIdentity($postType, 'store', $storeId); if ($sender == 'custom') { $sender = array('name' => $this->_helper->getPostSenderName($postType, 'store', $storeId), 'email' => $this->_helper->getPostSenderEmail($postType, 'store', $storeId)); } $message = new Bronto_Api_Model_Message(); $message->withId($this->_helper->getDefaultMessage($context->getPost(), $storeId)); $filterData = array('order' => $order) + $context->getExtra(); if ($context->hasPost()) { unset($filterData['order']); $filterData['orderIncrementId'] = $order->getIncrementId(); $filterData['orderCreatedAt'] = $order->getCreatedAtFormated('long'); $filterData['orderStatusLabel'] = $order->getStatusLabel(); $filterData['orderCustomerName'] = $order->getCustomerIsGuest() ? $order->getBillingAddress()->getName() : $order->getCustomerName(); } $this->_cancelReorderDelivery($context); $postMessage->addParam('store_id', $order->getStoreId())->addParam('order_id', $order->getId())->addParam('order_increment_id', $order->getIncrementId())->addParam('customer_email', $order->getCustomerEmail())->addParam('exclusion_list', $postType)->addParam('post_name', $this->_helper->getPostLabel($postType))->setDesignConfig(array('area' => 'frontend', 'store' => $storeId))->setSalesRule($this->_helper->getPostRule($postType, 'store', $storeId))->setProductRecommendation($this->_helper->getPostRecommendation($postType, 'store', $storeId))->setTemplateSendType('triggered')->setSendFlags($this->_helper->getPostSendFlags($postType, 'store', $storeId))->sendTransactional($message, $sender, array($order->getCustomerEmail()), array($order->getCustomerName()), $filterData, $storeId); if ($postMessage->getSentSuccess()) { $this->_helper->writeDebug(' Successfully created delivery.'); } else { $this->_helper->writeDebug(' Failed to send the message.'); } }