/** * Sends a Bronto Delivery * * @param Bronto_Common_Model_Queue $queue * @return boolean */ public function sendDeliveryFromQueue($queue) { $deliveryErrors = 0; $message = $queue->getMessage(); $contacts = $queue->getContacts(); $this->setSendQueue($queue); $this->setMessage($message); $this->setBrontoMessageId($message->getId()); $this->setBrontoMessageName($message->getName()); $this->setBrontoMessageApproved(1); $this->_setRelatedFields($queue); foreach ($contacts as $contact) { $this->_beforeSend($contact, $message); if (!$contact->id) { $deliveryErrors++; $this->_afterSend(false, "{$contact->email}: {$contact->error}"); continue; } try { $delivery = $queue->prepareDelivery()->withStart($this->_startTime($queue->getStoreId()))->addContact($contact->getId()); $list = Mage::getModel('bronto_common/list', array($this->_helper, $queue->getAdditionalData()->getExclusionList())); $excludes = $list->addAdditionalRecipients($queue->getStoreId()); foreach ($excludes as $exclude) { $delivery->ineligibleList($exclude['id']); } $queue->getDeliveryObject()->save($delivery); $this->setLastDeliveryId($delivery->getId()); $this->_afterSend(true, null, $delivery); } catch (Exception $e) { $deliveryErrors++; $errorMessage = $e->getMessage(); if ($e->getCode() === 215) { // Replace message id with message name if (preg_match_all("/([a-zA-Z0-9\\-]){36}/", $errorMessage, $matches)) { // Grab field id if exists foreach ($matches[0] as $match) { $errorMessage = str_replace($match, $message->getName(), $errorMessage); } } } Mage::helper($this->_helper)->writeError($errorMessage); $this->_afterSend(false, $errorMessage, $delivery); } $this->_flushLogs($queue->getDeliveryObject()->getApi()); } return $deliveryErrors == 0; }
/** * Sends a Bronto Delivery * * @param Bronto_Common_Model_Queue $queue * @return boolean */ public function sendDeliveryFromQueue($queue) { $deliveryErrors = 0; $message = $queue->getMessage(); $contacts = $queue->getContacts(); $this->setSendQueue($queue); $this->setMessage($message); $this->setBrontoMessageId($message->id); $this->setBrontoMessageName($message->name); $this->setBrontoMessageApproved(1); $this->_setRelatedFields($queue); foreach ($contacts as $contact) { $this->_beforeSend($contact, $message); if (!$contact->id) { $deliveryErrors++; $this->_afterSend(false, "{$contact->email}: {$contact->error}"); continue; } try { $delivery = $queue->prepareDelivery(); $delivery->start = $this->_startTime($queue->getStoreId()); $recipients = array(array('type' => 'contact', 'id' => $contact->id, 'deliveryType' => 'selected')); $list = Mage::getModel('bronto_common/list', array($this->_helper, $queue->getAdditionalData()->getExclusionList())); $excludes = $list->addAdditionalRecipients($queue->getStoreId()); foreach ($excludes as $exclude) { $recipients[] = $exclude; } $delivery->recipients = $recipients; $delivery->save(); if ($delivery->id) { $this->setLastDeliveryId($delivery->id); $this->_afterSend(true, null, $delivery); } else { $this->_afterSend(false, null, $delivery); } } catch (Exception $e) { $deliveryErrors++; $errorMessage = $e->getMessage(); if ($e->getCode() === Bronto_Api_Delivery_Exception::MESSAGE_NOT_TRANSACTIONAL_APPROVED) { // Replace message id with message name if (preg_match_all("/([a-zA-Z0-9\\-]){36}/", $errorMessage, $matches)) { // Grab field id if exists foreach ($matches[0] as $match) { $errorMessage = str_replace($match, $message->name, $errorMessage); } } } Mage::helper($this->_helper)->writeError($errorMessage); $this->_afterSend(false, $errorMessage, $delivery); } } return $deliveryErrors == 0; }