support

Author Topic: Best place to hook for a completed order?  (Read 7542 times)

Offline dhigz

  • Newbie
  • *
  • Posts: 46
  • Karma: +17/-0
    • View Profile
Best place to hook for a completed order?
« 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.
Don Higbee

Offline abolabo

  • core-developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 2063
  • Karma: +325/-13
  • web for all, all for web!
    • View Profile
    • AbanteCart
Re: Best place to hook for a completed order?
« Reply #1 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
“No one is useless in this world who lightens the burdens of another.”
― Charles Dickens

Offline dhigz

  • Newbie
  • *
  • Posts: 46
  • Karma: +17/-0
    • View Profile
Re: Best place to hook for a completed order?
« Reply #2 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
Don Higbee

Offline dhigz

  • Newbie
  • *
  • Posts: 46
  • Karma: +17/-0
    • View Profile
Re: Best place to hook for a completed order?
« Reply #3 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? 
Don Higbee

 

Powered by SMFPacks Social Login Mod