Closed (won't fix)
Project:
Commerce Core
Version:
7.x-1.x-dev
Component:
Rules integration
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
24 Feb 2013 at 18:18 UTC
Updated:
29 May 2013 at 03:18 UTC
Currently the only event that reacts on order deletion is "After deleting a commerce order.".
However, if you need to do some tasks depending on the orders line items properties you can't do this because at this time the line items are already deleted. The $order object passed to the event lists the line items ids but you can't load the line items anymore.
So there there needs to be a hook/event that fires before they get deleted.
In the meantime - is there a workaround?
Comments
Comment #1
rszrama commentedI don't see us adding such a hook specifically for orders; right now the hooks / events we use are pretty standard for entities across all Drupal modules. Depending on what you're trying to do, I'd either hook into hook_commerce_line_item_delete() or implement my own hook_field_attach_delete() in a custom module weighted to execute before the commerce_line_item.module's implementation. Referenced line items get deleted on that hook, which receives the full original referencing entity as well, so you can do what you need based on the order being deleted and the referenced line items.
See commerce_line_item_field_attach_delete() for more info.
Comment #2
haggins commentedThank you! Sounds good, I will loook into this.
edit: hook_field_attach_delete() is exactly what I need. Thanks for that idea! This saved my day.
Comment #3
ThaJoa commentedHi
I need something like this too.
I want to remove a role from the user who owned the order. I need to read out the user and the product sku for this.
How did you do this? What does your hook look like?
Comment #4
haggins commentedJust as an example:
I recommend reading this article if you are not familiar with entity_metadata_wrapper.