Jump to content

How to best add features into core files


Kristian Toldy

Recommended Posts

Hi,

I'm new to PrestaShop and I'm not sure how to do this the best.

We're trying to add 2 specific PDF files to the order confirmation email. We have a working code which adds these files and is working correctly by putting it in the classes/Mail.php file:

           if ($template == 'order_conf'){
             $file = _PS_ROOT_DIR_ . '/terms.pdf';
             $message->attach(Swift_Attachment::fromPath($file));
             $file2 = _PS_ROOT_DIR_ . '/return_money.pdf';
             $message->attach(Swift_Attachment::fromPath($file2));
            }

This is however a temporary solution as whenever Prestashop would get upgraded, this code would disappear as being part of a core. How else could this be done so it's protected from updating and the attachments are properly included in the send function.

Thanks for any tips!

Link to comment
Share on other sites

22 minutes ago, endriu107 said:

Thanks, we did override it by copying the  send function into an override class but this does not help with the updating problem as we copied the whole function. What if in the future there is an update to this function, because the overridden function will be always in use it won't be updated.

Thanks

Link to comment
Share on other sites

We suggest to use ActionEmailAddAfterContent hook to modify the email content.

  For reference:   


    public function hookActionEmailAddAfterContent(&$params)
    {
        $content = '';
        if ($params['template'] == 'order_conf') {

         // Let's edit content of Order's Confirmation email
   
            $params['template_html'] = str_replace("order", "order_new" . $content, $params['template_html']); 
        }
    }

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