I've found that if (for what ever reason) one or more of the line items an order is referencing are missing (deleted) that will prevent the order from being deleted. Trying to delete an order with missing line items results in the following error:

EntityMetadataWrapperException: Unable to get the data property line_item_id as the parent data structure is not set. in EntityStructureWrapper->getPropertyValue() (line 442 of /var/www/matkavekka.dev.wunder.io/drupal/current/sites/all/modules/contrib/entity/includes/entity.wrapper.inc).

Comments

aleksijohansson’s picture

Status: Active » Needs review
StatusFileSize
new1.08 KB

Check that the referenced line items exists when an order is being deleted.

aleksijohansson’s picture

StatusFileSize
new2.45 KB

Changed the method used in the patch for checking to getBundle since dataAvailable is a protected method.

rszrama’s picture

mglaman’s picture

Status: Needs review » Needs work
+++ b/modules/line_item/commerce_line_item.module
@@ -374,11 +374,15 @@ function commerce_line_item_field_attach_delete($entity_type, $entity) {
+        if ($line_item_wrapper->getBundle()) {

$line_item_wrapper doesn't exist as a variable.

mglaman’s picture

Status: Needs work » Needs review
StatusFileSize
new1.25 KB

The proper way to handle this is by implementing Try/Catch. We're encountering an unexpected reference due to the line item being deleted outside of the referencing entity's knowledge. So in the event of EntityMetadataWrapperException we should catch it and just carry on instead of adding other logic to check data values (which could still cause exceptions.)

aleksijohansson’s picture

@mglaman You're completely right, thanks for the patch! Testing this out now.

aleksijohansson’s picture

Status: Needs review » Reviewed & tested by the community

Seems to be working fine!

aleksijohansson’s picture

rszrama’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for the patch(es) and review. Committed!

  • rszrama committed 97e9d40 on 7.x-1.x authored by mglaman
    Issue #2485529 by mglaman, aleksijohansson: resolve an error deleting...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.