Jump to content

[Solved] Changing a core function with a module (not with the override directory)


Pierre.CIHOLAS

Recommended Posts

Hello everybody,

 

I have to modify Prestashop to join it to a simple ticket system, it has to execute some PHP actions when the status of an order is changed (by example, when an order moves from the status "waiting payment to paid, a new ticket has to be generated and sent by mail)

 

To do this, I have to change the function (method) updateOrderStatus of the HookCore class, actually I do it using the "override/classes" directory allowing me to modify the Prestashop core without changing the core files themselves.

 

Bu to make my system I need to modify several functions (methods) of core classes, and I will have to create several files in the override directory with my scripts.

I want (to make my module cleaner and configurable by the back office) to modify the functions (method) of the Prestashop Core classes using a module and not the override directory.

 

Do you have a solution to do this ? I can't believe it is not possible, I think a lot of modules need to change the prestashop core, I just don't know how they do...

 

Thanks in advance.

 

Pierre CIHOLAS

Link to comment
Share on other sites

Hello,

 

If you do not want to use the override possibility, you will need to open/read the file with FTP and locate the places you need to edit, then make the modifications to the string and write it to the file.

 

But if you need to make big changes, you should rather use the override.

Link to comment
Share on other sites

you should register hooks directly if possible. don't modify the Hook class, instead create a module, and register to listen for the hookUpdateOrderStatus event.

 

as for other methods that do not have hooks, do not modify core files, create the override class, and during the module installation, move the file to the override classes folder, but only if the file does not already exist. if the file already exists, then fail the installation and inform the user that they have manually merge the 2 files.

Link to comment
Share on other sites

when you create a module, you will implement a function called "install". below is an example of the install method from the bankwire module.

 

    public function install()
   {
       if (!parent::install() OR !$this->registerHook('payment') OR !$this->registerHook('paymentReturn'))
           return false;
       return true;
   }

 

This module "listens" for the payment and paymentReturn events (aka hooks). so for your module, you would listen for the "updateOrderStatus" event.

    public function install()
   {
       if (!parent::install() OR !$this->registerHook('updateOrderStatus'))
           return false;
       return true;
   }

 

then inside your module, you would define a function called "hookUpdateOrderStatus". This function will be called when the order status is changed. So you just need to implement your custom logic within this function. I would suggest you look at other modules for more details.

 

public function hookUpdateOrderStatus($params)

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