Good evening.
I am facing the last days a major issue with this exception.
I have installed commerce_coupon and commerce_shipping latest dev versions. Each time i enter a coupon code or choose a shipping method during the checkout proccess, in the next step (review pane) i get this message EntityMetadataWrapperException: Unknown data property commerce_product.
I have seen lots of reports about this problem but still exists.
I have installed Commerce repair, reconfigured all my fields and also checked them throughout the field list.
So i think that this exception doesnt occur from any field missing. Also i unistalled the EntityCache module in order to exclude cache issues.
My thought is that maybe i need to update Entity API and Views to the latest dev versions. I am using the recommended versions in both of them.
Do you have any other idea about what might cause this exception?
Thanks in advance
Comments
Comment #1
rszrama commentedYou didn't need to open a separate issue... updating #1315598: EntityMetadataWrapperException: Unknown data property commerce_product for contributed modules even if I closed it would have been fine. ; )
I'm not going to leave this open, as you still do have an open issue in the Coupon queue. Your install may be just fine, but it could be that the contributed module has a reference to a field that doesn't exist. The only thing you need to do to check is look at your product line item type's "Manage fields" display and make sure it has the commerce_product field. Find this at:
Store > Configuration > Line item types > Product > Manage fields
If it's there, then it's almost certainly a problem with the other module. If it doesn't have that product reference field, then we need to figure out why the repair didn't work for you. : )
I'm marking this one a duplicate again, but please feel free to update it if you need further assistance.
Comment #2
frixos12 commentedForgive me for duplicating this issue. I didnt see your first reply and thank you for your post
So, commerce_product field is shown in admin/commerce/config/line-items/product/fields
Also it is shown on the field list "commerce_product (Locked) -- Product reference -- Product".
I also checked the database tables "field_config" and "field_config_instance" and everything seems ok.
So i agree there is a problem with the other module but is there a possibility that i might need to clear the entity info cache?
Does this might fix my problem?
thank you
Comment #3
rszrama commentedNah, if all that is there and you can add products to the cart, then the problem almost certainly lies within the Coupon module (or another module) attempting to use a non-product line item in a function that expects to receive a product line item. Or it could just be that the module's own code thinks the commerce_product field will exist on a line item that it does not. You could start by searching the commerce_coupon code for any references to commerce_product. If you can't find any, then it may be doing the first thing I mention - passing a coupon line item to a function that expects to receive a product line item.
Comment #4
frixos12 commentedIs the above function might be an issue? (use a non-product line item in a function that expects to receive a product line item)
The code is inside the commerce_coupon.module file
/**
* Creates a new product line item populated with the proper product values.
*
* @param $coupon
* The fully loaded coupon to add.
* @param $order_id
* Order to add this coupon.
*
* @return
* Line item object with default values.
*/
function commerce_coupon_line_item_new($coupon, $order_id) {
// Create the new line item.
$line_item = entity_create('commerce_line_item', array(
'type' => 'coupon',
'order_id' => $order_id,
'quantity' => 1,
));
$line_item->sku = $coupon->type . '_' . $coupon->coupon_id;
if (!($line_item instanceof EntityMetadataWrapper)) {
$line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);
}
$line_item_wrapper->commerce_coupon_reference = $coupon->coupon_id;
// Return the line item.
return $line_item_wrapper->value();
}
Comment #5
rszrama commentedHmm, as long as it's properly detecting that that line item's type is coupon, wrapping it there shouldn't give you any errors. The entity_metadata_wrapper() can properly detect the bundle type (coupon vs. product) and shouldn't attempt to add wrappers for fields that aren't present on that bundle.
Comment #6
frixos12 commentedThank you for your post again.
So, i searched my database tables and found that when i enter a coupon code during the checkout process , in the commerce_line_item table two rows are added.
One for the product and one for the coupon as different line items. But the "line_item_label" field is empty for the coupon. Shouldn't be a value for this field?
Does this maybe causing this exception?
When i delete these two rows from commerce_line_item table and the order from commerce_order table my site recovers.
Also i get this message every time i flush my caches.
Notice: Trying to get property of non-object in commerce_entity_access() line 733 of ../modules/commerce/commerce.module)
Thank you.
Comment #7
rszrama commentedHmm, now that's interesting. Adding a coupon to an order also results in adding a product to the order? Does that product line item have any product reference data associated with it?
Comment #8
frixos12 commentedActually to be more specific, if i have two products in my cart and enter a coupon code, inside the commerce_line_item table the rows will have this format (line_item_id ,order_id, type, line_item_label, quantity )
2 2 product 10001 1.00
3 2 product 10000 1.00
4 2 coupon 1.00
10001 and 1000 are the product's SKU.
So adding a coupon to an order results in creating a new coupon line item each time with no line_item label.
Do i need to clear all my cache database tables with cache_clear_all function?
Just in case there is something in there that may be causing this exception...
Comment #9
bbjay commentedfrixos12, are you still getting Notice: Trying to get property of non-object in commerce_entity_access() line 733 of ../modules/commerce/commerce.module)? I am getting this notice as well when I clear my caches and was wondering if you found a fix. I posted this issue in #1298310: Trying to get property of non-object in commerce_entity_access() error w/ Commerce BPC but haven't found a solution.
Comment #10
vishal.sirsodiya commentedHi,
I have facing same problem, I have follow all above suggestions.
Notice: Trying to get property of non-object in commerce_product_line_item_populate() (line 1352 of