Jump to content

How to override Core-Function from Module?


Recommended Posts

Hello,

 

I am new in prestashop and still learning ...

 

To understand how things work I want to find out whats the best way to solve the following problem:

 

If I use the module mailalerts the email-logo is automatically attached to all emails even if  I remove "<img src="{shop_logo}" alt="{shop_name}" /></a>" from mailalerts email-templates (f.e. "new-order.html")

 

I wrote an override to "Mail.php" and placed it in /override/classes. This will do the job. 

class Mail extends MailCore
{
  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)
  {

...

        if (isset($logo)) {
            /* Do not attach Logo start */
            if(strpos($template,'new_order') === false && strpos($template,'productoutofstock') === false  && strpos($template,'productcoverage') === false)
            /* Don not attach Logo End */
            $template_vars['{shop_logo}'] = $message->attach(new Swift_Message_EmbeddedFile(new Swift_File($logo), null, ImageManager::getMimeTypeByExtension($logo)));
        }
...
  
  }
}

I also wrote a module with a helper-form to switch "Remove Logo" on and off.

The module works fine and stores the configuration. It should be not the problem to change the override of Mail.php to check this and avoid the attachment of the logo if "Remove Logo" is "on".

 

But I'm not really satisfied with a override + configuration(only)-module solution.  :(

 

I have read that i can place my override in my module directory and prestashop will automatically merge the override with a corresponding override in prestashops override-directory when the module is installed.

 

Is this the best way things should be done if I want to override a core function from a module?

If yes: How will prestashop merge the overrides if there are a least 2 overrides from different modules?

 

I know I could also write my own sendmail-function and "rebuild" (or override?) the ActionHooks from mailalerts.

But that seems to be the hard and not so elegant way. This would change a lot of code from mailalerts.

 

Thank you in advance for getting me on the right track.

 

best regards,

Karsten Boldt

 

 

 

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...