Jump to content

Unable to install override: The method already overridden. How to combine two override?


Zen_j1

Recommended Posts

Hello,

 

         I have purchased two module. Once I install one module successfully and if I Try to install another module I get error given below

 

Error:- Unable to install override: The method send in the class Mail is already overridden by the module bacodwithfees

 

After reading some article on internet I came to know another module is also trying to override same override which already overridden by another as stated in error.

 

In order to install another module I renamed Mail.php in One module to something else and module was installed. Since Mail.php was renamed to something else module installed but override for that module did not take.

 

I read some more article on Internet and prestashop forum that two override need to be combined.

 

Can Someone please help me to combine these two override. I have written down code for override for both module which need to be combined.  Both module are installed one with successful override and another without override as Mail.php was renamed before installation.

 

Override code of 1st  module:-

 

 

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 (Module::isEnabled('bacodwithfees')==false) {

            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);

        }

                                if (Tools::version_compare(_PS_VERSION_, '1.5.5.0', '>=') && Tools::version_compare(_PS_VERSION_, '1.6.0.0', '<')) {

                                                require_once(_PS_MODULE_DIR_."bacodwithfees/classes/mail1.5.php");

                                                $mail15 = new Mail15();

                                                return $mail15->send($id_lang, $template, $subject, $template_vars, $to, $to_name, $from, $from_name, $file_attachment, $mode_smtp, $template_path, $die, $id_shop);

               

                                } elseif (Tools::version_compare(_PS_VERSION_, '1.6.0.0', '>=') && Tools::version_compare(_PS_VERSION_, '1.6.1.0', '<')) {

                                                require_once(_PS_MODULE_DIR_."bacodwithfees/classes/mail1.6.php");

                                                $mail16 = new Mail16();

                                                return $mail16->send($id_lang, $template, $subject, $template_vars, $to, $to_name, $from, $from_name, $file_attachment, $mode_smtp, $template_path, $die, $id_shop, $bcc);

                                } else {

                                                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);

                                }

                               

    }

}

 

 

Override code of 2nd Module:-

 

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

    ) {

        if ($template == 'order_conf' || $template == 'new_order') {

            $module = Module::getInstanceByName('deliverydays');

            if ($module && $module->active) {

                $template_vars = $module->setMailTemplateVars($template_vars, $id_lang);

            }

        }

        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

        );

    }

}

 

 

 

 

 

Link to comment
Share on other sites

Try to put 

 if ($template == 'order_conf' || $template == 'new_order') {
            $module = Module::getInstanceByName('deliverydays');
            if ($module && $module->active) {
                $template_vars = $module->setMailTemplateVars($template_vars, $id_lang);
            }
        }

before

if (Module::isEnabled('bacodwithfees')==false) {........

So Override could look

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 ($template == 'order_conf' || $template == 'new_order') {
              $module = Module::getInstanceByName('deliverydays');
            if ($module && $module->active) {
                $template_vars = $module->setMailTemplateVars($template_vars, $id_lang);
            }
        }

        if (Module::isEnabled('bacodwithfees')==false) {
            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);
        }
                                if (Tools::version_compare(_PS_VERSION_, '1.5.5.0', '>=') && Tools::version_compare(_PS_VERSION_, '1.6.0.0', '<')) {
                                                require_once(_PS_MODULE_DIR_."bacodwithfees/classes/mail1.5.php");
                                                $mail15 = new Mail15();
                                                return $mail15->send($id_lang, $template, $subject, $template_vars, $to, $to_name, $from, $from_name, $file_attachment, $mode_smtp, $template_path, $die, $id_shop);
               
                                } elseif (Tools::version_compare(_PS_VERSION_, '1.6.0.0', '>=') && Tools::version_compare(_PS_VERSION_, '1.6.1.0', '<')) {
                                                require_once(_PS_MODULE_DIR_."bacodwithfees/classes/mail1.6.php");
                                                $mail16 = new Mail16();
                                                return $mail16->send($id_lang, $template, $subject, $template_vars, $to, $to_name, $from, $from_name, $file_attachment, $mode_smtp, $template_path, $die, $id_shop, $bcc);
                                } else {
                                                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);
                                }
                               
    }
}
  • Like 1
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...