When using custom order bundles (even if not recommended) which don't contain the commerce_discounts field, the module throws a critical exception. We need to check the existence of the commerce_discounts field before attempting to read from it via the wrapper.
EntityMetadataWrapperException: Unknown data property commerce_discounts. in EntityStructureWrapper->getPropertyInfo() (line 335 of
...../commerce_kickstart/modules/contrib/entity/includes/entity.wrapper.inc).
This was previously fixed in #1835528: commerce_discount_usage_commerce_order_insert function crash others module using bundle of commerce_order entity type., but a rewrite has re-exposed it.
Comments
Comment #1
andyg5000Comment #2
gonzalves CreditAttribution: gonzalves commentedI did apply this patch and still I have the issue. I am using Commerce Marketplace as well. This error happens when I try to add/edit any product. Not able to do anything with discounts module activated... (I have not even activated usage module) Please help...
Comment #3
andyg5000Hey @gonozalves,
The error is a generic exception whenever you try to use a wrapper to read from an undefined property. In this case, the issue was with commerce discount. It's trying to access $order->commerce_discounts->value() which may not exist on all order bundles. I'm not familiar with marketplace, but your error could be completely unrelated. You can try to backtrace the error on line 335 of the entity.wrapper.inc class to see what property the code is trying to access.
Comment #4
andyg5000After looking through commerce marketplace and commerce discounts, I think there are still places to be fixed in commerce discounts as you've suggested. We need to make sure that anywhere *wrapper*->commerce_discounts is read/written to, that we check the existence of the field first. I'm setting this to needs work so that we can go through the module and update every instance with one patch.
Comment #5
andyg5000Here's an updated patch that checks the wrapper properties existence before attempting to read/write to it in all instances.
Comment #6
gonzalves CreditAttribution: gonzalves commentedHi Andy, thank you very much for your quick response... unfortunately, this patch failed.. did not apply at all... thanks again.. rodrigues.
Comment #7
andyg5000Make sure you've reverted the change from the previous patch. The easiest way would be to grab a fresh copy of the dev release and apply it to that. I just tested locally and it worked fine.
Comment #8
gonzalves CreditAttribution: gonzalves commentedHi Andy, I did a manual patch and it seems to be working absolutely fine!! Thanks a ton Andy...
Comment #9
GuGuss CreditAttribution: GuGuss commentedHi,
I've applied your patch properly but stil get the same error when accessing a product page.
Not sure what to do from here ;-)
Comment #10
andyg5000Hey @guguss,
What modules are you using that define a new order bundle (marketplace)? Also, are you able to backtrace the calls on line 335 of entity.wrapper.inc? If you don’t have debug setup, you can put dpm(debug_backtrace()) on line 334 (with devel module enabled). From there, you should be able to see which line from commerce_discoutns is attempting to access the commerce discounts property. There’s a possibility that it’s another module that integrates with commerce_discount, or I may have missed a call in my patch. I’m on #drupal-commerce IRC if you want to chat on this.
Comment #11
andyg5000@guguss,
I missed you on IRC it looks like. However, your screenshot shows me that the issue is in commerce coupon. "Unknown data property commerce_coupons" and not commerce_discounts (as related to this issue). I'm creating an issue there and will supply a patch as well.
Comment #12
andyg5000Comment #13
andyg5000@guguss, checkout #2301043: Empty check on $order->commerce_coupons to prevent fatal error for your issue with the coupon module. Feedback on that would be great as well!
Comment #14
gonzalves CreditAttribution: gonzalves commentedAndy, You are the best!! I applied the next 2 patches and now the issue with my coupon module is also gone. I was not able to enable the coupon module.
Comment #16
bojanz CreditAttribution: bojanz commentedI've committed Andy's fix from #5. The bug is now resolved.
However, we really should support multiple order types, either by creating the field on all found order types, or by having a setting where you can choose which order types should be supported.
Once that is done, this commit ("fa79c63") can be reverted.
Comment #17
andyg5000I would vote for a setting where you can select the order bundles that have discounts. In which case the patch can be reverted and we can replace field checks with settings checks if that makes more sense.
Comment #18
gonzalves CreditAttribution: gonzalves commentedI also vote. Andy, if I use this commit, will it affect my implementation with Marketplace (since you you know my situation well) ?
Comment #19
andyg5000@gonzalves. You already have the commit applied to your instance. The good news is that if you grab a -dev version of this module it's now included so you don't have to re-apply the patch when you update the module. For now you can just keep your module the way it is.
Comment #20
gonzalves CreditAttribution: gonzalves commentedOk.. Thanks Andy..
Comment #21
yurg CreditAttribution: yurg commentedHi,
Have found this thread (and related closed one at #2301043: Empty check on $order->commerce_coupons to prevent fatal error ) since we're using Marketplace and have same issue with coupon / discount line item missed at order bundle created by Marketplace. We're using 2x-dev version of Coupon and dev version of Commerce Discount where all mentioned in both threads patches should be applied ( http://awesomescreenshot.com/03344r8i9b ); still, coupon is being applied to *native* Commerce order, ignoring Marketplace order, which is an it's exact copy bundle of Commerce order. Guess we're in same situation @gonzalves had but not sure what else should be done since we've carefully tried all steps advised. Would really appreciate any help and/or piece of advice.
Thank you in advance!
Comment #22
matthiasm11 CreditAttribution: matthiasm11 at MM-Experience commentedThe commerce_coupon module adds its commerce_coupons field to each type of orders. (without a settings form)
Programmed the same approach for the commerce_discounts field in the attached patch.
Comment #23
joelpittetThat looks like a reasonable patch to get in. Could someone give this a thumbs up(RTBC) and I'll commit.
Comment #24
matthiasm11 CreditAttribution: matthiasm11 at MM-Experience commentedClosing this issue since the patch (with exactly the same code and purpose) has already been copied and committed in https://www.drupal.org/project/commerce_discount/issues/1872922#comment-...