a-ok Posted January 9, 2019 Share Posted January 9, 2019 I had a hook method set up to do a few things, hooked to a lazycron of every 30 minutes: wire()->addHook('LazyCron::every30Minutes', function($event) { // functions etc } This was working fine but I needed to call the content of the function on a specific page save also so I made it into a public function and set up two hooks for it... one on the lazycron and one on page. function shopifyInit(HookEvent $event) { // functions etc } wire()->addHook('LazyCron::every30Minutes', null, 'shopifyInit'); wire()->addHookAfter('Pages::save', function($event) { $page = $event->arguments(0); if ($page->template->name == 'shop') { // Shop shopifyInit(); $page->message('Shopify cache has been cleared for all products'); } }); However on save I am getting this error... ArgumentCountError Too few arguments to function ProcessWire\shopifyInit(), 0 passed and exactly 1 expected Any thoughts where I'm going wrong? Link to comment Share on other sites More sharing options...
flydev Posted January 9, 2019 Share Posted January 9, 2019 32 minutes ago, a-ok said: shopifyInit(); to 32 minutes ago, a-ok said: shopifyInit($event); 1 Link to comment Share on other sites More sharing options...
kongondo Posted January 9, 2019 Share Posted January 9, 2019 (edited) 33 minutes ago, a-ok said: Any thoughts where I'm going wrong? It says it right there in the error ?, 33 minutes ago, a-ok said: ArgumentCountError Too few arguments to function ProcessWire\shopifyInit(), 0 passed and exactly 1 expected Your function shopifyInit() expects a single argument/parameter but here: 33 minutes ago, a-ok said: if ($page->template->name == 'shop') { // Shop shopifyInit(); $page->message('Shopify cache has been cleared for all products'); } you are not passing it the $event. edit: I'm too slow; what @flydev said ?. Edited January 9, 2019 by kongondo 1 Link to comment Share on other sites More sharing options...
a-ok Posted January 9, 2019 Author Share Posted January 9, 2019 Thanks folks. I tried this but received an error: Using $this when not in object context function shopifyInit(HookEvent $event) { 83: 84: $collections = $this->shopifyHttp->getJSON($this->shopifyBase . "custom_collections.json"); I'm using $this to grab my API keys etc outside of the scope of the hook $this->shopifyHttp = new WireHttp(); $this->shopifyAPIKey = blahblah Using $this works fine when using it directly in a hook but not within a function that's called within a hook? 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