Registrations saved in commerce_registration_commerce_checkout_complete are writing over changes made by Rules

Created on 13 November 2015, over 9 years ago
Updated 28 February 2025, about 2 months ago

Problem/Motivation

Note: I have disabled the default rule "Set Registrations to Pending upon Order Completion" and I'm still using the rule "Set Registrations to Complete upon Full Payment."

What I found while testing was that all of my registrations were still set to "Pending" (the default) when the order was completed and paid in full.

It looks like whatever changes being made to the registration in commerce_registration.rules.inc (in the commerce_registration_set_state function) are overridden when the order's closed by commerce_registration_commerce_checkout_complete (in commerce_registration.module).

In commerce_registration.rules.inc there's a db_select used to fetch the registration IDs from the database based on the order's ID. The registration object is populated by registration_load($row->registration_id), the status is set, and then it's saved using registration_save($registration).

This happens when the order is paid in full. After this, when the checkout is complete, the commerce_registration_commerce_checkout_complete hook fires. The code in this function fetches the registrations again, but instead of doing a db_select it grabs an earlier copy of them out of the $order object, then re-saves them. The copy of the registrations stored in the order does not reflect the changes previously made (and saved) in the Rule, so those changes are overridden by the earlier "Pending" copy of the registration entity.

Proposed resolution

Either the commerce_registration Rules should just modify the copies of the registrations stored in the $order object, or (perhaps) the re-saving of the registration entities in the commerce_checkout_complete hook is unnecessary.

I'm not sure what removing the commerce_checkout_complete hook would break otherwise. If we do decide to change how the Rules work though, there's a handful of other action callbacks that likely all have the same issue. I'm leaning towards removing the checkout_complete hook.

Remaining tasks

Decide which of the resolutions could work, or if I'm completely off base and there's a simpler solution.

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Closed: outdated

Version

2.0

Component

Checkout

Created by

πŸ‡¨πŸ‡¦Canada adamwhite

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024