easynowbaby Posted October 8, 2016 Share Posted October 8, 2016 Hi, I'm trying to create a simple module, that is hooking into a certain function in Padloper that returns a filled form. I want to use these data to create a new user. But when I try to create a page I'm getting this error: Call to a member function get() on null (line 30) Here is my module: <?php class RegisterUser extends WireData implements Module { public static function getModuleInfo() { return array( 'title' => 'Registration during checkout', 'version' => 1, 'summary' => 'Register user during checkout', 'singular' => true, 'autoload' => true, 'icon' => 'user', ); } public function init() { /* */ $this->addHookBefore('PadOrderProcess::saveOrder', $this, 'registerUser'); } /** * This is the method that hook run. Since in Padloper we can have any field as pricefield, * we need to find out which is the pricefield. */ public function registerUser($event) { // This way we can access the arguments that are send to hooked method $hp = wire('pages')->get(1); $p = new Page(); $p->of(false); // sets output formatting to false in order to change field values. $p->parent = $hp; $p->template = "basic-page"; $p->title = 'test2'; // sanitized your value from form and sets to title $p->save(); // save the new page } } This is my first time working with hooks, so maybe I'm missing something. Maybe hooks are strictly for modifying arguments sent to hooked methods? Thank you for any help! Link to comment Share on other sites More sharing options...
szabesz Posted October 9, 2016 Share Posted October 9, 2016 Hi, $hp = $this->wire('pages')->get(1); The reason: 1 Link to comment Share on other sites More sharing options...
easynowbaby Posted October 12, 2016 Author Share Posted October 12, 2016 Thank you for your reply but I keep getting the same error Link to comment Share on other sites More sharing options...
netcarver Posted October 12, 2016 Share Posted October 12, 2016 Could you try... $hp = $event->pages->get(1); 1 Link to comment Share on other sites More sharing options...
easynowbaby Posted October 13, 2016 Author Share Posted October 13, 2016 After further investigation it seems that both answers are correct, the problem was something else. For some reason my hook is being fired every time any page is loaded, not just after saveOrder function is being run, as I intended to. For the time being, my workaround is to wrap everything in my registerUser function in an if statement: public function registerUser($event) { if ($event) { $order = $event->arguments('order'); if ($order->pad_register) { .... } } } I would love an explanation why is this happening if anyone has one Link to comment Share on other sites More sharing options...
netcarver Posted October 13, 2016 Share Posted October 13, 2016 @easynowbabyIt might be advantageous for you to post about this in the padloper support forum as Antti is more likely to see it and fix it if it's in there. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now