Jump to content

How to use action hooks?


itps

Recommended Posts

I can't figure out how to use action hooks. 

For example In order process I have to get info which carrier is chosen for shipping and then write some extra stuff in database if client finish order process.

How can I do that?

Link to comment
Share on other sites

uhm...google search works great for me

 

I think the problem is that the links I sent do not point exactly to what you are researching, though you said you have reviewed all the documenation  on module writing it does have a section just for hook processing..

 

09.23.2013-07.37.png
http://screencast.com/t/iv1W1KDH

 

and as I stated earlier on, a good way to learn hooks etc. is to look at modules that come with your ps installation.

Link to comment
Share on other sites

Hooks in PrestaShop 1.5 have a new naming scheme, with a situation-specific prefix:

  • action. These hooks are triggered by specific events that take place in PrestaShop.
  • display. These hooks result in something being displayed, either in the front-end or the back-end.

Implementing hooks section in documentation show example only about display hooks what I learned already, but I want to change some PS functionality with action hooks and i have no idea with what i have to start.

Of course i could look at some other modules, but i need some step by step explanation, because i am newbie at prestashop modules and hooks.

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...
  • 4 weeks later...

Hi Kezeno, 

 

Thanks for the very clear explanation, I am writing my own module, and I casually use the  actionValidateOrder Hook.

 

I follow your indications, and look other modules code, I even use some code an example because they get the same data that I need, well, i finish mymodule and upload to test it.

 

When I hit the install button I found this error:

 

Incapaz de instalar con control manual : Class PaymentModuleOverride does not exist

 

 "Incapable of install with manual control : Class PaymentModuloOverride does not exist"

 

I wonder why?

if (!defined('_CAN_LOAD_FILES_'))
	exit;

class txtstock extends Module
{
	
		
	public function __construct()
	{
		$this->name = 'txtstock';
		$this->tab = 'others';
		$this->version = '0.1';
		$this->author = 'Myself';
		$this->need_instance = 0;

		parent::__construct();

		if ($this->id)
			$this->init();

		$this->displayName = $this->l('Venta a un txt');
		$this->description = $this->l('Escribe un txt con la última venta.');
		$this->confirmUninstall = $this->l('Esta seguro que quiere borrar este modulo?');
	}

	public function install() {
		$this->registerHook('actionValidateOrder');  
    	if(parent::install() == false)
        return false;
		return true;
	}
	
	public function hookActionValidateOrder($params){



        }

Into the public function there is more code, but I decide to cut it to test it and even without the public function code, I can't install my module.

 

I use PS 1.5.3.1

 

 

Thanks in advanced for your help.

 

Best regards

Edited by elgris (see edit history)
Link to comment
Share on other sites

  • 2 years later...

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