Jump to content

Hook replace fails occasionaly


apeisa
 Share

Recommended Posts

I have nasty problem that I am having hard time debugging.

I have two modules. First one is called TapuFormsProcessing and it has this method:

public function ___getEventPrice() {
	$price = $this->event->price;
	return $price;
}

Other one is autoload module that needs to replace that value if certain circumstances are met. This is singular and autoload and has one hook:

public function init() {
	$this->addHookBefore('TapuFormsProcess::getEventPrice', $this, 'martatPrice'); 
}

This "martatPrice" method is little bit complicated than that - but I have only relevant stuff here:

public function martatPrice(HookEvent $event) {

	if ( ! $this->session->reg_id > 0) return;

	$page = wire('pages')->get($this->session->reg_id);

	if ($page->id) {
		if ($page->price_member > 0 || $page->price_member === 0) {
			$log = new FileLog($this->config->paths->logs . 'customprice.txt');
			$log->save("$page->title ($page->id): $page->price_member ({$this->session->reg_id})"); 
			$event->replace = true;
			$event->return = $page->price_member;
		}
	}	
}

What is weird here is that what goes to log is always right. So the logic (that I have mostly stripped there) works right. But sometimes that replaced method still returns the original price. I am little stuck since I don't know how to debug this.


I tried to remove $event->replace and change it to after hook - but then it never modified the return value on TapuFormsProcess::getEventPrice. Not sure if I missed something simple on there? 

I am using templates cache (but not on these event templates), other one of the modules is symlinked, both modules use session data (though those are always right based on logs)... I don't know if those can affect it, since I don't really now how the hook system works. Of course (and probably) the bug is somewhere else than in hook system - but I have hard time debugging that.

This is how TapuFormsProcess() uses it's own method:

$price = $this->getEventPrice();
Link to comment
Share on other sites

I think I found the problem (after three days of debugging). Sometimes writing down the problem helps most.

It doesn't have anything to do with the hook system. I just have another call for the hooked method - that is why the log works. Sorry for wasting your time (if anyone already read this).

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...