Re: adding new templates to newsletter module
Quote:
Originally Posted by
DrByte
That dropdown determines which module to run from the modules/newsletters folder.
If you want to add something to that dropdown and write a new module to go with it, feel free.
if I just literally copied the newsletter.php file and changed the template name in there, would that work? Then I'd copy that file up to the server and it would appear in the drop-down. What I don't know if other functions would reference back to the newsletter.php file?
Quote:
Originally Posted by
DrByte
Sorry if that's too much tech talk -- you sounded like you had a handle on programming when you said you altered things to allow additional newsletter choices.
It's not too much tech talk - I do have a handle on programming but are relatively new to zencart and have not delved in the email coding at all - mainlly dealt with the template side of things so far.
Re: adding new templates to newsletter module
Quote:
Originally Posted by
christoph_lutz
i have amended the subscribe to newsletter option where users can tick different categories, so I can select those when sending a newsletter
"How" are you selecting those when you send a newsletter?
Re: adding new templates to newsletter module
By selecting the audience from the dropdown. I have added queries to the query builder table that gets me the right group of customers
Re: adding new templates to newsletter module
Okay, then one approach could be to use the query_name value from the query-builder data (ie: the audiences list) to determine which template to use.
1. Rename your special queries like this:
Code:
Subscriber Group: Bleeding Edge Racers
or
Subscriber Group: All Stars ~ Heavy Hitters
2. Create corresponding email template files.
The email templates for the example names above would be:
Code:
/email/email_template_bleedingedgerac.html
/email/email_template_allstars.html
Explanation:
The template names will be built from the query_name (audience names) starting with 'Subscriber Group: ' followed by up to 15 chars for the template name (or until a ~ is found).
Converted to lower-case letters to find the template filename.
If a filename matching the pattern isn't found, the module name will be used instead.
3. Make the following code edits to the admin/includes/newsletters/newsletter.php:
Code:
function send($newsletter_id) {
global $db;
// Look for audience names starting with 'Subscriber Group: ' and accept up to 15 chars for template name (takes name up to ~ or if no ~ then 15 max chars)
$my_template_name = str_replace('Subscriber Group: ', '', $this->query_name);
$my_template_name = preg_replace('/^[0-9a-zA-Z_~]/', '', $my_template_name);
$pos = strpos($my_template_name, '~');
$my_template_name = strtolower(substr($my_template_name, 0, ($pos > 0 && $pos < 15 ? $pos : 15) ));
$audience_select = get_audience_sql_query($this->query_name, 'newsletters');
$audience = $db->Execute($audience_select['query_string']);
$records = $audience->RecordCount();
if ($records==0) return 0;
$i=0;
while (!$audience->EOF) {
$i++;
$html_msg['EMAIL_FIRST_NAME'] = $audience->fields['customers_firstname'];
$html_msg['EMAIL_LAST_NAME'] = $audience->fields['customers_lastname'];
$html_msg['EMAIL_MESSAGE_HTML'] = $this->content_html;
$html_msg['EMAIL_TEMPLATE_FILENAME'] = $my_template_name;
This all requires that you implement the functions_email changes I mentioned earlier.
Re: adding new templates to newsletter module
Hi Dr Byte,
Nice one, this has worked - although your regular expression did not quite work as it cut off some of the name of the group and did not take out the spaces. I have just shortened it to [\s] so it's working fine now.
Just one thing: Although I have now done it your way, I had thought I'd add a column to the table and put the template name in there. Would you think that's a bad idea?
Thanks
Christoph
Re: adding new templates to newsletter module
Feel free to do as you wish with it.
I looked at the new-column-in-table approach and realized there'd need to be coding changes in several places in order to make that work, and I didn't want to risk breaking other things without thorough testing ... so I opted to give you the simplest route.
Sorry about the bad regex ... I meant to go test that but forgot :eek:
Re: adding new templates to newsletter module
Hi,
Fair enough, I just thought the extra column would be relatively simple but have not looked at the wider implications. In any case, I have got it working beautifully now which is great. I have also put in an alert in the result screen to show what template is being used so that other people who may be using it will see what's happening.
Thanks for all you help on this one!
And yes, regular expressions catch me out at times, too :) No worries
Christoph
Re: adding new templates to newsletter module
Dr Byte,
I've done something similar here, where i've duplicated the newsletters module to create an additional one, let's call it "news2".
I was able to use a different email template I created WITHOUT modifying functions_email.
In the duplicated newsletter module... "news2" I changed the following at line 351:
Code:
<?php
zen_set_time_limit(600);
flush();
$i = $module->send($nInfo->newsletters_id);
?>
TO THIS
Code:
<?php
zen_set_time_limit(600);
flush();
$current_page_base = 'news2';
$i = $module->send($nInfo->newsletters_id);
?>
I'm wondering if this is a bad way to accomplish this.
Thanks
DD
Re: adding new templates to newsletter module
I suppose if you only ever intend to send to one group, that's fine.
The workaround to the original poster's question was way more generic than what you are suggesting, and doesn't require changing code everytime one wants to send a different newsletter.