AbanteCart Community

AbanteCart Development => Extensions and Add-Ons => Topic started by: dhigz on July 16, 2020, 08:22:27 PM

Title: Best place to hook for a completed order?
Post by: dhigz on July 16, 2020, 08:22:27 PM
Hi,

What is the best controller and method to hook to in order to capture a successfully completed order with payment made. Is ControllerPagesCheckoutSuccess the best controller? Or do you recommend another controller/method?

I do see the value for $this->session->data['processed_order_id'] is created after validation. Are there any other indicators of a successful order?

Thanks.
Title: Re: Best place to hook for a completed order?
Post by: abolabo on July 17, 2020, 03:36:06 AM
you can write hook directly to model.
Also you can play with func_get_args() there ;-)
See public_html/storefront/model/checkout/order.php:330 for details.

Code: [Select]
public function afterModelCheckoutOrder_confirm() {
       /* @var ModelCheckoutOrder * /
      $that = $this->baseObject;

     //YOUR CODE HERE
}

P.S. btw same trick works with "create" method
Title: Re: Best place to hook for a completed order?
Post by: dhigz on July 17, 2020, 03:06:51 PM
Thanks abalabo,

I see the hook for this function as well as others. Not sure why it did not notice them before. I did find some hooks in the core/lib/order.pdf file specifically $this->extensions->hk_ProcessData($this, 'build_order_data', $order_info);.

If I want to add data to the build_order_data function $order_info array, what would be the proper function name to use?

Thanks
Title: Re: Best place to hook for a completed order?
Post by: dhigz on July 18, 2020, 01:05:40 AM
abolabo,

I seem to have run into another issue. I created the function afterModelCheckoutOrder_confirm() and I am able to get the order_id value with func_get_args(). But it seems not matter what I do I cannot call a query in the normal manor:  $that->model_catalog.... I even tried loading the model with this instead of that and using this-> for the query and they did not work either. I get the error: Call to a member function queryName() on null.

My assumption is that since I am not actually hooking on a controller, the normal rules do not apply. Any suggestions of how I can get a query to work in this case?