protected function _prepareColumns() { $this->addColumn('email_created_at', array('index' => 'email_created_at', 'type' => 'datetime', 'header' => $this->__('Created at'), 'align' => 'left', 'width' => '145px', 'filter_condition_callback' => array($this, '_filterConditionDate'))); $this->addColumn('email_sent_at', array('index' => 'email_sent_at', 'type' => 'datetime', 'header' => $this->__('Sent at'), 'align' => 'left', 'width' => '145px', 'filter_condition_callback' => array($this, '_filterConditionDate'))); $this->addColumn('link_visited_at', array('index' => 'link_visited_at', 'type' => 'datetime', 'header' => $this->__('Link visited at'), 'align' => 'left', 'width' => '145px', 'filter_condition_callback' => array($this, '_filterConditionDate'))); $this->addColumn('email_sequence_number', array('index' => 'email_sequence_number', 'header' => $this->__('Seq. No'), 'align' => 'center', 'width' => '50px', 'filter_condition_callback' => array($this, '_filterCondition'))); $this->addColumn('rule_title', array('index' => 'rule_title', 'header' => $this->__('Rule'), 'align' => 'left', 'filter_condition_callback' => array($this, '_filterConditionText'))); $this->addColumn('rule_event_type', array('index' => 'rule_event_type', 'header' => $this->__('Event'), 'align' => 'left', 'type' => 'options', 'options' => Mage::getModel('followupemail/source_rule_types')->toShortOptionArray(), 'filter_condition_callback' => array($this, '_filterCondition'))); $this->addColumn('email_recipient_name', array('index' => 'email_recipient_name', 'header' => $this->__('Recipient name'), 'align' => 'left', 'filter_condition_callback' => array($this, '_filterConditionText'))); $this->addColumn('email_recipient_email', array('index' => 'email_recipient_email', 'header' => $this->__('Recipient email'), 'align' => 'left', 'filter_condition_callback' => array($this, '_filterConditionText'))); // adding cart-related fields if (AW_Followupemail_Model_Source_Linktracking_Types::LINKTRACKING_TYPE_LINK_CART == $this->_queryType) { $this->addColumn('quote_created_at', array('index' => 'quote_created_at', 'type' => 'datetime', 'header' => $this->__('Quote created at'), 'align' => 'left', 'filter_condition_callback' => array($this, '_filterConditionDate'))); $this->addColumn('quote_grand_total', array('index' => 'quote_grand_total', 'type' => 'currency', 'header' => $this->__('Quote grand total'), 'align' => 'left', 'filter_condition_callback' => array($this, '_filterConditionCurrency'))); } // adding order-related fields if (AW_Followupemail_Model_Source_Linktracking_Types::LINKTRACKING_TYPE_LINK_CART_ORDER == $this->_queryType) { $this->addColumn('quote_created_at', array('index' => 'quote_created_at', 'type' => 'datetime', 'header' => $this->__('Quote created at'), 'align' => 'left', 'filter_condition_callback' => array($this, '_filterConditionDate'))); $this->addColumn('order_increment_id', array('index' => 'order_increment_id', 'header' => $this->__('Order No'), 'align' => 'left', 'filter_condition_callback' => array($this, '_filterConditionText'))); $mageVersionCode = AW_Followupemail_Helper_Data::getMagentoVersionCode(); if ($mageVersionCode == AW_Followupemail_Helper_Data::MAGENTO_VERSION_CE_1_3) { $this->addColumn('order_is_active', array('index' => 'order_is_active', 'type' => 'options', 'header' => $this->__('Order is active'), 'align' => 'left', 'options' => array(1 => $this->__('Yes'), 0 => $this->__('No')), 'filter_condition_callback' => array($this, '_filterCondition'))); } $this->addColumn('order_grand_total', array('index' => 'order_grand_total', 'type' => 'currency', 'header' => $this->__('Order Grand Total'), 'align' => 'left', 'filter_condition_callback' => array($this, '_filterConditionCurrency'))); } // actions $actions = array(array('caption' => $this->__('View email'), 'url' => array('base' => '*/*/viewEmail'), 'field' => 'id', 'popup' => true), array('caption' => $this->__('View rule'), 'url' => array('base' => '*/*/viewRule'), 'field' => 'id', 'popup' => true), array('caption' => $this->__('View customer (if registered)'), 'url' => array('base' => '*/*/viewCustomer'), 'field' => 'id', 'popup' => true)); if (false !== strpos($this->_queryType, 'cart')) { $actions[] = array('caption' => $this->__('View cart (if customer is registered)'), 'url' => array('base' => '*/*/viewCart'), 'field' => 'id', 'popup' => true); } if (false !== strpos($this->_queryType, 'order')) { $actions[] = array('caption' => $this->__('View order'), 'url' => array('base' => '*/*/viewOrder'), 'field' => 'id', 'popup' => true); } $this->addColumn('action', array('header' => $this->__('Action'), 'width' => '120', 'type' => 'action', 'getter' => 'getId', 'actions' => $actions, 'filter' => false, 'sortable' => false, 'index' => 'stores', 'is_system' => true)); return parent::_prepareColumns(); }
public function __construct() { parent::__construct(); $this->setTemplate('followupemail/linktracking/queryselector.phtml'); $this->setQueryType(AW_Followupemail_Helper_Data::getLinktrackingQueryType()); }
public function processBirthday($params, $templateId, $timeDelay, $sequenceNumber) { $objects = $this->_createObjects($params, array()); if (!$this->_validated) { $this->validate($objects); } if ($this->_isValid) { if (!(isset($params['customer_id']) && $params['customer_id'])) { $message = 'rule id=' . $this->getId() . ' processing error: customer_id is not set on birthday event, email="' . $objects['customer_email'] . '"'; $subject = "Rule processing error"; Mage::getSingleton('followupemail/log')->logError($message, $this, $subject); return false; } // Generate coupon if it needed if ($this->getCouponEnabled()) { //get content of current email template $emailTemplate = $this->_getTemplate($templateId); $emailTemplateContent = $emailTemplate['content']; // checking for presence standard coupon variable ( {{var coupon.code}}) $pattern2 = '|{{\\s*var\\s+coupon.code\\s*}}|u'; if (preg_match_all($pattern2, $emailTemplateContent, $matches) > 0) { $coupon = Mage::helper('followupemail/coupon')->createNew($this); $message = 'New coupon ' . $coupon->getCouponCode() . ' is created {' . print_r($coupon->getData(), true) . '}'; $subject = "New coupon is created"; Mage::getSingleton('followupemail/log')->logSuccess($message, $this, $subject); $objects['coupon'] = $coupon; $message = 'Coupon ' . $coupon->getCouponCode() . ' used {' . print_r($coupon->getData(), true) . '}'; $subject = "Coupon used"; Mage::getSingleton('followupemail/log')->logSuccess($message, $this, $subject); } // checking for presence extended coupon variable ( {{var coupons.__ALIAS__.code}}) $pattern1 = '|{{\\s*var\\s+coupons.(.*).code\\s*}}|u'; if (preg_match_all($pattern1, $emailTemplateContent, $matches) > 0) { // using object for access to variables from AW_Followupemail_Model_Filter::filter() $coupons = new Varien_Object(); foreach ($matches[1] as $couponId) { $coupon = Mage::helper('followupemail/coupon')->createNew($this); $message = 'New coupon ' . $coupon->getCouponCode() . ' is created {' . print_r($coupon->getData(), true) . '}'; $subject = "New coupon is created"; Mage::getSingleton('followupemail/log')->logSuccess($message, $this, $subject); $message = 'Coupon ' . $coupon->getCouponCode() . ' used {' . print_r($coupon->getData(), true) . '}'; $subject = "Coupon used"; Mage::getSingleton('followupemail/log')->logSuccess($message, $this, $subject); $coupons->setData($couponId, $coupon); } $objects['coupons'] = $coupons; } } $objects['has_coupon'] = isset($objects['coupon']); $queue = Mage::getModel('followupemail/queue'); $objects['sequence_number'] = $sequenceNumber; $objects['time_delay'] = (int) $timeDelay; $objects['time_delay_absolute'] = abs((int) $timeDelay); $objects['time_delay_text'] = Mage::helper('followupemail')->getTimeDelayText($timeDelay, 0, 0, $timeDelay < 0 ? -1 : 1); $code = AW_Followupemail_Helper_Data::getSecurityCode(); $objects['security_code'] = $code; $objects['url_resume'] = $objects['store']->getUrl('followupemail/index/resume', array('code' => $code)); $objects['url_unsubscribe'] = $objects['store']->getUrl('followupemail/index/unsubscribe', array('code' => $code)); /* Store logo init */ $objects['logo_url'] = Mage::helper('followupemail')->getLogoUrl($objects['store']->getStoreId()); $objects['logo_alt'] = Mage::helper('followupemail')->getLogoAlt($objects['store']->getStoreId()); if (!($content = $this->_getContent($objects, $templateId))) { $message = "rule id={$this->getId()} has invalid templateId=" . $templateId . " in sequenceNumber={$sequenceNumber}"; $subject = "Rule has invalid"; Mage::getSingleton('followupemail/log')->logError($message, $this, $subject); return false; } $storedParams = $params; unset($storedParams['object_id']); $queue->add($code, $sequenceNumber, $content['sender_name'], $content['sender_email'], $objects['customer_name'], $this->_isTest ? $this->getTestRecipient() : $objects['customer_email'], $this->getId(), time(), $content['subject'], $content['content'], $params['object_id'], $storedParams, $content['template_styles']); return true; } Mage::getSingleton('followupemail/log')->logWarning("rule id={$this->getId()} is not valid for birthday event of customerId={$params['customer_id']}, params=" . AW_Followupemail_Helper_Data::printParams($params), $this); return false; }
public function process($params, $objects = array(), $dateOffset = false) { $objects = $this->_createObjects($params, $objects); if (isset($objects['order']) && is_object($objects['order']) && $objects['order']->status) { $objects['order']->status = '"' . Mage::getSingleton('sales/order_config')->getStatusLabel($objects['order']->status) . '"'; } if (!$this->_validated) { $this->validate($objects); } if ($this->_isValid) { $message = 'rule id=' . $this->getId() . ' validation OK'; $subject = "validation OK"; Mage::getSingleton('followupemail/log')->logSuccess($message, $this, $subject); if (!($this->getChain() && count($chain = unserialize($this->getChain())))) { Mage::getSingleton('followupemail/log')->logWarning('rule id=' . $this->getId() . ' has no chain or the chain is empty: "' . $this->getChain() . '"', $this); return false; } if (Mage::getModel('followupemail/unsubscribe')->checkIsUnsubscribed($objects['store_id'], $objects['customer_id'], $objects['customer_email'], $this->getId())) { $message = 'Email canceled. The customer has unsubscribed from getting this email: customer id=' . $objects['customer_id'] . ' email=' . $objects['customer_email'] . ' rule id=' . $this->getId(); Mage::getSingleton('followupemail/log')->logWarning($message, $this); return false; } $queue = Mage::getModel('followupemail/queue'); $sequenceNumber = 1; foreach ($chain as $chainItem) { // Generate coupon if it needed if ($this->getCouponEnabled()) { unset($objects['has_coupon']); //get content of current email template $emailTemplate = $this->_getTemplate($chainItem['TEMPLATE_ID']); $emailTemplateContent = $emailTemplate['content']; // checking for presence standard coupon variable ( {{var coupon.code}}) $pattern2 = '|{{\\s*var\\s+coupon.code\\s*}}|u'; Mage::app()->getLocale()->emulate($objects['store_id']); $formatDate = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_LONG); if (preg_match_all($pattern2, $emailTemplateContent, $matches) > 0) { $coupon = Mage::helper('followupemail/coupon')->createNew($this, $chainItem['DAYS']); $message = 'New coupon ' . $coupon->getCouponCode() . ' is created {' . print_r($coupon->getData(), true) . '}'; $subject = "New coupon is created"; Mage::getSingleton('followupemail/log')->logSuccess($message, $this, $subject); $_dateStr = Mage::helper('core')->formatDate($coupon->getExpirationDate(), Mage_Core_Model_Locale::FORMAT_TYPE_LONG); $coupon->setExpirationDate(Mage::app()->getLocale()->date($_dateStr)->toString($formatDate)); $objects['coupon'] = $coupon; $message = 'Coupon ' . $coupon->getCouponCode() . ' used {' . print_r($coupon->getData(), true) . '}'; $subject = "Coupon used"; Mage::getSingleton('followupemail/log')->logSuccess($message, $this, $subject); } // checking for presence extended coupon variable ( {{var coupons.__ALIAS__.code}}) $pattern1 = '|{{\\s*var\\s+coupons.(.*).code\\s*}}|u'; if (preg_match_all($pattern1, $emailTemplateContent, $matches) > 0) { // using object for access to variables from AW_Followupemail_Model_Filter::filter() $coupons = new Varien_Object(); foreach ($matches[1] as $couponId) { $coupon = Mage::helper('followupemail/coupon')->createNew($this); $message = 'New coupon ' . $coupon->getCouponCode() . ' is created {' . print_r($coupon->getData(), true) . '}'; $subject = "New coupon is created"; Mage::getSingleton('followupemail/log')->logSuccess($message, $this, $subject); $message = 'Coupon ' . $coupon->getCouponCode() . ' used {' . print_r($coupon->getData(), true) . '}'; $subject = "Coupon used"; Mage::getSingleton('followupemail/log')->logSuccess($message, $this, $subject); $_dateStr = Mage::helper('core')->formatDate($coupon->getExpirationDate(), Mage_Core_Model_Locale::FORMAT_TYPE_LONG); $coupon->setExpirationDate(Mage::app()->getLocale()->date($_dateStr)->toString($formatDate)); $coupons->setData($couponId, $coupon); } $objects['coupons'] = $coupons; } Mage::app()->getLocale()->revert(); } $objects['has_coupon'] = isset($objects['coupon']); $objects['sequence_number'] = $sequenceNumber; $objects['time_delay'] = $chainItem['DAYS'] * 1440 + $chainItem['HOURS'] * 60 + $chainItem['MINUTES']; $objects['time_delay_text'] = Mage::helper('followupemail')->getTimeDelayText($chainItem['DAYS'], $chainItem['HOURS'], $chainItem['MINUTES']); $code = AW_Followupemail_Helper_Data::getSecurityCode(); $objects['security_code'] = $code; $objects['url_resume'] = $objects['store']->getUrl('followupemail/index/resume', array('code' => $code)); $objects['url_unsubscribe'] = $objects['store']->getUrl('followupemail/index/unsubscribe', array('code' => $code)); /* Store logo init */ $objects['logo_url'] = Mage::helper('followupemail')->getLogoUrl($objects['store']->getStoreId()); $objects['logo_alt'] = Mage::helper('followupemail')->getLogoAlt($objects['store']->getStoreId()); //------------------------------------------------------------------- //Check for cross-sells functionality active if ($this->getCrossActive()) { $objects['related'] = $this->_getCrossProducts($objects); } /** @var $productWishlistCollection Mage_Wishlist_Model_Resource_Product_Collection */ $wishlist = Mage::getModel('wishlist/wishlist')->loadByCustomer($objects['customer_id']); $productWishlistCollection = Mage::getResourceModel('wishlist/item_collection'); $productWishlistCollection->addWishlistFilter($wishlist); if (isset($objects['order'])) { $paymentBlock = Mage::helper('payment')->getInfoBlock($objects['order']->getPayment())->setIsSecureMode(true); $paymentBlock->getMethod()->setStore($objects['order']->getStoreId()); $objects['payment_html'] = $paymentBlock->toHtml(); } if ($dateOffset) { $dateOffset = strtotime($dateOffset); } else { $dateOffset = time(); } if (!($content = $this->_getContent($objects, $chainItem['TEMPLATE_ID']))) { $message = "rule id={$this->getId()} has invalid templateId=" . $chainItem['TEMPLATE_ID'] . " in sequenceNumber={$sequenceNumber}"; $subject = "Rule has invalid"; Mage::getSingleton('followupemail/log')->logError($message, $this, $subject); return false; } else { $testFlag = Mage::helper('followupemail')->__('TEST EMAIL '); $queue->add($code, $sequenceNumber, $content['sender_name'], $content['sender_email'], $objects['customer_name'], $this->_isTest ? $this->getTestRecipient() : $objects['customer_email'], $this->getId(), $dateOffset + $objects['time_delay'] * 60, $this->_isTest ? $testFlag . $content['subject'] : $content['subject'], $this->_isTest ? $testFlag . $content['content'] : $content['content'], $objects['object_id'], $params, $content['template_styles']); } $sequenceNumber++; } return true; } Mage::getSingleton('followupemail/log')->logWarning('rule id=' . $this->getId() . ' is not valid for event=' . $this->getEventType() . ' reason="' . $this->_validationMessage . '" objectId=' . (isset($objects['object_id']) ? $objects['object_id'] : 'none') . ', params="' . AW_Followupemail_Helper_Data::printParams($params), $this); return false; }
public function previewAction() { if ($id = $this->getRequest()->getParam('id')) { $email = Mage::getModel('followupemail/queue')->load($id); if (!$email->getId()) { Mage::getSingleton('adminhtml/session')->addError($this->__('Email does not longer exist')); $this->_redirect('*/*/'); return; } $rule = Mage::getModel('followupemail/rule')->load($email->getRuleId()); $from = Mage::getResourceModel('followupemail/queue')->getFromFields($email->getRuleId()); if (!isset($from['email_send_to_customer'])) { $from['email_send_to_customer'] = true; } if (!$from['email_send_to_customer'] && AW_Followupemail_Helper_Data::getCustomSMTPSettings() === false) { $_copyTo = Mage::helper('followupemail')->explodeEmailList($from['email_copy_to']); $_emailCopyTo = implode(', ', $_copyTo); } $this->getResponse()->setBody($this->getLayout()->createBlock('core/template')->setId($id)->setTemplate('followupemail/preview.phtml')->setSenderName($email->getSenderName())->setSenderEmail($email->getSenderEmail())->setRecipientName($email->getRecipientName())->setRecipientEmail($email->getRecipientEmail())->setSubject($email->getSubject())->setEmailCopyTo(isset($_emailCopyTo) ? $_emailCopyTo : $rule->getEmailCopyTo())->setContent($email->getContent())->setTemplateStyles($email->getTemplateStyles())->setStatus($email->getStatus())->toHtml()); } }