Our site functionality allows an admin to reverse a payment made by a user (drupal.org/project/commerce_reverse_payments), therefore we need to be able to automatically change an order from completed to pending, and from pending to completed when it gets back to a 0 balance. Currently, the logic to fire the rules event and see if this is the first time a user pays in full is in the commerce_payment module, it makes a little more sense to put that logic in a rules condition where it is more customizable and still allowing existing functionality of drupal commerce.

Comments

artkon’s picture

Patch for 7.x-1.3

artkon’s picture

Status: Active » Needs review
rszrama’s picture

Status: Needs review » Needs work

I can't commit the patch as is to the 1.x branch, because it represents a significant API change that would be quite disruptive to sites depending on the current event. However, if you're up to resubmitting the patch, I'd be happy to add the condition code to check if an order has already been marked paid in full before. To determine if an order has been paid in full then without a separate event, you can just use the events pertaining to after a payment transaction has been saved / updated.

artkon’s picture

Makes sense, here is the patch for the additional condition to check for order first paid in full.

artkon’s picture

Status: Needs work » Needs review
damien tournoud’s picture

Status: Needs review » Needs work

I think it would make slightly more sense to allow you to execute an action that says "forget that the order has been paid in full before" (ie. basically resetting $order->data['commerce_payment_order_paid_in_full_invoked']). I don't see how the new condition is actually useful in your use-case.

artkon’s picture

Well, I reverted back to just using the entity rules "After saving a new commerce payment transaction" and condition "Order balance comparison" <= 0. Partly agree with Damien, don't really need the added condition because the previous mentioned condition takes care of that so I would be ok without it. One other suggestion might be to add another rules event "Order paid in full" on top of "Order paid in full for first time" but that just might be too much.

rszrama’s picture

Title: I would like to move the existing logic of the rule event 'When an order is first paid in full' to a condition » Add a Rules action that tells an order to forget that is has been paid in full
Version: 7.x-1.3 » 7.x-1.x-dev
Status: Needs work » Active
Issue tags: +low-hanging fruit

Updating the title and tagging.

rszrama’s picture

Issue summary: View changes

The solution here will be a real simple action that can be modeled off of the commerce_order_update_status action in commerce_order.rules.inc. (Naturally, it will only need the first parameter, and as we discussed and you can review in rules.api.php, you should set the save property for the order parameter to TRUE.) The callback itself should only need to unset the variable in the $order->data array Damien points to above.

nullvariable’s picture

Status: Active » Needs review
StatusFileSize
new2.15 KB

Attached is a patch that adds a rules action to revoke paid in full status on an order. The action does not clear payments from the order. Just the paid in full status.

Status: Needs review » Needs work

The last submitted patch, 10: 1659070.revoke-paid-in-full.patch, failed testing.

rszrama’s picture

Instead of language re: revocation, let's use language about unsetting (code) / resetting (UI) an order's paid in full status.

Machine-name / execute callback: commerce_order_unset_paid_in_full
Label: Reset an order's paid in full status

nullvariable’s picture

StatusFileSize
new2.15 KB

revised patch is attached

rszrama’s picture

One minor change - for string literals inside of t(), we don't want to include any escape characters unless absolutely necessary. That helps simplify translation. Instead, in cases where you have an apostrophe or single quote, use double quotes to wrap the string literal.

nullvariable’s picture

StatusFileSize
new2.15 KB

revised patch to fix quotes/escaping issue

nullvariable’s picture

Status: Needs work » Needs review

The last submitted patch, 13: 1659070.13.reset-paid-in-full.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 15: 1659070.15.reset-paid-in-full.patch, failed testing.

nullvariable’s picture

StatusFileSize
new1.04 KB

fixed encoding

nullvariable’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 19: reset-paid-in-full.1659070-19.patch, failed testing.