-
Posts
394 -
Joined
-
Last visited
-
Days Won
12
Everything posted by Gadgetto
-
Just stumbled across this older post and I want to say: IMHO this is the simplest/best explanation for registering / executing hooks! Thanks! This is also a problem for me when I try to post more complex questions in the forum. I'm often not understood.
- 14 replies
-
- 1
-
-
- hook
- non autoload
-
(and 1 more)
Tagged with:
-
If this is the real reason, I don't know how to solve this, as process() needs to be called by a hook. ?
-
Changed to a static method call - still not working... ? I'm just thinking it could be a problem that the process() method (which calls the hook method dynamically) itself is also triggered by a hook? public function init() { ... $this->addHookBefore('ProcessPageView::execute', $this, 'checkWebhookRequest'); ... } /** * Check for webohook request and process them. * (Method triggered before ProcessPageView execute) * */ public function checkWebhookRequest(HookEvent $event) { if ($webhooksEndpoint = $this->get('webhooks_endpoint')) { if ($this->sanitizer->url($this->input->url) == $webhooksEndpoint) { $this->wire('webhooks')->process(); $event->replace = true; // @note: Tracy Debug won't work from here on as normal page rendering is omitted! } } }
-
Are you sure? Maybe I don't understand this correctly... It seems a new method is only added if the specified method name doesn't exist. From the docs: --- You can add new methods to any ProcessWire class in the same way that you would hook an existing method. The only difference is that the method doesn't already exist, so you are adding it. Also, because there is no distinction of "before" or "after" for something that doesn't already exist, you can attach the method using addHook(); rather than addHookBefore(); or addHookAfter() … though technically it doesn't really matter what you use here. Lets say that you wanted to add a new method to all Page instances that outputs a relative time string of when the page was last modified (for example, "45 minutes ago" or "3 days ago", etc.): public function init() { $this->addHook('Page::lastModified', $this, 'lastModified'); } public function lastModified($event) { $page = $event->object; $event->return = wireRelativeTimeStr($page->modified); } Hooking both before and after If you want your hook method to run both before and after a particular event occurs, you can specify that in an $options array to the addHook() call, like this: $wire->addHook('Class::method', function(HookEvent $e) { // ... }, [ 'before' => true, 'after' => true ]);
-
I changed to addHookAfter but still doesn't work. (had this tried before without success) ?
-
Could be a bug in PW...
-
OK, If I call this manually in Tracy Console: $webhooks->handleOrderCompleted(); The hook is triggered! Shouldn't a dynamic method call trigger a hook event? $this->{$methodName}();
-
I have this part in my ready.php $webhooks->addHook('handleOrderCompleted', function($event) { wire('log')->save('webhookstest', 'hook works'); }); But the log entry isn't written.
-
From PW docs: So it should work. ?
-
This is strange! Why doesn't it work in my environment? None of the hooks I posted above is triggered.
-
Hi @bernhard, thanks for jumping in! What does that do? The Webhooks class handles Snipcart's web hook events and provides hookable methods to attach custom code to those events. eg. orderCompleted, customerUpdated, ad so on ... A Snipcart webhook event is a POST request which is sent to your site by Snipcart. Each POST request holds json encoded data corresponding to the specific situation. e.g. A orderCompleted event POSTs the full order array to your site. The Webhooks class is available as custom API variable $webhooks. This code in SnipWire main module takes over POST request from Snipcart: /** * Check for webohook request and process them. * (Method triggered before ProcessPageView execute) * */ public function checkWebhookRequest(HookEvent $event) { if ($webhooksEndpoint = $this->get('webhooks_endpoint')) { if ($this->sanitizer->url($this->input->url) == $webhooksEndpoint) { $this->wire('webhooks')->process(); $event->replace = true; // @note: Tracy Debug won't work from here on as normal page rendering is omitted! } } } This line... $this->wire('webhooks')->process(); ... starts the process which handles a Snipcart POST request: https://github.com/gadgetto/SnipWire/blob/cc9922fbe059b3961d3ee63be253e34d4cf96bc1/services/Webhooks.php#L108 Within this processing the specific hookable method within the Webhooks class is called. I thought it should be easy to provide those methods a hookable. But it seems this isn't so easy with custom classes. For example - this doesn't work: $webhooks->addHook('handleOrderCompleted', function($event) { wire('log')->save('webhookstest', 'hook works'); }); and also not this: $webhooks->addHook('Webhooks::handleOrderCompleted', function($event) { wire('log')->save('webhookstest', 'hook works'); }); or this: $wire->addHook('Webhooks::handleOrderCompleted', function($event) { wire('log')->save('webhookstest', 'hook works'); });
-
Hang in there and stay healthy!
-
Austria 2020-03-13 14:00: 361 Covid-19 cases, 1 dead. Starting with coming Monday all shops (except grocery stores, post office, banks, gas stations and similar) closed, schools closed! Some ski areas under complete quarantine. Borders closed. People are hoarding shops. It's really creepy! This is how I imagine the beginning of the Zombie Apocalypse! But our neighbor country Italy is hit much harder: about 15.000 cases, more then 800 dead! Hold on through people!
-
What would be the benefit of making a custom helper class a module?
-
module SnipWire - Snipcart integration for ProcessWire
Gadgetto replied to Gadgetto's topic in Modules/Plugins
I’ll have a look at this! BTW, could you please file your issues on SnipWires GitHub repo? it is hard to keep the overview here in the forum.- 231 replies
-
- shopping cart
- snipcart
-
(and 2 more)
Tagged with:
-
module SnipWire - Snipcart integration for ProcessWire
Gadgetto replied to Gadgetto's topic in Modules/Plugins
I just read you’d like to use subscriptions feature? Subscriptions are not yet supported by SnipWire.- 231 replies
-
- shopping cart
- snipcart
-
(and 2 more)
Tagged with:
-
module SnipWire - Snipcart integration for ProcessWire
Gadgetto replied to Gadgetto's topic in Modules/Plugins
Do you have a hook on path method of PagefilesManager class? I’ll try to reproduce this behavior, but I’d need more infos. Could you please send me the complete stack trace of the exception? You can use TracyDebugger for this. How does your product template look like?- 231 replies
-
- shopping cart
- snipcart
-
(and 2 more)
Tagged with:
-
Hi guys (didn't see any gals here), I have a module which has some custom helper classes. One of these classes has methods which are hookable. The class is derived from WireData. An additional complication is that this class has its own namespace. What would be the correct way to provide the hookable methods via API? Here is a very simplified code sample of the class: <?php namespace SnipWire\Services; use ProcessWire\WireData; use ProcessWire\WireException; class Webhooks extends WireData { ... public function ___handleOrderCompleted() { if ($this->debug) $this->wire('log')->save( self::snipWireWebhooksLogName, '[DEBUG] Webhooks request: handleOrderCompleted' ); $this->responseStatus = 202; // Accepted } public function ___handleOrderStatusChanged() { if ($this->debug) $this->wire('log')->save( self::snipWireWebhooksLogName, '[DEBUG] Webhooks request: handleOrderStatusChanged' ); $this->responseStatus = 202; // Accepted } ... } The class itself is invoked/used by a hook from within the main module: Depending of the event, one of the methods of the Webhooks class above is triggered. A developer should now be able to use one of the ___handle* methods to do further things. /** * Check for webohook request and process them. * (Method triggered before ProcessPageView::execute) * */ public function checkWebhookRequest(HookEvent $event) { if ($webhooksEndpoint = $this->get('webhooks_endpoint')) { if ($this->sanitizer->url($this->input->url) == $webhooksEndpoint) { /** @var Webhooks $webhooks Custom ProcessWire API variable */ $this->wire('webhooks', new Webhooks()); $this->wire('webhooks')->process(); $event->replace = true; // @note: Tracy Debug won't work from here on as normal page rendering is omitted! } } } Should I provide a custom API variable e.g. $webhooks? Or how is the best way to do this?
-
module SnipWire - Snipcart integration for ProcessWire
Gadgetto replied to Gadgetto's topic in Modules/Plugins
@creativejay I must admit, now I've gotten myself into a bit of a mess. Unfortunately, most of the hookable methods are not yet ready. I am currently working on the final implementation. Sorry, you'll have to be patient. i’ll let you know when it is ready.- 231 replies
-
- 3
-
-
- shopping cart
- snipcart
-
(and 2 more)
Tagged with:
-
module SnipWire - Snipcart integration for ProcessWire
Gadgetto replied to Gadgetto's topic in Modules/Plugins
Hi @creativejay, you can hook into SnipWire‘s predefined webhook methods. Please have a look into the Webhooks class starting at this lines: https://github.com/gadgetto/SnipWire/blob/8d38ced82bbfc5633a3d6de7cae6217fcd408c39/services/Webhooks.php#L312 For creating/importing products it would be best to write a small importer using the PW API which creates SnipWire (ProcessWire) pages.- 231 replies
-
- 1
-
-
- shopping cart
- snipcart
-
(and 2 more)
Tagged with:
-
module SnipWire - Snipcart integration for ProcessWire
Gadgetto replied to Gadgetto's topic in Modules/Plugins
UPDATE 2020-03-03 SnipWire 0.8.4 (beta) released! This update improves compatibility for Windows based Systems (thanks @bernhard for your help!)- 231 replies
-
- 2
-
-
-
- shopping cart
- snipcart
-
(and 2 more)
Tagged with:
-
module SnipWire - Snipcart integration for ProcessWire
Gadgetto replied to Gadgetto's topic in Modules/Plugins
Thanks @Jens Martsch - dotnetic for reporting back!- 231 replies
-
- 1
-
-
- shopping cart
- snipcart
-
(and 2 more)
Tagged with:
-
Module uninstall when Fieldtype is still in use?
Gadgetto replied to Gadgetto's topic in Module/Plugin Development
Thanks @bernhard, problem solved! I decided to use the "convert field type" method. -
module SnipWire - Snipcart integration for ProcessWire
Gadgetto replied to Gadgetto's topic in Modules/Plugins
UPDATE 2020-03-01 SnipWire 0.8.3 (beta) released! In this new release the installation and uninstallation process has been heavily revised! The module and its submodules should now uninstall perfectly. To preserve the full products catalogue and products data, all fields with the custom field type FieldtypeSnipWireTaxSelector are now converted to FieldtypeText on uninstall. If yo want to reinstall SnipWire and reuse your previous products catalogue, you simply need to change the taxes field back to FieldtypeSnipWireTaxSelector. Here is the complete list of changes: Updated products package installer to add specific module config on install The uninstallation process is now much more reliable FieldtypeSnipWireTaxeSelector is now uninstalled properly (existing fields are converted to FieldtypeText) Refactored ExtendedInstaller class to be more reliable Extended resources installer page is now more user friendly Fixed product price JSON output if a currency field is missing Small fixes and code enhancements Updated apexcharts.js vendor plugin to version 3.15.6- 231 replies
-
- 3
-
-
- shopping cart
- snipcart
-
(and 2 more)
Tagged with:
-
Module uninstall when Fieldtype is still in use?
Gadgetto replied to Gadgetto's topic in Module/Plugin Development
I still have no idea on how to handle this problem within my module (SnipWire) properly. The main module comes with 3 required sub-modules and one of them is a custom field type. The custom field type has dependencies in helpers classes of the main module. What should I do if someone tries to uninstall the main module but the custom field type is still in use? Should I prevent uninstallation of the complete module package? Or let the user uninstall the main module but only let the custom field type installed (which would lead to problems because of the dependencies)? One idea is to convert the field which uses the custom field type to a simple text field when the custom field type is uninstalled.