Jump to content
Sign in to follow this  
luigidefra

Strange behaviour ShoppingCartCheckoutCompletePage Hook

Recommended Posts

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

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites
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?

 

Share this post


Link to post
Share on other sites

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. 

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

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 by Wouter0100
Addition for OrderPaid

Share this post


Link to post
Share on other sites
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! 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated