Here for the community? On May 9th, we'll be in New Orleans. Don’t miss out!
Trivial patch. Whether this is correct or needs deeper work I do not know. I can't find anything broken at least.
Thanks, chx. I'm worried about what would happen throughout line item price calculation / order total calculation if we have an empty price. Theoretically speaking, products should never not have a value in the commerce_price field... hmm, unless it was unset during calculation but a line item was still created based on it. I don't suppose you can share how you ran into the notice so I can play with it locally?
This fixed the issue for me. Thanks.
(Note: I had trouble applying the patch — ended up applying the changes manually.)
I ran into it after I created test products and orders using Commerce Devel, so I was assuming this notice was a result of improperly configured orders being generated by that module. Thought it may help you get on the right track to figuring out if this is a result of Drupal Commerce or of another module's usage of the API.
A little more information. This seems to happen with Commerce Devel when I generate products and related product displays when the product display's product reference field does not support the type of product being generated. So, in my experience this seems to be a result of some issue with the product reference field, which I know from working with the code deals in line items (though I'm admittedly not that savvy about what's going on in there). Of course, Commerce Devel can do things that a user may not be able to do through the UI, but hopefully this little bit of information can help you track down what might be the cause in a scenario where a user can cause this issue (if it exists).
That's a good lead; technically speaking, you shouldn't end up with a product type that doesn't have a commerce_price field, but it sounds like perhaps Commerce Devel is generating products that have don't end up getting a commerce_price property on them even if the field should be there.
I guess the question then is do we want to pass the same problem along to the created line item? Or should we perhaps set $commerce_line_item->commerce_unit_price to some alternate value, such as a price with a NULL amount which we do actually use elsewhere to represent the inability to find a price for a product.
notice_1093.patch queued for re-testing.
The last submitted patch, notice_1093.patch, failed testing.
I think for now I'm going to postpone making a change to commerce_product_line_item_populate(), as I can't really figure out how to create this scenario. I took a clean install of Kickstart 1.x and first manually deleted the price data for a product from the database and then deleted the value of a required product reference field but got different notices, not the one reported.
However, having fixed a separate issue with chx, I believe the original report may have been caused in some roundabout way by a migration updating a product but from entity_create() (i.e. with a half-formed product entity, one without its price field) and perhaps saved that incomplete product entity in the cache and tried to create a line item using that cached product later. That's a pretty roundabout process, but I was also unable to reproduce the precise notice by simple using entity_create() to whip up a new product and pass it through commerce_product_line_item_new().
In the end, I think I want to fall back on the function's doc block, which specifies that $product should be a "fully loaded product entity." There can be no fully loaded product entity that doesn't have a commerce_price field, and if a site is generating one and trying to pass it through this function, I think it's better for there to be a notice than to silently assume the price is NULL as I suggested above.
@chx - perhaps we need to file a bug report in Commerce Migrate if you're using that to create your products / product displays?
To the others in the thread, if you continue to have issues with Commerce Devel, I'd file a bug report in its issue queue.
To anyone who's using the patch in production, I'd advise you to get to the source of why you have a product without the commerce_price field. I don't think you'll have any negative consequences from a user facing standpoint, because Commerce will just assume the price is NULL and therefore render the product unpurchasable in the Add to Cart form.
Reopening this without interacting with previous comments is not helpful.
Apparently the issue still occurs in version 7.x-1.11.
I've applied the same solution, but now the code is at row 1374.
I'm facing the same problem in version 7.x-1.11 .
It occured when transferring configuration from a development site to a live site using features. I did enable all commerce modules & dependencies in one go. My products don't have a commerce_price field so I can't add a price..
EntityMetadataWrapperException: Unknown data property commerce_product. in EntityStructureWrapper->getPropertyInfo() (regel 335 van /home/welzijnszorg/drupal/sites/all/modules/entity/includes/entity.wrapper.inc).
commerc_repaire module didn't fix this
Drupal is a registered trademark of Dries Buytaert.