1

I'm very new to magento. I want to show the newsletter template's preview for the customers. I know it is possible from the admin backend. But how can I obtain this link in the template pages?. I found this code in core/Mage/AdminHtml/controllers/Newsletter/TemplateController.php

`public function previewAction ()
{
    $this->_setTitle();
    $this->loadLayout();

    $data = $this->getRequest()->getParams();
    if (empty($data) || !isset($data['id'])) {
        $this->_forward('noRoute');
        return $this;
    }

    // set default value for selected store
    $data['preview_store_id'] = Mage::app()->getAnyStoreView()->getId();

    $this->getLayout()->getBlock('preview_form')->setFormData($data);
    $this->renderLayout();
}`. 

but I don't know how to use it for this. I have the template_id to load the template.

Is there any other method to accomplish this?. Thanks in advance

  • Where do you wan't to show it? And what is actually your plan why you want to achieve this? – Anna Völkl Nov 13 '14 at 11:44
  • I want to show it on customer/form/newsletter.phtml. Actually my client need the preview of all news letters displayed on the newsletter.phtml page. Is it possible? – user3905451 Nov 13 '14 at 11:54
1

Something like this could help, anyway I did not test it:

$queue = Mage::getModel('newsletter/queue');
$queue->setTemplateId('YOUR_ID');
$data['preview_store_id'] = Mage::app()->getAnyStoreView()->getId(); //or your store-id
$queue->addTemplateData($data);
$queue->getNewsletterText();

//more:
$this->getNewsletterSubject();
$this->getNewsletterStyles();

To get a proper view you will need to include it via iframe or popup-windows I guess.

From my personal experience I can say, that sending Newsletters directly from Magento is not too much fun and it's very inflexible. It would make sense to integrate a newsletter service.

  • Till $data['preview_store_id'] = Mage::app()->getAnyStoreView()->getId(); is working fine but it is stuck in the line $queue->addTemplateData($data);. print_r($queue->addTemplateData($data);) shows nothing. – user3905451 Nov 13 '14 at 12:35
  • Sorry, I cannot debug it right now. You should check what happens in the addTemplateData and getTemplate methods of Mage_Newsletter_Model_Queue. – Anna Völkl Nov 13 '14 at 12:53
0

I found a solution for this in an indirect way and it worked for me. I directly get all required newsletter data from the database itself.

$resource = new Mage_Core_Model_Resource();  
$read = $resource->getConnection('core_read');  
$select = $read->select()->from('newsletter_template');
$temp = $read->fetchAll($select); 

then simply using a foreach loop, I was able to get all the values.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.