luigidefra Posted August 12, 2020 Share Posted August 12, 2020 hi guys, i have a doubt from hooks documentation i see ----------------------------------------------- ShoppingCartCheckoutCompletePage Executes when the Complete Page is displayed on checkout. -------------------------------------------------------------------------------------- but when I complete an order from the shopping cart, the hook starts before displaying the Complete Page. I notice this because when I complete an order the checkout page remains blocked, with loading in progress, until the hook finishes processing what it has to do 0 Quote Link to comment Share on other sites More sharing options...
WHMCS Dan Posted August 12, 2020 Share Posted August 12, 2020 This would seem to be expected behaviour as the hook code would be executed before returning the results to the browser (to show the complete checkout page). Are you having a particular issue with this currently? 0 Quote Link to comment Share on other sites More sharing options...
luigidefra Posted August 17, 2020 Author Share Posted August 17, 2020 On 8/12/2020 at 9:02 PM, WHMCS Dan said: This would seem to be expected behaviour as the hook code would be executed before returning the results to the browser (to show the complete checkout page). Are you having a particular issue with this currently? but documentation say "Executes when the Complete Page is displayed on checkout." therefore after complete page is displayed or not? --------------------------------------- Then I have a hook that takes a long time and I have two problems. 1. Checkout waits for confirmation until the hook ends, isn't there a way to start it in the background? 2. I have the same method in hooked to two hooks, one is the one mentioned "ShoppingCartCheckoutCompletePage" the other is "OrderPaid". If the method starts from the "OrderPaid" hook, I will still have to wait for the method to finish working but I can still navigate within my admin area, if instead the method starts from the "ShoppingCartCheckoutCompletePage" hook in addition to waiting for the method to finish to process to get to the CheckoutComplete page, I can't navigate my admin area, if I try to update any page the server keeps me waiting for an answer. Why? 0 Quote Link to comment Share on other sites More sharing options...
Wouter0100 Posted August 17, 2020 Share Posted August 17, 2020 By default, PHP can't be further excecuted after a page is already returned to the browser (there are some workarounds available though). The documentation could be clearer in by making it something like: `Executes when the Complete Page is rendered and before displayed to the browser on checkout.` To do it fully in the background, you should make a cron (or extend WHMCS's cron) for it. The fact that your browser hangs on other pages aswel, is something related to your webserver or browser - most likely. 0 Quote Link to comment Share on other sites More sharing options...
luigidefra Posted August 18, 2020 Author Share Posted August 18, 2020 18 hours ago, Wouter0100 said: By default, PHP can't be further excecuted after a page is already returned to the browser (there are some workarounds available though). The documentation could be clearer in by making it something like: `Executes when the Complete Page is rendered and before displayed to the browser on checkout.` To do it fully in the background, you should make a cron (or extend WHMCS's cron) for it. The fact that your browser hangs on other pages aswel, is something related to your webserver or browser - most likely. Thank you very much, how can I extend whmcs cron? Do you have any guide? ------------------------ The fact that it only hangs if the method is started by the "ShoppingCartCheckoutCompletePage" hook makes me think that it is not a problem related to the web server or browser otherwise it would hangs with both hooks. Anyway I should solve with the cron 0 Quote Link to comment Share on other sites More sharing options...
Wouter0100 Posted August 18, 2020 Share Posted August 18, 2020 (edited) There's no real guide available, as far as I know. You should be able to create a class that extends `\WHMCS\Scheduling\Task\AbstractTask` like so: <?php namespace YourName; class YourTask extends \WHMCS\Scheduling\Task\AbstractTask { protected $defaultFrequency = 60; protected $skipDailyCron = true; public function __invoke() { // do whatever you desire the most } } When you initialize your module or addon, call \YourName\YourTask::register() statically. It'll be registered in the `tbltask` and should be invoked every minute. You could also use one of these hooks (for example, `AfterCronJob` should also run every minute if you run your cron every minute). And: most likely `OrderPaid` is executed in the background (as the payment is processed in the background aswel). This happens by a request from your payment service provider back to your WHMCS installation. This request will hang/wait. Edited August 18, 2020 by Wouter0100 Addition for OrderPaid 0 Quote Link to comment Share on other sites More sharing options...
luigidefra Posted August 18, 2020 Author Share Posted August 18, 2020 30 minutes ago, Wouter0100 said: You could also use one of these hooks (for example, `AfterCronJob` should also run every minute if you run your cron every minute). Thank you so much, I am following this way, It seems the simplest! 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.