Problem/Motivation
Cart items deleted programmatically without invoking the cart manager can leave detached registrations behind. These registrations should be deleted just like they would be if the items were removed using the cart manager API.
Steps to reproduce
- Install module commerce_cart_redirection.
- Make sure that the checkbox "Clear cart before add" is checked at /admin/commerce/config/commerce_cart_redirection.
- Create 2 products for users to register.
- User registers for the first product without making any payment.
- The same user clicks the Register button for the second product. At this time, the first item is removed from the cart and the second item is added. However, the registration from the first item still exists and is now detached from any item.
Issue fork commerce_registration-3425082
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
franceslui commentedComment #3
john.oltman commentedThanks for the post @franceslui. I tried this on a test system and it works correctly. Also this is a common scenario, for which nobody else has reported a problem. So I suspect that the issue is related to your installation and not a general problem. To help get to the bottom of this, would you be able to provide more information:
* Is either product on a wait list? If you have commerce_registration_waitlist installed, there is a scenario where a registration can move to a different commerce order item on a different order if a registration was on a waiting list and then more room becomes available.
* Does the registration itself still exist? If you go to the Manage Registrations tab for the first product, is the registration still there.
* Is this something that used to work and now no longer does?
* Do you have any custom code that moves registrations between orders, or deletes registrations from carts?
* Does it matter which products. Or does the problem occur with any two products in your store.
* Is it possible the first registration expired - or does the problem occur even when little time has passed between adding the items to the cart.
Let's try to isolate the issue and go from there. For now, I am going to mark this as a support request. We can change it back to a Bug if it turns out this is a general problem with the module.
John
Comment #4
franceslui commented@john.oltman Thank you very much for your quick reply and asking questions to help resolve the issue.
I have found out what caused the issue. So, I have modified the section "Steps to reproduce" to explain how the issue can be reproduced.
To get around the issue, I have added the following code in our custom module:
Do you think you could do something similar in your module? Thank you again for your help.
Comment #5
john.oltman commentedComment #6
john.oltman commentedComment #7
john.oltman commentedComment #10
john.oltman commentedThanks @franceslui, this did turn out to be a bug in the module. Once this is released, you can remove the custom code you added. The registrations for the deleted cart item will be deleted instead of canceled. For now, the fix is committed to the dev branch.
Comment #11
franceslui commented@john.oltman. Thank you very much for your quick reply and fix. I greatly appreciate your help!
Comment #13
tcrawford commentedHi. This fix works fine if an order item is deleted and the cart still exists. The fix does not work in a common use case where the order item is deleted in the postDelete of the order. This happens commonly when an abandoned cart is deleted via CRON. The issue is that the code tries to load the order to check if it is a cart (but can't as it was deleted) and therefore does not clean up the registration. As I can't re-open this issue, I will create a separate issue an link this one.