public function unsubscribe() { parent::unsubscribe(); if (self::STATUS_UNSUBSCRIBED == $this->getSubscriberStatus() && Mage::getStoreConfig('followupemail/general/sendonlytosubscribers')) { Mage::getModel('followupemail/mysql4_queue')->deleteByCustomerEmail($this->getSubscriberEmail()); AW_Followupemail_Model_Log::logWarning('email ' . $this->getSubscriberEmail() . ' unsubscribed, all emails that were scheduled ' . 'from now and not sent were deleted from the email queue'); } return $this; }
public static function sendPrepared() { $config = Mage::getModel('followupemail/config'); if (!($lastExecTime = $config->getParam(AW_Followupemail_Model_Config::EMAIL_SENDER_LAST_EXEC_TIME))) { $config->setParam(AW_Followupemail_Model_Config::EMAIL_SENDER_LAST_EXEC_TIME, time()); return; } if (self::$_isRunning || time() - $lastExecTime < self::$runInterval) { return; } self::$_isRunning = true; $config->setParam(AW_Followupemail_Model_Config::EMAIL_SENDER_LAST_EXEC_TIME, time()); $emails = Mage::getModel('followupemail/mysql4_queue')->getPreparedEmailIds(); $model = Mage::getModel('followupemail/queue'); AW_Followupemail_Model_Log::log('email sender started, ' . count($emails) . ' email(s) prepared'); foreach ($emails as $emailId) { $model->load($emailId)->send(); } self::$_isRunning = false; }
public function checkCustomer($event) { if (!Mage::registry('checked_customer')) { $customer = $event->getCustomer(); if (self::isNewCustomer($customer) == true) { $queue = Mage::getResourceModel('followupemail/queue'); $queue->cancelByEvent($customer['email'], AW_Followupemail_Model_Source_Rule_Types::RULE_TYPE_CUSTOMER_NEW, $customer['entity_id']); $ruleIds = Mage::getModel('followupemail/mysql4_rule')->getRuleIdsByEventType(AW_Followupemail_Model_Source_Rule_Types::RULE_TYPE_CUSTOMER_NEW); if (!count($ruleIds)) { return; } $params = array(); $objects = array(); $params['customer_id'] = $customer['entity_id']; $params['store_id'] = $customer['store_id']; $objects['object_id'] = $customer['entity_id']; foreach ($ruleIds as $ruleId) { AW_Followupemail_Model_Log::log('customer registered, customerId=' . $params['customer_id'] . " validating, ruleId={$ruleId}"); Mage::getModel('followupemail/rule')->load($ruleId)->process($params, $objects); } } Mage::register('checked_customer', '1'); } }
$message = 'Failed to load XML : ' . $error->message; $subject = "Failed to load XML"; Mage::getSingleton('followupemail/log')->logError($message, $this, $subject); } return; } libxml_clear_errors(); define('TEMPLATE_PREFIX', 'template="nsltr:'); $templates = array(); $existingTemplates = array(); $model = Mage::getModel('newsletter/template'); foreach ($xml as $template) { $data = array(); foreach ($template as $fieldName => $value) { $data[$fieldName] = (string) $template->{$fieldName}; } if (!isset($data['template_code']) || $model->loadByCode($data['template_code'])->getId()) { continue; } $templates[] = $data; } foreach ($templates as $data) { foreach ($existingTemplates as $k => $v) { $data['template_text'] = str_replace(TEMPLATE_PREFIX . $k . '"', TEMPLATE_PREFIX . $k . '_' . $v . '"', $data['template_text']); } $model->setData($data)->setTemplateId(null)->setTemplateType(Mage_Newsletter_Model_Template::TYPE_TEXT)->setTemplateActual(1)->save(); AW_Followupemail_Model_Log::log(print_r($model->getData(), true)); } } catch (Exception $e) { Mage::logException($e); }
protected function _checkBirthdays() { $ruleIds = Mage::getModel('followupemail/mysql4_rule')->getRuleIdsByEventType(AW_Followupemail_Model_Source_Rule_Types::RULE_TYPE_CUSTOMER_BIRTHDAY); if (!count($ruleIds)) { return; } $customerEntityTypeID = Mage::getModel('eav/entity_type')->loadByCode('customer')->getId(); $customerDateOfBirthAttributeId = Mage::getModel('eav/entity_attribute')->loadByCode($customerEntityTypeID, 'dob')->getId(); $resource = Mage::getSingleton('core/resource'); $read = $resource->getConnection('core_read'); $customerEntity = $resource->getTableName('customer/entity'); $dobTableName = $customerEntity . '_datetime'; $time = time(); foreach ($ruleIds as $ruleId) { $rule = Mage::getModel('followupemail/rule')->load($ruleId); $sequenceNumber = 1; foreach (unserialize($rule->getChain()) as $chain) { $select = $read->select()->from(array('dob' => $dobTableName), array('entity_id', 'value'))->join(array('customer' => $customerEntity), 'customer.entity_id=dob.entity_id AND customer.entity_type_id=dob.entity_type_id', 'store_id')->where('dob.entity_type_id=?', $customerEntityTypeID)->where('dob.attribute_id=?', $customerDateOfBirthAttributeId)->where('DATE_FORMAT(dob.value, "%m-%d")=?', date('m-d', $time - (int) ($chain['BEFORE'] * $chain['DAYS'] * 86400))); $birthDays = $read->fetchAll($select); if (count($birthDays)) { $params = array(); foreach ($birthDays as $birthDay) { $params['object_id'] = $birthDay['entity_id']; $params['customer_id'] = $birthDay['entity_id']; $params['dob'] = $birthDay['value']; $params['store_id'] = $birthDay['store_id']; AW_Followupemail_Model_Log::log('customer birthday event processing, rule_id=' . $ruleId . ', customerId=' . $params['customer_id'] . ', dob=' . $params['dob'] . ', store_id=' . $params['store_id']); $rule->processBirthday($params, $chain['TEMPLATE_ID'], $chain['BEFORE'] * $chain['DAYS'], $sequenceNumber); } } $sequenceNumber++; } } }