This may be related to this issue or this issue, so my apologies if this is a duplicate.
While doing some work with the commerce_coupon module, I needed to solve an issue where a coupon would remain in the cart even though the product it was valid for had been removed. So I created a patch which you can view here. But a coupon is a line item and when a product is removed from the cart, commerce_cart calls rules_invoke_all() just before calling commerce_line_item_delete() and a recursive situation arises where the line item to be removed has already been removed and an EntityMetadataWrapperException is thrown.
To fix the problem I patched commerce_cart.module to pull in the order from the database, reset it, and then save it. I've attached the patch in a comment below for you guys to review and offer any comments, opinions, or better ideas.
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | commerce_cart-1408464-1.patch | 532 bytes | dags |
Comments
Comment #1
dags commentedComment #1.0
dags commentedphrasing
Comment #2
rszrama commentedI'm not following you with how you're generating your recursive loop. Is the Coupon module using this function to remove coupon line items for some reason?
I'm also not sure how this patch fixes anything for you, but whatever it did, it basically makes the save here meaningless, doesn't it? Why load the order from the database just to resave it here? Perhaps the problem is a stale line item reference in the order or something, but I'm going to need more information. The actual error thrown would be helpful, for example.
Reclassifying until we're sure the Coupon module isn't abusing the Cart API.
Comment #3
anibal commentedhere is the error when you remove the item from the cart.
Error
The website encountered an unexpected error. Please try again later.
Status message Coupon removed from order.
Error messageEntityMetadataWrapperException: Unable to get the data property commerce_total as the parent data structure is not set. in EntityStructureWrapper->getPropertyValue() (line 442 of /var/www/sites/dtc/cd-ai.com/subdomains/clientes/html/lusomundo2/profiles/commerce_kickstart/modules/entity/includes/entity.wrapper.inc).
Comment #4
dags commentedThanks anibal.
Recursive might be the wrong word. Stale line-item reference sounds about right. I'm not exactly sure what you mean by that though or how that situation arises. I'm only just starting to get deeper into Drupal 7 module development, so my understanding is a bit limited. I'll try to explain what I was thinking...
Line 1203 in commerce_coupon.module has this function:
I had created an action to 'Remove coupon line item' (see http://drupal.org/node/1295316) and in that patch I decided to call coupon_log_remove() to carry out this action, since it deletes the line item and the log. So when commerce_cart_order_product_line_item_delete() is called it invokes the rule 'commerce_cart_product_remove' which then calls my action to delete the coupon line item. Maybe coupon_log_remove() is the wrong function to use?
Comment #5
dags commentedI believe this was somehow fixed in the latest stable release. After upgrading to 7.x-1.2, my patch was no longer necessary. Marking closed.
Comment #6
rszrama commentedExcellent, glad to hear it.
Comment #7
ofktoubro commented(got and 'solved' a somewhat similar error over here: http://drupal.org/node/1580406)
Comment #8
haradhansharma commentedDuring Checkout process, when clicking on My shipping information is the same as my billing information. below notice are getting, ---- but when entering separate address, then this massage are not showing!!
EntityMetadataWrapperException: Unable to get the data property commerce_total as the parent data structure is not set. in EntityStructureWrapper->getPropertyValue() (line 442
need solution!
Comment #9
finex commented@haradhansharma: I've just opened a new issue about this bug: http://drupal.org/node/1905234
Comment #10
Zac_JH commentedPosted more on this at: http://drupal.org/node/1510172#comment-7236366
Comment #10.0
Zac_JH commentedphrasing