This is an issue about providing hooks to other code. We want to make it easy for people to write custom modules for themselves instead of having to rely on Conditional Actions for absolutely everything. So, we need to make sure that there are hooks whenever there is a call to ca_pull_trigger().

Once that's done, we should also think about moving those calls to a hook implementation, which puts the CA predicates on the same footing as a hook implementation. These can be handled differently in each, and may not be necessary.

Please, give comments, thoughts, and ideas.

Comments

Island Usurper’s picture

Status: Active » Needs review
StatusFileSize
new2.35 KB

Here's a start towards this goal. I decided to put the hook implementations in ca.module on a whim. It won't bother me if they're put back in the modules that call them.

There are surprisingly few CA triggers in Ubercart. Most of them actually involve sending notification emails, and I haven't figured out yet what to do with them. A few were already associated with hooks, like updating the order status, so I left those alone. This left two triggers: uc_checkout_complete and uc_payment_entered

rszrama’s picture

Status: Needs review » Needs work

I think I'd prefer leaving the trigger pulling to happen alongside of the hook invoking, primarily to avoid cluttering up ca.module but for other reasons related to readability, debuggability, and availability of other variables in the original context.

Island Usurper’s picture

Status: Needs work » Needs review
StatusFileSize
new4.18 KB

OK, that makes sense. I also figured that the uc_payment_entered trigger could use an $account variable as well, even though we don't have any conditions or actions using it at the moment.

Island Usurper’s picture

StatusFileSize
new5.88 KB

From a feature request at the Ubercart.org forums, I've added a trigger that is fired when a shipment is saved. There was already a hook in that place, so it makes sense to have both there.

Island Usurper’s picture

StatusFileSize
new5.88 KB

So, I got to wondering why I was always redirected to the cart page after I completed checkout. It turns out that uc_cart_checkout_complete() is already a function, but now module_invoke_all() is calling it again. That's not good, so I've changed the name of the hook to hook_checkout_completed().

Island Usurper’s picture

StatusFileSize
new5.9 KB

OK, one more time. Ryan pointed out that the example hook_checkout_completed() had the wrong name, and we should be using clone when passing in the global $user object so that nothing bad happens to it.

rszrama’s picture

Issue tags: +ubercamp sprint

Tagging.

andreiashu’s picture

Status: Needs review » Needs work

The call to hook_payment_entered should also pass the last inserted payment id. This is really needed for example for refunds and such. More info in #506104: There is not way to know the entered payment/receipt ID. I'm not sure if it should do the same (pass the inserted payment id) to the CA actions.

I've marked #506104: There is not way to know the entered payment/receipt ID as a duplicate of this.

andreiashu’s picture

Status: Needs work » Needs review
StatusFileSize
new5.29 KB

I updated the patch form #6 with the observations from #8.

I didn't update the docs. It needs some reviews first.

cyu’s picture

I'm interested in writing a contrib module that would allow you to use Rules in any place where CA is currently used. Adding these hooks is a great step towards making that a possibility, but speaking to Amitaibu the other day he brought up that shipping quotes were hard coded to conditional actions and had no usable hooks. Would all ca_load_trigger_predicates() calls need hooks in order to make a full replacement of CA possible?

Island Usurper’s picture

Even with the way they're written now, shipping quotes don't use CA the same way that users are meant to. Even if you add extra actions to the quote predicates, they won't actually get run. It doesn't seem like the same kind of use-case that makes Rules integration natural. Now, I could implement Rules the same way here, and probably will eventually, but it will probably be with the same kind of customization prevention that's already in place.

Island Usurper’s picture

StatusFileSize
new8.69 KB

Ryan thought it would be a good idea to name the new hooks after the CA triggers they are associated with.

andreiashu, I'd like for both the hook function and the conditional actions to have the same access to the payments on an order. The real solution, I think, would involve adding data to the $order object in uc_payment_order('load'), but that's really out of the scope for this issue. However, you can run a database query to get all of the payments on an order or call db_last_insert_id() in your hook implementation yourself.

rszrama’s picture

Looks good to me... applying to a test site, but if it's working fine on yours then go ahead and commit.

Island Usurper’s picture

Status: Needs review » Fixed

Committed.

Status: Fixed » Closed (fixed)
Issue tags: -ubercamp sprint

Automatically closed -- issue fixed for 2 weeks with no activity.