├── CHANGELOG.md ├── README.md ├── RESEARCH.md ├── app ├── code │ └── community │ │ └── Hackathon │ │ └── EmailPreview │ │ ├── Block │ │ └── Adminhtml │ │ │ ├── Email.php │ │ │ └── Email │ │ │ ├── Edit.php │ │ │ ├── Preview.php │ │ │ └── PreviewContent.php │ │ ├── Helper │ │ └── Data.php │ │ ├── Model │ │ ├── Data │ │ │ └── Form.php │ │ ├── EmailPreview.php │ │ ├── Mail │ │ │ └── Type │ │ │ │ ├── AccountEmail.php │ │ │ │ ├── Newsletter.php │ │ │ │ ├── PasswordEmail.php │ │ │ │ ├── ProductAlert │ │ │ │ ├── Abstract.php │ │ │ │ ├── PriceEmail.php │ │ │ │ └── StockEmail.php │ │ │ │ ├── RmaNew.php │ │ │ │ ├── Sales │ │ │ │ ├── Abstract.php │ │ │ │ ├── CreditmemoEmail.php │ │ │ │ ├── InvoiceEmail.php │ │ │ │ ├── OrderEmail.php │ │ │ │ └── ShipmentEmail.php │ │ │ │ ├── Sendfriend.php │ │ │ │ ├── ShareWishlistEmail.php │ │ │ │ ├── SitemapGenerateWarningsEmail.php │ │ │ │ └── TokenStatusChangeEmail.php │ │ └── Source │ │ │ └── Testtypes.php │ │ ├── controllers │ │ └── Adminhtml │ │ │ ├── PreviewController.php │ │ │ └── System │ │ │ └── Email │ │ │ └── TemplateController.php │ │ └── etc │ │ └── config.xml ├── design │ └── adminhtml │ │ └── default │ │ └── default │ │ └── layout │ │ └── hackathon_emailpreview.xml ├── etc │ └── modules │ │ └── Hackathon_EmailPreview.xml └── locale │ └── en_US │ └── Hackathon_EmailPreview │ └── Hackathon_EmailPreview.csv ├── composer.json └── modman /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | Changelog 2 | ========= 3 | 4 | Unreleased 5 | ----- 6 | 7 | Added / improved: 8 | 9 | * Previews are opened in a new browser window/tab (fixes #1). 10 | 11 | 1.0.0 (12.09.2014) 12 | ----- 13 | 14 | * Initial release 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Hackathon EmailPreview 2 | ====================== 3 | This extension enables the merchants and developers to preview mail templates from the backend with real data. 4 | 5 | Facts 6 | ----- 7 | - version: 1.0.0 8 | - extension key: Hackathon_EmailPreview 9 | - [extension on GitHub](https://github.com/magento-hackathon/E-MailPreview) 10 | 11 | Description 12 | ----------- 13 | This extension enables the merchants and developers to preview mail templates from the backend with real data. 14 | 15 | Requirements 16 | ------------ 17 | - PHP >= 5.2.0 18 | - Mage_Adminhtml 19 | 20 | Compatibility 21 | ------------- 22 | - Magento CE >= 1.7.0.2 (only tested on this version) 23 | 24 | Installation Instructions 25 | ------------------------- 26 | 1. Install the extension by copying the files into your Magento root or by using a modman compatible tool 27 | ([modman](https://github.com/colinmollenhour/modman), [Composer](http://getcomposer.org/)). 28 | 2. Clear the cache, logout from the admin panel and then login again. 29 | 30 | Uninstallation 31 | -------------- 32 | 1. Remove the extension by removing the files. 33 | 34 | Usage 35 | ----- 36 | 37 | The functionality can be used in the backend section `System > Transactional Emails`. 38 | 39 | * Click on a template in the transaction email grid and navigate to the `Preview Email` tab. 40 | * Choose the `Template type`. This is necessary because an e-mail template is not fixed to a certain template type. For 41 | example you load a `New account` template and select the `Template type` `New account`. 42 | * Unfortunately, you have do use common sense to find out which data are necessary for which template at the moment. It 43 | doesn't harm if you enter more data than necessary so if you're in doubt fill in more fields. 44 | 45 | Extending 46 | --------- 47 | 48 | ### Extending existing mail templates 49 | If you introduce new variables into existing mail templates, you have to provide Magento with actual models (ie. orders, 50 | customers, ...). 51 | 52 | You can do so by observing the `hackathon_emailpreview_render_email_before` event. You will be provided with: 53 | 54 | * `templateType`. Use the template type to decide if you have to modify the parameters for this type of template. 55 | * `templateParams`. This `Varien_Object` contains the parameters (ie. variables like orders, customers, ...) that will be passed to the mail template renderer. 56 | 57 | Adding a customer with real data as a template parameter looks like this: 58 | 59 | $templateParams = $observer->getEvent()->getData('templateParams'); 60 | $requestParams = $templateParams->getRequestParams(); 61 | $customerId = $requestParams['customerId']; 62 | $customer = Mage::getModel('customer/customer')->load($customerId); 63 | $templateParams->setCustomer($customer); 64 | 65 | Support 66 | ------- 67 | If you have any issues with this extension, open an issue on [GitHub](https://github.com/magento-hackathon/E-MailPreview/issues). 68 | 69 | Contribution 70 | ------------ 71 | Any contribution is highly appreciated. The best way to contribute code is to open a 72 | [pull request on GitHub](https://help.github.com/articles/using-pull-requests). 73 | 74 | Developer 75 | --------- 76 | * Matthias Zeis 77 | 78 | [http://www.matthias-zeis.com](http://www.matthias-zeis.com) 79 | 80 | [@mzeis](https://twitter.com/mzeis) 81 | 82 | * Marc Päpper 83 | 84 | [http://www.lemundo.de](http://www.lemundo.de) 85 | 86 | [@mpaepper](https://twitter.com/mpaepper) 87 | 88 | * Tobias Hille 89 | 90 | License 91 | ------- 92 | [OSL - Open Software Licence 3.0](http://opensource.org/licenses/osl-3.0.php) 93 | -------------------------------------------------------------------------------- /RESEARCH.md: -------------------------------------------------------------------------------- 1 | # Research 2 | 3 | Research notes for the implementation of this extension. 4 | 5 | ## E-mail templates 6 | 7 | ### Contact Form 8 | 9 | 10 | ### DONE: Credit Memo Update 11 | 12 | * Used in model sales/order_creditmemo in method sendUpdateEmail($notifyCustomer = true, $comment = '') 13 | * Variables: 14 | * 'order' => $order 15 | * 'creditmemo' => $creditmemo 16 | * 'comment' => $comment 17 | * 'billing' => $order->getBillingAddress() 18 | * Special: 19 | * In method, customer email address is retrieved from order: $order->getCustomerEmail() 20 | 21 | 22 | ### DONE: Credit Memo Update for Guest 23 | 24 | * Same as Credit Memo Update, method selects template depending on $order->getCustomerIsGuest() 25 | 26 | ### Currency Update Warnings 27 | 28 | 29 | ### Forgot Admin Password 30 | 31 | 32 | ### DONE: Forgot Password 33 | * Template file: account_password_reset_confirmation.html 34 | * Template type: html 35 | * Method: Mage_Customer_Model_Customer::sendPasswordResetConfirmationEmail() 36 | * Template params: 37 | - customer (Mage_Customer_Model_Customer) 38 | Shouldn't be a problem, just provide the customer object. 39 | 40 | ### DONE: Invoice Update 41 | 42 | * Used in model sales/order_invoice in method sendUpdateEmail($notifyCustomer = true, $comment = '') 43 | * Variables: 44 | * 'order' => $order 45 | * 'invoice' => $invoice 46 | * 'comment' => $comment 47 | * 'billing' => $order->getBillingAddress() 48 | * Special: 49 | * In method, customer email address is retrieved from order: $order->getCustomerEmail() 50 | 51 | ### DONE: Invoice Update for Guest 52 | 53 | * Same as Invoice update, the method checks whether customer is guest by $order->getCustomerIsGuest() 54 | 55 | ### Log cleanup Warnings 56 | 57 | 58 | ### Moneybookers activate email 59 | 60 | 61 | ### DONE: New Credit Memo 62 | 63 | * Used in model sales/order_creditmemo in method sendEmail($notifyCustomer = true, $comment = '') 64 | * Variables: 65 | * 'order' => $order 66 | * 'creditmemo' => $creditmemo 67 | * 'comment' => $comment 68 | * 'billing' => $order->getBillingAddress() 69 | * 'payment_html' => $paymentBlockHtml 70 | * Special: 71 | * The payment block is generated in the method using the store emulation 72 | * In method, customer email address is retrieved from order: $order->getCustomerEmail() 73 | 74 | ### DONE: New Credit Memo for Guest 75 | 76 | * Same as New Credit Memo, the method checks whether customer is guest by $order->getCustomerIsGuest() 77 | 78 | ### DONE: New Invoice 79 | 80 | * Used in model sales/order_invoice in method sendEmail($notifyCustomer = true, $comment = '') 81 | * Variables: 82 | * 'order' => $order 83 | * 'invoice' => $invoice 84 | * 'comment' => $comment 85 | * 'billing' => $order->getBillingAddress() 86 | * 'payment_html' => $paymentBlockHtml 87 | * Special: 88 | * The payment block is generated in the method using the store emulation 89 | * In method, customer email address is retrieved from order: $order->getCustomerEmail() 90 | 91 | ### DONE: New Invoice for Guest 92 | 93 | * Same as New Invoice, the method checks whether customer is guest by $order->getCustomerIsGuest() 94 | 95 | ### DONE: New Order 96 | 97 | * Used in model sales/order in method sendNewOrderEmail() 98 | * Variables: 99 | * 'order' => $order, 100 | * 'billing' => $order->getBillingAddress(), 101 | * 'payment_html' => $paymentBlockHtml 102 | * Special: 103 | * The payment block is generated in the method using the store emulation 104 | * In method, customer email address is retrieved from order: $order->getCustomerEmail() 105 | 106 | 107 | ### DONE: New Order for Guest 108 | 109 | * Same as New Order, the method checks whether customer is guest by $order->getCustomerIsGuest() 110 | 111 | ### DONE: New Shipment 112 | 113 | * Used in model sales/order_shipment in method sendEmail($notifyCustomer = true, $comment = '') 114 | * Variables: 115 | * 'order' => $order 116 | * 'shipment' => $shipment 117 | * 'comment' => $comment 118 | * 'billing' => $order->getBillingAddress() 119 | * 'payment_html' => $paymentBlockHtml 120 | * Special: 121 | * The payment block is generated in the method using the store emulation 122 | * In method, customer email address is retrieved from order: $order->getCustomerEmail() 123 | 124 | ### DONE: New Shipment for Guest 125 | 126 | * Same as New Shipment, the method checks whether customer is guest by $order->getCustomerIsGuest() 127 | 128 | ### DONE: New account 129 | * Template file: account_new.html 130 | * Template type: html 131 | * Method: Mage_Customer_Model_Customer::sendNewAccountEmail() 132 | * Template params: 133 | - customer (Mage_Customer_Model_Customer) 134 | - backUrl (String, default '') 135 | Shouldn't be a problem, just provide the customer object. 136 | 137 | ### DONE: New account confirmation key 138 | * Template file: account_new_confirmation.html 139 | * Template type: html 140 | * Method: Mage_Customer_Model_Customer::sendNewAccountEmail() 141 | * Template params: 142 | - customer (Mage_Customer_Model_Customer) 143 | - backUrl (String, default '') 144 | Shouldn't be a problem, just provide the customer object. 145 | 146 | ### DONE: New account confirmed 147 | * Template file: account_new_confirmed.html 148 | * Template type: html 149 | * Method: Mage_Customer_Model_Customer::sendNewAccountEmail() 150 | * Template params: 151 | - customer (Mage_Customer_Model_Customer) 152 | - backUrl (String, default '') 153 | Shouldn't be a problem, just provide the customer object. 154 | 155 | ### DONE:Newsletter subscription confirmation 156 | * Template file: newsletter_subscr_confirm.html 157 | * Template type: html 158 | * Method: Mage_Newsletter_Model_Subscriber::sendConfirmationRequestEmail() 159 | * Template params: 160 | - subscriber (Mage_Newsletter_Model_Subscriber) 161 | * Notes: 162 | - inline translation disabled while sending mail 163 | - does getProcessedTemplate() get called at all? 164 | 165 | ### DONE:Newsletter subscription success 166 | * Template file: newsletter_subscr_success.html 167 | * Template type: html 168 | * Method: Mage_Newsletter_Model_Subscriber::sendConfirmationSuccessEmail() 169 | * Template params: 170 | - subscriber (Mage_Newsletter_Model_Subscriber) 171 | * Notes: 172 | - inline translation disabled while sending mail 173 | - does getProcessedTemplate() get called at all? 174 | 175 | ### DONE:Newsletter unsubscription success 176 | * Template file: newsletter_unsub_success.html 177 | * Template type: html 178 | * Method: Mage_Newsletter_Model_Subscriber::sendUnsubscriptionEmail() 179 | * Template params: 180 | - subscriber (Mage_Newsletter_Model_Subscriber) 181 | * Notes: 182 | - inline translation disabled while sending mail 183 | - does getProcessedTemplate() get called at all? 184 | 185 | ### DONE: Order Update 186 | 187 | * Used in model sales/order in method sendOrderUpdateEmail($notifyCustomer = true, $comment = '') 188 | * Variables: 189 | * 'order' => $order 190 | * 'billing' => $order->getBillingAddress() 191 | * 'payment_html' => $paymentBlockHtml 192 | * Special: 193 | * In method, customer email address is retrieved from order: $order->getCustomerEmail() 194 | 195 | ### DONE: Order Update for Guest 196 | 197 | * Same as Order Update, the method checks whether customer is guest by $order->getCustomerIsGuest() 198 | 199 | 200 | ### Payment Failed 201 | 202 | 203 | ### Product alerts Cron error 204 | 205 | 206 | ### DONE: Product price alert 207 | * Template file: product_price_alert.html 208 | * Template type: html 209 | * Method: Mage_ProductAlert_Model_Email::send() 210 | * Template params: 211 | * 'customerName' => $this->_customer->getName(), 212 | * 'alertGrid' => $block 213 | 214 | ### DONE: Product stock alert 215 | * Template file: product_stock_alert.html 216 | * Template type: html 217 | * Method: Mage_ProductAlert_Model_Email::send() 218 | * Template params: 219 | * 'customerName' => $this->_customer->getName(), 220 | * 'alertGrid' => $block 221 | 222 | 223 | ### DONE: Remind Password 224 | * Template file: password_new.html 225 | * Template type: html 226 | * Method: Mage_Customer_Model_Customer::sendPasswordReminderEmail() 227 | * Template params: 228 | * customer (Mage_Customer_Model_Customer) 229 | Shouldn't be a problem, just provide the customer object. 230 | 231 | ### DONE: Send product to a friend 232 | 233 | * Used in model sendfriend/sendfriend in method send() 234 | * Variables: 235 | * 'name' => $name 236 | * 'email' => $email 237 | * 'product_name' => $this->getProduct()->getName() 238 | * 'product_url' => $this->getProduct()->getUrlInStore() 239 | * 'message' => $message 240 | * 'sender_name' => $sender['name'] 241 | * 'sender_email' => $sender['email'] 242 | * 'product_image' => Mage::helper('catalog/image')->init($this->getProduct(), 'small_image')->resize(75) 243 | 244 | 245 | ### DONE: Share Wishlist 246 | * Template file: wishlist_share.html 247 | * Template type: html 248 | * Method: Mage_Wishlist_controllers_IndexController::sendAction() 249 | * Template params: 250 | - 'customer' => $customer, 251 | - 'salable' => $wishlist->isSalable() ? 'yes' : '', 252 | - 'items' => $wishlistBlock, 253 | - 'addAllLink' => Mage::getUrl('*/shared/allcart', array('code' => $sharingCode)), 254 | - 'viewOnSiteLink' => Mage::getUrl('*/shared/index', array('code' => $sharingCode)), 255 | - 'message' => $message 256 | 257 | ### DONE: Shipment Update 258 | 259 | * Used in model sales/order_shipment in method sendUpdateEmail($notifyCustomer = true, $comment = '') 260 | * Variables: 261 | * 'order' => $order 262 | * 'shipment' => $shipment 263 | * 'comment' => $comment 264 | * 'billing' => $order->getBillingAddress() 265 | * Special: 266 | * In method, customer email address is retrieved from order: $order->getCustomerEmail() 267 | 268 | ### DONE: Shipment Update for Guest 269 | 270 | * Same as Shipment Update, the method checks whether customer is guest by $order->getCustomerIsGuest() 271 | 272 | ### DONE: Sitemap generate Warnings 273 | * Template file: sitemap_generate_warning.html 274 | * Template type: text 275 | * Method: Mage_Sitemap_Model_Observer::scheduledGenerateSitemaps() 276 | * Template params: 277 | - 'warnings' => join("\n", $errors) 278 | 279 | ### DONE: Token Status Change 280 | * Template file: token.html 281 | * Template type: html 282 | * Method: Mage_Oauth_Helper_Data::sendNotificationOnTokenStatusChange() 283 | * Template params: 284 | * 'name' => $userName // @var string 285 | * 'userName' => $userName // @var string 286 | * 'email' => $userEmail // @var string 287 | * 'applicationName' => $applicationName // @var string 288 | * 'status' => $status // @var string 289 | 290 | ## Necessary parameters 291 | 292 | * customerId 293 | - test_product_price_alert_email_template 294 | - test_product_stock_alert_email_template 295 | - test_new_account_email_template 296 | - test_new_account_confirmation_key_email_template 297 | - test_new_account_confirmed_email_template 298 | - test_forgot_password_email_template 299 | - test_remind_password_email_template 300 | - test_share_wishlist_email_template 301 | * incrementId (Order) 302 | - test_sales_order_creditmemo_email_template 303 | - test_sales_order_creditmemo_update_email_template 304 | - test_sales_order_invoice_email_template 305 | - test_sales_order_invoice_update_email_template 306 | - test_sales_order_email_template 307 | - test_sales_order_update_email_template 308 | - test_sales_order_shipment_email_template 309 | - test_sales_order_shipment_update_email_template 310 | * comment (optional) 311 | - test_sales_order_creditmemo_email_template 312 | - test_sales_order_creditmemo_update_email_template 313 | - test_sales_order_invoice_email_template 314 | - test_sales_order_invoice_update_email_template 315 | - test_sales_order_email_template 316 | - test_sales_order_update_email_template 317 | - test_sales_order_shipment_email_template 318 | - test_sales_order_shipment_update_email_template 319 | * fromName 320 | - test_sendfriend_email_template 321 | * fromEmail 322 | - test_sendfriend_email_template 323 | * toName 324 | - test_sendfriend_email_template 325 | * toEmail 326 | - test_sendfriend_email_template 327 | * message 328 | - test_sendfriend_email_template 329 | * productSku 330 | - test_sendfriend_email_template 331 | * wishlistId 332 | - test_share_wishlist_email_template 333 | * (kein Parameter) 334 | - test_newsleter_subscribe_email_template 335 | - test_newsletter_subscribe_success_email_template 336 | - test_newsletter_unsubscribe_success_email_templates 337 | - test_sitemap_generate_warnings_email_template 338 | - test_token_status_change_email_template 339 | -------------------------------------------------------------------------------- /app/code/community/Hackathon/EmailPreview/Block/Adminhtml/Email.php: -------------------------------------------------------------------------------- 1 | unsetChild('preview_button'); 13 | } 14 | 15 | public function __construct() 16 | { 17 | parent::__construct(); 18 | } 19 | 20 | public function getTabLabel() 21 | { 22 | return $this->helper("hackathon_emailpreview")->__("Edit Email"); 23 | } 24 | 25 | public function getTabTitle() 26 | { 27 | return $this->helper("hackathon_emailpreview")->__("Edit Email"); 28 | } 29 | 30 | public function canShowTab() 31 | { 32 | return true; 33 | } 34 | 35 | public function isHidden() 36 | { 37 | return false; 38 | } 39 | } -------------------------------------------------------------------------------- /app/code/community/Hackathon/EmailPreview/Block/Adminhtml/Email/Preview.php: -------------------------------------------------------------------------------- 1 | _blockGroup = 'hackathon_emailpreview'; 11 | $this->_controller = 'adminhtml_form'; 12 | $this->_headerText = Mage::helper('hackathon_emailpreview')->__('Edit Form'); 13 | 14 | parent::__construct(); 15 | 16 | self::_prepareForm(); 17 | } 18 | 19 | protected function _prepareForm() 20 | { 21 | $form = new Hackathon_EmailPreview_Model_Data_Form( 22 | array( 23 | 'id' => 'edit_form', 24 | 'action' => $this->getUrl('*/preview/index'), 25 | 'method' => 'post', 26 | 'target' => '_blank' 27 | ) 28 | ); 29 | 30 | $form->setUseContainer(true); 31 | $this->setForm($form); 32 | 33 | $helper = Mage::helper('hackathon_emailpreview'); 34 | $fieldset = $form->addFieldset('display', array( 35 | 'legend' => $helper->__('Preview with Data'), 36 | 'class' => 'entry-edit-head', 37 | )); 38 | 39 | $templateId = Mage::app()->getRequest()->getParam('id', false); 40 | $fieldset->addField('templateId', 'hidden', array( 41 | 'name' => 'templateId', 42 | 'label' => $helper->__('Template Type'), 43 | 'value' => $templateId 44 | )); 45 | 46 | $fieldset->addField('templateType', 'select', array( 47 | 'name' => 'templateType', 48 | 'options' => Mage::getModel('hackathon_emailpreview/source_testtypes')->toOptionArray(), 49 | 'label' => $helper->__('Template Type'), 50 | )); 51 | 52 | $fieldset->addField('incrementId', 'text', array( 53 | 'name' => 'incrementId', 54 | 'label' => $helper->__('Increment ID'), 55 | )); 56 | 57 | $fieldset->addField('customerId', 'text', array( 58 | 'name' => 'customerId', 59 | 'label' => $helper->__('Customer ID'), 60 | )); 61 | 62 | $fieldset->addField('storeId', 'select', array( 63 | 'name' => 'storeId', 64 | 'label' => $helper->__('Store ID'), 65 | 'title' => $helper->__('Store ID'), 66 | 'values' => Mage::getModel('adminhtml/system_config_source_store')->toOptionArray(), 67 | )); 68 | 69 | $fieldset->addField('comment', 'text', array( 70 | 'name' => 'comment', 71 | 'label' => $helper->__('Comment'), 72 | )); 73 | 74 | $fieldset->addField('fromName', 'text', array( 75 | 'name' => 'fromName', 76 | 'label' => $helper->__('From Name'), 77 | )); 78 | 79 | $fieldset->addField('fromEmail', 'text', array( 80 | 'name' => 'fromEmail', 81 | 'label' => $helper->__('From Email'), 82 | )); 83 | 84 | $fieldset->addField('toName', 'text', array( 85 | 'name' => 'toName', 86 | 'label' => $helper->__('To Name'), 87 | )); 88 | 89 | $fieldset->addField('toEmail', 'text', array( 90 | 'name' => 'toEmail', 91 | 'label' => $helper->__('To Email'), 92 | )); 93 | 94 | $fieldset->addField('message', 'text', array( 95 | 'name' => 'message', 96 | 'label' => $helper->__('Message'), 97 | )); 98 | $fieldset->addField('productSku', 'text', array( 99 | 'name' => 'productSku', 100 | 'label' => $helper->__('Product SKU'), 101 | )); 102 | $fieldset->addField('wishlistId', 'text', array( 103 | 'name' => 'wishlistId', 104 | 'label' => $helper->__('Wishlist ID'), 105 | )); 106 | 107 | $fieldset->addField('previewbutton', 'submit', array( 108 | 'name' => 'previewbutton', 109 | 'class' => 'scalable form-button', 110 | 'value' => $helper->__('Preview with Data'), 111 | )); 112 | 113 | if (Mage::registry('hackathon_emailpreview')) { 114 | $form->setValues(Mage::registry('hackathon_emailpreview')->getData()); 115 | } 116 | 117 | return parent::_prepareForm(); 118 | } 119 | 120 | public function getTabLabel() 121 | { 122 | return $this->helper("hackathon_emailpreview")->__("Preview Email"); 123 | } 124 | 125 | public function getTabTitle() 126 | { 127 | return $this->helper("hackathon_emailpreview")->__("Preview Email"); 128 | } 129 | 130 | public function canShowTab() 131 | { 132 | return true; 133 | } 134 | 135 | public function isHidden() 136 | { 137 | return false; 138 | } 139 | 140 | } 141 | -------------------------------------------------------------------------------- /app/code/community/Hackathon/EmailPreview/Block/Adminhtml/Email/PreviewContent.php: -------------------------------------------------------------------------------- 1 | getRequest()->getParam('storeId'); 12 | $appEmulation = Mage::getSingleton('core/app_emulation'); 13 | $initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($storeId); 14 | Mage::app()->getTranslator()->init('frontend', true); 15 | 16 | $previewModel = Mage::getModel('hackathon_emailpreview/emailPreview'); 17 | 18 | $templateId = $this->getRequest()->getParam('templateId'); 19 | $templateType = $this->getRequest()->getParam('templateType'); 20 | 21 | $templateParams = new Varien_Object(); 22 | $templateParams->setRequestParams($this->getRequest()->getParams()); 23 | $templateParams->setStoreId($storeId); 24 | 25 | $eventData = array( 26 | 'templateParams' => $templateParams, 27 | 'templateType' => $templateType 28 | ); 29 | 30 | Mage::dispatchEvent('hackathon_emailpreview_render_email_before', $eventData); 31 | 32 | $storeId = $templateParams->getStoreId(); 33 | $templateParams->setStore(Mage::app()->getStore($storeId)); 34 | 35 | $html = $previewModel->renderEmail($templateId, $templateParams->getData()); 36 | 37 | Mage::app()->getTranslator()->init('frontend', false); 38 | $appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo); 39 | 40 | return $html; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /app/code/community/Hackathon/EmailPreview/Helper/Data.php: -------------------------------------------------------------------------------- 1 | getStoreId(); 17 | $initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($storeId); 18 | 19 | $template = Mage::getModel('core/email_template'); 20 | $template->load($templateId); 21 | 22 | /* @var $filter Mage_Core_Model_Input_Filter_MaliciousCode */ 23 | $filter = Mage::getSingleton('core/input_filter_maliciousCode'); 24 | 25 | $template->setTemplateText( 26 | $filter->filter($template->getTemplateText()) 27 | ); 28 | 29 | $templateProcessed = $template->getProcessedTemplate($templateParams, true); 30 | 31 | if ($template->isPlain()) { 32 | $templateProcessed = "
" . htmlspecialchars($templateProcessed) . ""; 33 | } 34 | 35 | // Stop store emulation process 36 | $appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo); 37 | 38 | return $templateProcessed; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /app/code/community/Hackathon/EmailPreview/Model/Mail/Type/AccountEmail.php: -------------------------------------------------------------------------------- 1 | getEvent()->getData('templateType'), array(self::TYPE_NEW_ACCOUNT, self::TYPE_NEW_ACCOUNT_CONFIRMATION_KEY, self::TYPE_NEW_ACCOUNT_CONFIRMATED))) { 16 | return $this; 17 | } 18 | 19 | $templateParams = $observer->getEvent()->getData('templateParams'); 20 | $requestParams = $templateParams->getRequestParams(); 21 | $customerId = $requestParams['customerId']; 22 | $customer = Mage::getModel('customer/customer')->load($customerId); 23 | $customer->setPassword(Mage::helper('hackathon_emailpreview')->__('[yourpasswordhere]')); 24 | $templateParams->setCustomer($customer); 25 | $templateParams->setBackUrl(''); 26 | 27 | return $this; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /app/code/community/Hackathon/EmailPreview/Model/Mail/Type/Newsletter.php: -------------------------------------------------------------------------------- 1 | getEvent()->getData('templateType'), 16 | array(self::TYPE_NEWSLETTER_CONFIRM, 17 | self::TYPE_NEWSLETTER_SUBSCRIBE_SUCCESS, 18 | self::TYPE_NEWSLETTER_UNSUBSCRIBE_SUCCESS))) { 19 | return $this; 20 | } 21 | 22 | $templateParams = $observer->getEvent()->getData('templateParams'); 23 | $subscriber = Mage::getModel('newsletter/subscriber'); 24 | $templateParams->setSubscriber($subscriber); 25 | 26 | return $this; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /app/code/community/Hackathon/EmailPreview/Model/Mail/Type/PasswordEmail.php: -------------------------------------------------------------------------------- 1 | getEvent()->getData('templateType'), array(self::TYPE_FORGOT_PASSWORD, self::TYPE_REMIND_PASSWORD))) { 15 | return $this; 16 | } 17 | 18 | $templateParams = $observer->getEvent()->getData('templateParams'); 19 | $requestParams = $templateParams->getRequestParams(); 20 | $customerId = $requestParams['customerId']; 21 | $customer = Mage::getModel('customer/customer')->load($customerId); 22 | $customer->setPassword(Mage::helper('hackathon_emailpreview')->__('[yourpasswordhere]')); 23 | $templateParams->setCustomer($customer); 24 | 25 | return $this; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /app/code/community/Hackathon/EmailPreview/Model/Mail/Type/ProductAlert/Abstract.php: -------------------------------------------------------------------------------- 1 | getEvent()->getData('templateType') !== $this->_getType()) { 26 | return $this; 27 | } 28 | 29 | // Create customer 30 | $templateParams = $observer->getEvent()->getData('templateParams'); 31 | $requestParams = $templateParams->getRequestParams(); 32 | $customerId = $requestParams['customerId']; 33 | $customer = Mage::getModel('customer/customer')->load($customerId); 34 | $customerName = $customer->getName(); 35 | 36 | $templateParams = $observer->getEvent()->getData('templateParams'); 37 | $templateParams->setData('customerName', $customerName); 38 | $templateParams->setData('alertGrid', $this->_getBlockHtml($templateParams->getStoreId(), $customer->getGroupId())); 39 | 40 | return $this; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /app/code/community/Hackathon/EmailPreview/Model/Mail/Type/ProductAlert/PriceEmail.php: -------------------------------------------------------------------------------- 1 | createBlock('productalert/email_price'); 15 | $block->setStore($storeId)->reset(); 16 | $product = Mage::getModel('catalog/product')->getCollection()->addPriceData()->getFirstItem(); 17 | $product->setCustomerGroupId($customerGroupId); 18 | $productPrice = $product->getFinalPrice(); 19 | $product->setFinalPrice(Mage::helper('tax')->getPrice($product, $productPrice)); 20 | $product->setPrice(Mage::helper('tax')->getPrice($product, $product->getPrice())); 21 | $block->addProduct($product); 22 | 23 | return $block->toHtml(); 24 | } 25 | 26 | /** 27 | * Returns the template type. 28 | * 29 | * @return string 30 | */ 31 | protected function _getType() 32 | { 33 | return self::TYPE; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /app/code/community/Hackathon/EmailPreview/Model/Mail/Type/ProductAlert/StockEmail.php: -------------------------------------------------------------------------------- 1 | createBlock('productalert/email_stock'); 15 | $block->setStore($storeId)->reset(); 16 | 17 | $product = Mage::getModel('catalog/product')->getCollection()->addPriceData()->getFirstItem(); 18 | $product->setCustomerGroupId($customerGroupId); 19 | $productPrice = $product->getFinalPrice(); 20 | $product->setFinalPrice(Mage::helper('tax')->getPrice($product, $productPrice)); 21 | $product->setPrice(Mage::helper('tax')->getPrice($product, $product->getPrice())); 22 | $block->addProduct($product); 23 | 24 | return $block->toHtml(); 25 | } 26 | 27 | /** 28 | * Returns the template type. 29 | * 30 | * @return string 31 | */ 32 | protected function _getType() 33 | { 34 | return self::TYPE; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /app/code/community/Hackathon/EmailPreview/Model/Mail/Type/RmaNew.php: -------------------------------------------------------------------------------- 1 | getEvent()->getData('templateType'), array(self::TYPE_RMA_NEW, self::TYPE_RMA_AUTH))) { 15 | return $this; 16 | } 17 | 18 | $this->_prepareParams($observer, 'enterprise_rma/rma'); 19 | 20 | return $this; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /app/code/community/Hackathon/EmailPreview/Model/Mail/Type/Sales/Abstract.php: -------------------------------------------------------------------------------- 1 | getStore()->getStoreId(); 12 | 13 | try { 14 | // Retrieve specified view block from appropriate design package (depends on emulated store) 15 | $paymentBlock = Mage::helper('payment')->getInfoBlock($order->getPayment()) 16 | ->setIsSecureMode(true); 17 | $paymentBlock->getMethod()->setStore($storeId); 18 | $paymentBlockHtml = $paymentBlock->toHtml(); 19 | } catch (Exception $exception) { 20 | throw $exception; 21 | } 22 | 23 | return $paymentBlockHtml; 24 | } 25 | 26 | /** 27 | * Prepare the parameters for the email 28 | * 29 | * @param Varien_Event_Observer $observer 30 | * @param type $modelName 31 | * @param type $entityTemplateName 32 | * @return array($entity, $templateParams) 33 | */ 34 | protected function _prepareParams(Varien_Event_Observer $observer, $modelName, $entityTemplateName = null) 35 | { 36 | $templateParams = $observer->getEvent()->getData('templateParams'); 37 | $requestParams = $templateParams->getRequestParams(); 38 | 39 | $incrementId = $requestParams['incrementId']; 40 | 41 | $entity = $this->_loadEntityByIncrementId($modelName, $incrementId); 42 | 43 | $order = $this->_loadOrderFrom($entity); 44 | 45 | $templateParams->setStoreId($order->getStore()->getStoreId()); 46 | 47 | $templateParams->setOrder($order); 48 | $templateParams->setBilling($order->getBillingAddress()); 49 | $paymentBlockHtml = $this->_getPaymentBlockHtmlFrom($order); 50 | $templateParams->setPaymentHtml($paymentBlockHtml); 51 | 52 | if (isset($requestParams['comment'])) { 53 | $templateParams->setComment($requestParams['comment']); 54 | } 55 | 56 | if (!empty($entityTemplateName)) { 57 | $templateParams->setData($entityTemplateName, $entity); 58 | } 59 | 60 | return array($entity, $templateParams); 61 | } 62 | 63 | /** 64 | * Load the the main email entity by its increment id 65 | */ 66 | protected function _loadEntityByIncrementId($modelName, $incrementId) 67 | { 68 | return Mage::getModel($modelName)->load($incrementId, 'increment_id'); 69 | } 70 | 71 | /** 72 | * Load the order from the main email entity 73 | */ 74 | protected function _loadOrderFrom($entity) 75 | { 76 | if ($entity instanceof Mage_Sales_Model_Order) { 77 | return $entity; 78 | } else { 79 | return $entity->getOrder(); 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /app/code/community/Hackathon/EmailPreview/Model/Mail/Type/Sales/CreditmemoEmail.php: -------------------------------------------------------------------------------- 1 | getEvent()->getData('templateType') !== self::TYPE_NEW && 16 | $observer->getEvent()->getData('templateType') !== self::TYPE_UPDATE) { 17 | return $this; 18 | } 19 | 20 | $this->_prepareParams($observer, 'sales/order_creditmemo', 'creditmemo'); 21 | 22 | return $this; 23 | } 24 | } -------------------------------------------------------------------------------- /app/code/community/Hackathon/EmailPreview/Model/Mail/Type/Sales/InvoiceEmail.php: -------------------------------------------------------------------------------- 1 | getEvent()->getData('templateType') !== self::TYPE_NEW && 16 | $observer->getEvent()->getData('templateType') !== self::TYPE_UPDATE) { 17 | return $this; 18 | } 19 | 20 | $this->_prepareParams($observer, 'sales/order_invoice', 'invoice'); 21 | 22 | return $this; 23 | } 24 | } -------------------------------------------------------------------------------- /app/code/community/Hackathon/EmailPreview/Model/Mail/Type/Sales/OrderEmail.php: -------------------------------------------------------------------------------- 1 | getEvent()->getData('templateType') !== self::TYPE_NEW && 16 | $observer->getEvent()->getData('templateType') !== self::TYPE_UPDATE) { 17 | return $this; 18 | } 19 | 20 | $this->_prepareParams($observer, 'sales/order'); 21 | 22 | return $this; 23 | } 24 | } -------------------------------------------------------------------------------- /app/code/community/Hackathon/EmailPreview/Model/Mail/Type/Sales/ShipmentEmail.php: -------------------------------------------------------------------------------- 1 | getEvent()->getData('templateType') !== self::TYPE_NEW && 16 | $observer->getEvent()->getData('templateType') !== self::TYPE_UPDATE) { 17 | return $this; 18 | } 19 | 20 | $this->_prepareParams($observer, 'sales/order_shipment', 'shipment'); 21 | 22 | return $this; 23 | } 24 | } -------------------------------------------------------------------------------- /app/code/community/Hackathon/EmailPreview/Model/Mail/Type/Sendfriend.php: -------------------------------------------------------------------------------- 1 | getEvent()->getData('templateType'), array(self::TYPE_SENDFRIEND))) { 14 | return $this; 15 | } 16 | 17 | $templateParams = $observer->getEvent()->getData('templateParams'); 18 | $requestParams = $templateParams->getRequestParams(); 19 | $fromName = $requestParams['fromName']; 20 | $fromEmail = $requestParams['fromEmail']; 21 | $toName = $requestParams['toName']; 22 | $toEmail = $requestParams['toEmail']; 23 | $message = $requestParams['message']; 24 | $productSku = $requestParams['productSku']; 25 | $product = Mage::getModel('catalog/product')->loadByAttribute('sku', $productSku); 26 | $productName = $product->getName(); 27 | $productUrl = $product->getUrlInStore(); 28 | $productImage = Mage::helper('catalog/image')->init($product, 'small_image')->resize(75); 29 | $templateParams->setName($toName); 30 | $templateParams->setEmail($toEmail); 31 | $templateParams->setProductName($productName); 32 | $templateParams->setProductUrl($productUrl); 33 | $templateParams->setMessage($message); 34 | $templateParams->setSenderName($fromName); 35 | $templateParams->setData('sender_email', $fromEmail); 36 | $templateParams->setProductImage($productImage); 37 | 38 | return $this; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /app/code/community/Hackathon/EmailPreview/Model/Mail/Type/ShareWishlistEmail.php: -------------------------------------------------------------------------------- 1 | getEvent()->getData('templateType') !== self::TYPE) { 14 | return $this; 15 | } 16 | 17 | // Create customer 18 | $templateParams = $observer->getEvent()->getData('templateParams'); 19 | $requestParams = $templateParams->getRequestParams(); 20 | $customerId = $requestParams['customerId']; 21 | $customer = Mage::getModel('customer/customer')->load($customerId); 22 | 23 | // Create wishlist 24 | $wishlistId = $requestParams['wishlistId']; 25 | $wishlist = Mage::getModel('wishlist/wishlist')->loadByCustomer($customer); 26 | 27 | /* 28 | * Create wishlist block. We add the wishlist to the registry because the block class (and its helper) 29 | * look at the registry in the first place. 30 | */ 31 | $originalWishlist = Mage::registry('shared_wishlist'); 32 | Mage::register('shared_wishlist', $wishlist, true); 33 | $wishlistBlock = Mage::getSingleton('core/layout')->createBlock('wishlist/share_email_items')->toHtml(); 34 | Mage::register('shared_wishlist', $originalWishlist, true); 35 | 36 | // Create add all link 37 | $addAllLink = Mage::getUrl('wishlist/shared/allcart', array('code' => $wishlist->getSharingCode())); 38 | 39 | // Create view on site link 40 | $viewOnSiteLink = Mage::getUrl('wishlist/shared/index', array('code' => $wishlist->getSharingCode())); 41 | 42 | $templateParams = $observer->getEvent()->getData('templateParams'); 43 | $templateParams->setCustomer($customer); 44 | $templateParams->setSalable($wishlist->isSalable() ? 'yes' : ''); 45 | $templateParams->setItems($wishlistBlock); 46 | $templateParams->setMessage(Mage::helper('hackathon_emailpreview')->__('[yourmessage]')); 47 | $templateParams->setData('addAllLink', $addAllLink); 48 | $templateParams->setData('viewOnSiteLink', $viewOnSiteLink); 49 | 50 | return $this; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /app/code/community/Hackathon/EmailPreview/Model/Mail/Type/SitemapGenerateWarningsEmail.php: -------------------------------------------------------------------------------- 1 | getEvent()->getData('templateType') !== self::TYPE) { 14 | return $this; 15 | } 16 | 17 | $templateParams = $observer->getEvent()->getData('templateParams'); 18 | $templateParams->setWarnings(Mage::helper('hackathon_emailpreview')->__('[error 1]') . "\n" . Mage::helper('hackathon_emailpreview')->__('[error 2]')); 19 | 20 | return $this; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /app/code/community/Hackathon/EmailPreview/Model/Mail/Type/TokenStatusChangeEmail.php: -------------------------------------------------------------------------------- 1 | getEvent()->getData('templateType') !== self::TYPE) { 14 | return $this; 15 | } 16 | 17 | $templateParams = $observer->getEvent()->getData('templateParams'); 18 | $templateParams->setName(Mage::helper('hackathon_emailpreview')->__('[yourname]')); 19 | $templateParams->setData('userName', Mage::helper('hackathon_emailpreview')->__('[yourname]')); 20 | $templateParams->setEmail(Mage::helper('hackathon_emailpreview')->__('[email@example.com]')); 21 | $templateParams->setData('applicationName', Mage::helper('hackathon_emailpreview')->__('[application_name]')); 22 | $templateParams->setStatus(Mage::helper('hackathon_emailpreview')->__('[status]')); 23 | 24 | return $this; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/code/community/Hackathon/EmailPreview/Model/Source/Testtypes.php: -------------------------------------------------------------------------------- 1 | getConfig()->getNode(self::XML_PATH_TESTTYPES)->children(); 10 | 11 | $options = array(); 12 | 13 | foreach ($templateLabelNode as $node) { 14 | $options[(string) $node->type] = (string) $node->name; 15 | } 16 | 17 | asort($options); 18 | 19 | return $options; 20 | } 21 | 22 | } -------------------------------------------------------------------------------- /app/code/community/Hackathon/EmailPreview/controllers/Adminhtml/PreviewController.php: -------------------------------------------------------------------------------- 1 | loadLayout() 10 | ->renderLayout(); 11 | } 12 | } -------------------------------------------------------------------------------- /app/code/community/Hackathon/EmailPreview/controllers/Adminhtml/System/Email/TemplateController.php: -------------------------------------------------------------------------------- 1 | loadLayout(); 16 | $template = $this->_initTemplate('id'); 17 | $this->_setActiveMenu('system/email_template'); 18 | $this->_addBreadcrumb(Mage::helper('adminhtml')->__('Transactional Emails'), Mage::helper('adminhtml')->__('Transactional Emails'), $this->getUrl('*/*')); 19 | 20 | if ($this->getRequest()->getParam('id')) { 21 | $this->_addBreadcrumb(Mage::helper('adminhtml')->__('Edit Template'), Mage::helper('adminhtml')->__('Edit System Template')); 22 | } else { 23 | $this->_addBreadcrumb(Mage::helper('adminhtml')->__('New Template'), Mage::helper('adminhtml')->__('New System Template')); 24 | } 25 | 26 | $this->_title($template->getId() ? $template->getTemplateCode() : $this->__('New Template')); 27 | 28 | /* 29 | $this->_addContent($this->getLayout()->createBlock('adminhtml/system_email_template_edit', 'template_edit') 30 | ->setEditMode((bool)$this->getRequest()->getParam('id'))); 31 | */ 32 | 33 | $this->renderLayout(); 34 | } 35 | 36 | } -------------------------------------------------------------------------------- /app/code/community/Hackathon/EmailPreview/etc/config.xml: -------------------------------------------------------------------------------- 1 | 2 |