Needs review
Project:
Commerce Coupon (D7)
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
28 Mar 2013 at 14:56 UTC
Updated:
21 Jan 2015 at 17:39 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
pcambraDo you mean that when manually removing a coupon through the UI it should be an event/hook or both to be able to react and remove also whatever extra stuff was granted with the coupon?
Comment #2
pvhee commentedExactly. For example, to allow to take off a free product granted via a previously applied coupon, or something of that sort.
Comment #3
pcambraMakes sense, patches are welcome :)
We could use rules_invoke_all to have both a hook and a rules event.
Comment #4
pvhee commentedHere you go, a first try :)
I am using rules_invoke_all, I created the rules event, and also documented the hook in the api.php. Tested with some dummy rule that removes all products from the cart after the coupon is removed.
My use case really is to remove a product that was added through a coupon to the cart (in the style of "buy 3 get 1 free" coupon), but for this I need to sort out #1267156: Create a "Remove single item from cart" action or go with code for the free product removal.
Comment #5
pcambraLooks good, but if you want to expose it both as a hook and an event, you need to use rules_invoke_all instead of rules_invoke_event, the later would just expose an event and you're documenting it as a hook as well.
Comment #6
pvhee commentedUpdated patch attached, thanks for the review!
Comment #7
pcambraOk, took a closer look to this and I have second thoughts.
You could use the default entity delete hook/rules event for this the way that this is implemented, I don't see a difference between this event and using "After deleting a commerce coupon" from Entity API.
What needs to happen here is to execute this event *just* when the coupon is deleted from the form that the customer sees.
I guess you could accomplish this using the event above and the user id, but it might not be the case if someone is managing the order on behalf of the customer (i.e. customer service)
Comment #8
Scott Robertson commentedI think there may have been some confusion on what this event would be for. Based on pvhee's patch, I believe he wants an event to be fired when a customer manually removes a coupon from their order during checkout, not when you delete a coupon entity through the admin interface.
If that's the case, then I believe the patch he provided would still be useful.