Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PrestaShop email localization

Tags:

prestashop

I am developing a module for PrestaShop 1.5.

I am sending email like this(the documentation is really missing, i studied other default components and this is what i got so far)

Mail::Send(
                            $this->context->language->id, //int $id_lang
                            'template_name',//string $template
                            //Mail::l('Hello', $this->context->language->id),//string $subject
                            $this->l('Email subject'),//string $subject
                            array('{discount}' => $code,
                                  '{firstname}' => $customer['firstname'],
                                  '{lastname}' => $customer['lastname'],
                                  '{img_url}' => $img_url,
                                  '{valid_days}' => $form['days_valid']  
                            ),//string $template_vars
                            $customer['email'],//string $to
                            implode(' ', array_filter( array( $customer['firstname'], $customer['lastname']) )),
                            strval( Configuration::get('PS_SHOP_EMAIL') ),//string $from
                            strval( Configuration::get('PS_SHOP_NAME') ),//string $from_name
                            /* null,//string $from
                            null//string $from_name */
                            null,//array $file_attachment
                            null,//$mode_smtp
                            $template_path//string $template_path /*__PS_BASE_URI__.'modules/'.$this->name.'/mails/' */

                    );

Note i tried using

Mail::l('Hello', $this->context->language->id),//string $subject

and

$this->l('Email subject'),//string $subject

as the email's subject.

And i keep getting "No Subject was found for ...". What the customer receive is the hardcoded string i put in the source code.

So how to get rid of this error: enter image description here Plus the emails are sent in apparently random language(sometimes english, sometimes italian).

like image 691
max4ever Avatar asked Jan 18 '13 16:01

max4ever


2 Answers

In your module, you must use Mail::l() in the subject parameter. Here's an example of Mail::Send() for a module :

Mail::Send($this->context->language->id,
    'test',
    Mail::l('test subject', $this->context->language->id),
    array(),
    $to_email);

Here how email translations is working :

AdminTranslationsController will check in "/modules/[module folder]/mails/" for the templates and in "/mails/[lang]/lang.php" for subjects. Subjects will be created when submitting translations.


If that doesn'work, maybe it's a problem with folder's rights. Open this file :

/prestashop/mails/it/lang.php

And check if there's a line like this one :

$_LANGMAIL['Email subject'] = 'translation in italian';

If not, check web server rights on this file and parent folders.

like image 194
SJousse Avatar answered Sep 28 '22 19:09

SJousse


I've now came over same issue working with Prestashop version 1.5.5.0.

In some circumstances, getSubjectMail() method won't recognize email template, so it cannot be matched with subject. The whole point is that while this method looks for subjects to be translated, it parses php files as plain text. Therefore all variables are parsed unresolved.

In my case, I'm calling Mail:Send from the module's controller and it looks like:

Mail::Send(
    $id_lang,
    $template, // <- don't use variable here, rather type email template there directly.
    Mail::l('Message from footer contact form'),
    $template_vars,
    $contact->email,
    $contact->name,
    ($is_email ? $from : Configuration::get('PS_SHOP_EMAIL')),
    '',
    null, // file attachment
    null, // mode smtp
    $this->module->_mailpath
);

Parsing this file would result into matching subject Message from footer contact form to the mail template "$template". Which doesn't exist obviously.

To make sure that your subject will be recognized correctly, don't use variable to pass template name.

like image 40
Michael Kubovic Avatar answered Sep 28 '22 20:09

Michael Kubovic