The commit in #1872922: EntityMetadataWrapperException: Unknown data property commerce_discounts. causes a new EntityMetadataWrapperException because the entity metadata property of commerce_unit_price is still set in the loop after the line item has been deleted.

Comments

andyg5000 created an issue. See original summary.

joelpittet’s picture

@andyg5000 which loop? And can you try this patch out to see if it helps? #2657792: Cart order totals incorrect after updating line item quanity

andyg5000’s picture

Status: Active » Needs review
StatusFileSize
new712 bytes
andyg5000’s picture

I've confirmed the cart patch mentioned in #2 doesn't solve the problem.

joelpittet’s picture

Any chance you can provide some steps to reproduce, I'd be happy to write a test so we don't regress if it's truely the fix.

joelpittet’s picture

I've not run into this problem yet so I'd like to get to the bottom of it, and at the very least write some docs around why it's needed to be checked. Tests would be better though as they prove more than words.

andyg5000’s picture

This was reported from a client site with 1 enabled % based discount with no conditions. The issue happens when proceeding thru checkout and selecting or unselecting billing same as shipping. I haven't confirmed that this happens on a vanilla install.

joelpittet’s picture

Crappy they spotted it:(

Product or Order discount? Are you using commerce_addressbook for that? Are there any commerce patches being used? I'm assuming that is an AJAX related issue?

andyg5000’s picture

Order and no addressbook. Yea it's the ajax callback and has to do with the line item being deleted, but the line item reference on the order still containing the reference.

joelpittet’s picture

We dug into over google hangout. It seems that during a Commerce Order save, it would load unchanged entity, which called order refresh which does the discount line item saves and eventually gets to the discount usage check and the line item entity load failure.

I'll put in a check and maybe a watchdog to get the callstack and a transaction layer check at the failure but we should open a commerce issue for this. One possibly solution is put a marker while saving the order that refresh is prevented inside a save causing further order saves... needs a proof of concept.

I couldn't reproduce the bug on my environment, but @andyg5000 may give me a something to try.

joelpittet’s picture

I was able to reproduce this locally!

Here's the screenshot of the whole problem. We need to solve saves within saves, IMO.
I'll post a watchdog catch quickfix in the meantime, this aft.

andyg5000’s picture

Woo hoo! In the meantime that patch doesn't change anything that's not already there in the code. It just catches the exception properly. It can cause checkout to be abandoned, so I would vote for applying it until the core issues you've found are resolved.

joelpittet’s picture

StatusFileSize
new1.58 KB

I'm thinking of committing a similar patch with a watchdog. Does this work for you for now @andyg5000?
I'd like to get any more information but maybe that's all we can start collecting in watchdog.

joelpittet’s picture

I've pushed to -dev this for now. Let me know if the watchdog is too much.

goz’s picture

Status: Needs review » Needs work

I don't think issue comes from commerce_discount. Issue comes from a call with an outdated order.
There is a custom or contrib module which uses form_state['order'] object (or object from elsewhere) which is outdated and contains a deleted line item. You should find which module make this to solve your issue.

joelpittet’s picture

@GoZ we went on google hangout for a couple hours to track down in the debugger exactly where the issue @andyg5000 had. We had a minimal stock drupal commerce and I was eventually able to reproduce the problem locally as well as he described by checking off and on the "same as billing"

goz’s picture

@joelpittet may be one of those can help you :
https://www.drupal.org/node/2624586
https://www.drupal.org/node/1804592

joelpittet’s picture

@GoZ not using commerce_addressbook, the #1804592: During AJAX form submission in checkout, the $order argument passed by the Form API is incorrect. may resolve it, but not convinced that solution is correct.

kfitz’s picture

Was not able to reproduce the issue on a fresh install of Commerce Kickstart; steps I used to attempt reproducing issue:
- created new % based discount
- checked off and on 'same as billing' option

The checkout continued as expected. I've tried different discount configurations but have not been able to reproduce the issue. @joelpittet can you provide any more details of reproducing the error.

kfitz’s picture

Status: Needs work » Reviewed & tested by the community

Ok, was able to reproduce now by setting the maximum usage limit on the discount. Like @joelpittet it's related to loading the line item entity when discount usage check occurs. Patch provides graceful failure. Marking as RTBC.

joelpittet’s picture

@kfitz Thanks for testing. There may be a better solution for commerce over here:
#2690765: Prevent entity_load_unchanged() from changing orders through order refresh

Discount makes that problem evident but I think the problem is with loading unchanged orders during a save causing more saves during the refresh

joelpittet’s picture

Status: Reviewed & tested by the community » Needs work

Yeah we need to solve the issue mentioned in #22 for a proper fix

czigor’s picture

Status: Needs work » Closed (works as designed)

I suppose this can be closed as #2690765: Prevent entity_load_unchanged() from changing orders through order refresh has been fixed. I could not reproduce it at least by triggering the copy shipping to billing address ajax and going back and forth in checkout with a % order discount.