Jump to content

How to remove the shop name from the mail subject by override


ballashop

Recommended Posts

Hi,

is there anyone who can tell me how to override this code to remove [shop name] from the mail subject?

from:

$subject = '[' . $shop->name . '] ' . $subject;

to:

$subject = $subject;

goal: remove [shop name] from the all mails subject

Thanks for any reply.

balla

Link to comment
Share on other sites

./classes/Mail.php

Find function Send().

 

Comment line /* xxx */:

/* $subject = '[' . Configuration::get('PS_SHOP_NAME', null, null, $idShop) . '] ' . $subject; */

 

Or create override Mail.php and save to ./override/classes/Mail.php:

<?php

class Mail extends MailCore
{
    
    public static function send(
        $idLang,
        $template,
        $subject,
        $templateVars,
        $to,
        $toName = null,
        $from = null,
        $fromName = null,
        $fileAttachment = null,
        $mode_smtp = null,
        $templatePath = _PS_MAIL_DIR_,
        $die = false,
        $idShop = null,
        $bcc = null,
        $replyTo = null,
        $replyToName = null
    )
    {
        $shop_name = '[' . strip_tags($configuration['PS_SHOP_NAME']) . '] ';
        $subject = str_replace($shop_name, '', $subject);
        $message->setSubject($subject);     
    
        return parent::send(
            $idLang,
            $template,
            $subject,
            $templateVars,
            $to,
            $toName,
            $from,
            $fromName,
            $fileAttachment,
            $mode_smtp,
            $templatePath,
            $die,
            $idShop,
            $bcc,
            $replyTo,
            $replyToName
        );
    }
}

 

Or create custom module and call hook:

public function hookActionEmailSendBefore($param)
{
    if (!isset($param['subject'])) {
        return;
    }

    $shop_name = '['.strip_tags($configuration['PS_SHOP_NAME']).'] ';
    $subject = str_replace($shop_name, '', $param['subject']);
    
    $param['subject'] = $subject;
}

There are more options 😉

Edited by 4you.software (see edit history)
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

  • 9 months later...

@4you.software Hi, I would like to use the code you provided above, but my ./override/classes/Mail.php file already contains code. 
Is it possible to integrate your code without losing the code that is already there? 
Thanks
 

Here is the actual Mail.php file

<?php

if (! defined('_PS_VERSION_')){

exit();

}

$modulePath = rtrim(_PS_MODULE_DIR_, '/') . '/mailhook/';

require_once $modulePath . 'MailMessage.php';

require_once $modulePath . 'MailMessageAttachment.php';

require_once $modulePath . 'MailMessageEvent.php';

class Mail extends MailCore{

/*

* module: mailhook

* date: 2022-10-01 16:33:25

* version: 1

*/

public static function Send($id_lang, $template, $subject, $template_vars, $to, $to_name = null, $from = null, $from_name = null,

$file_attachment = null, $mode_smtp = null, $template_path = _PS_MAIL_DIR_, $die = false, $id_shop = null, $bcc = null, $reply_to = null,

$replyToName = null) {

$message = new MailMessage();

$message

->setLangId($id_lang)

->setTemplateName($template)

->setSubject($subject)

->setTemplateVariables($template_vars)

->setToEmailAddress($to)

->setToName($to_name)

->setFromEmailAddress($from)

->setFromName($from_name)

->setTemplateFolderPath($template_path)

->setModeSMTP($mode_smtp)

->setShopId($id_shop)

->setBcc($bcc)

->setReplyTo($reply_to)

->setReplyToName($replyToName)

;

if ($file_attachment !== null) {

$message->setFileAttachment(new MailMessageAttachment($file_attachment));

}

$event = new MailMessageEvent($template);

$event->setDie($die);

$event->addMessage($message);

self::executeMailSendingHook($event);

return self::processMailEvent($event);

}

/*

* module: mailhook

* date: 2022-10-01 16:33:25

* version: 1

*/

public static function sendMailWithoutHook($id_lang, $template, $subject, $template_vars, $to, $to_name = null, $from = null, $from_name = null,

$file_attachment = null, $mode_smtp = null, $template_path = _PS_MAIL_DIR_, $die = false, $id_shop = null, $bcc = null, $reply_to = null, $replyToName = null) {

return parent::Send($id_lang, $template, $subject, $template_vars, $to, $to_name, $from, $from_name, $file_attachment, $mode_smtp, $template_path, $die, $id_shop, $bcc, $reply_to, $replyToName);

}

/*

* module: mailhook

* date: 2022-10-01 16:33:25

* version: 1

*/

public static function sendMailMessageWithoutHook(MailMessage $message, $isDie) {

$file_attachment = null;

if ($message->getFileAttachment() !== null) {

$file_attachment = $message->getFileAttachment()->toArray();

}

return self::sendMailWithoutHook(

$message->getLangId(),

$message->getTemplateName(),

$message->getSubject(),

$message->getTemplateVariables(),

$message->getToEmailAddress(),

$message->getToName(),

$message->getFromEmailAddress(),

$message->getFromName(),

$file_attachment,

$message->getModeSMTP(),

$message->getTemplateFolderPath(),

$isDie,

$message->getShopId(),

$message->getBcc(),

$message->getReplyTo(),

$message->getReplyToName()

);

}

/*

* module: mailhook

* date: 2022-10-01 16:33:25

* version: 1

*/

protected static function executeMailSendingHook(MailMessageEvent $event) {

Hook::exec('actionMailSend', array(

'event' => $event

));

}

/*

* module: mailhook

* date: 2022-10-01 16:33:25

* version: 1

*/

protected static function processMailEvent(MailMessageEvent $event) {

$numberOfSuccessfulRecipients = 0;

foreach ($event->getMessages() as $message) {

$rs = self::sendMailMessageWithoutHook($message, $event->isDie());

if ($rs !== false) {

$numberOfSuccessfulRecipients = $rs + $numberOfSuccessfulRecipients;

}

}

if ($numberOfSuccessfulRecipients > 0) {

return $numberOfSuccessfulRecipients;

}

else {

return false;

}

}

}

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...