Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
EntityMetadataWrapperException: Unable to get the data property
currency_code
as the parent data structure is not set. in EntityStructureWrapper->getPropertyValue() (line 442 of /~/~/sites/all/modules/entity/includes/entity.wrapper.inc).
This happens when i am trying to add any product to cart ?!! can not fiend a solution
Comments
Comment #1
rszrama CreditAttribution: rszrama commentedNot enough info here; bug reports need to be reproducible, such as "I installed this module" or "I setup this rule." If this is a vanilla install, try using Commerce Repair to see if a field got missed on installation (though that sort of thing has been happening less and less).
Comment #2
tonyoflow CreditAttribution: tonyoflow commentedi also had a similar problem but the 'currency code' in my case is just 'data' svolved it halfway i think.
since i got the same error when adding to cart and trying to view orders,
i went into the database and whiped clean/did a TRUNCATE on the order spesific tables:
commerce_order
commerce_order_revision
field_data-commerce_order_total
field_revision_commerce_order_total
(!note: deletes current order data.)
and the cart and orders works fine again!
but suddenly i got problems with search_api_index at the 'view all products page'.
And now after i removed the indexes with UI to rebuild again,
i get the same damn error!? when trying to rebuild (..or run cron)
the error:
An AJAX HTTP error occurred. HTTP Result Code: 500 Debugging information follows. Path: /batch?id=154&op=do StatusText: Service unavailable (with message) ResponseText: EntityMetadataWrapperException: Unable to get the data property as the parent data structure is not set. in EntityStructureWrapper->getPropertyValue() (line 442 of /home4/brevisfo/public_html/profiles/commerce_kickstart/modules/contrib/entity/includes/entity.wrapper.inc).
Comment #3
deggertsen CreditAttribution: deggertsen as a volunteer commentedJust thought I should chime in. I've run into this problem on multiple websites. Here's the full error.
EntityMetadataWrapperException: Unable to get the data property currency_code as the parent data structure is not set. in EntityStructureWrapper->getPropertyValue() (line 438 of /sites/all/modules/entity/includes/entity.wrapper.inc).
I've managed to work around this by removing the lines that throw this error as shown below:
It would be nice to have a permantent solution, but I'm not sure how to get to the bottom of where it's coming from.
Added a couple of issues I believe are related.
Comment #4
Tsegaye CreditAttribution: Tsegaye commentedIn my case, #3 will make the order bypass the coupons applied because it originally did not get the coupon data, that's why the entity module returned it did not get the parent data.
Comment #5
Joe HuggansI can confirm that this is related to the coupon module in my case, it happens if you add a coupon to an order, then leave the review page and then return to the review page.
Comment #6
donquixote CreditAttribution: donquixote commentedI also experience this error.
"past" module gives me a stack trace:
The culprit is this code in commerce_line_item.module:
In my case, I have a custom line item type where the commerce_total is empty, that is, it has no field items.
Solution
The question is: Do we consider such a line item "broken", or is this is a rare but valid case that needs to be supported?
Consider it "broken", and throw a custom exception.
Do not just let Entity API throw its exception.
Instead, either
- catch the exception from Entity API, and throw a custom exception, saying "Line item 123 of type xyz does not have any items in commerce_total field. Cannot compute order total from 5 line items.", or
- check whether commerce_total exists (e.g.
!empty($line_item_wrapper->commerce_total->value()
), and then throw a custom exception.Consider it "broken", but treat it as price === zero
As above, either catch the EntityMetadataWrapperException, or do a check before.
Log a watchdog message, saying "line item 123 of type xyz does not have any items in commerce_total field. It was assumed that this item is for free.".
Then skip this line item for calculating the sum.
Consider it a valid case, treat as zero
As above: Either catch the EntityMetadataWrapperException, or do a check before.
Then simply count the item as zero / skip it, and do not log an error or throw an exception.
Notes
I want to say the entire function commerce_line_items_total() looks way more complicated than it should be.
Also, it looks like it will fail if the list is empty? Just a guess.
Comment #7
donquixote CreditAttribution: donquixote commentedI found some code duplication:
- commerce_order_calculate_total()
- commerce_line_items_total()
These two share a lot of code, and are susceptible to the same error, if commerce_total has no field items for one line item.
The differences:
- commerce_order_calculate_total() also removes orphan line item references from the order.
- commerce_order_calculate_total() writes the result into $order_wrapper->commerce_order_total, instead of returning it.
It could be refactored such that commerce_order_calculate_total() would call commerce_line_items_total() for the calculation.
Comment #8
donquixote CreditAttribution: donquixote commentedAnother difference:
commerce_order_calculate_total() also looks into the components for each $line_item_wrapper->commerce_total.
commerce_line_items_total() does not do this.
This is strange.
Shouldn't both give the same result?
Comment #9
donquixote CreditAttribution: donquixote commentedI re-open this, because there is now more information.
If the questions in my previous posts can be answered, I can produce a patch, which fixes this issue and also cleans up the two functions.