The validation breaks with the folowing error message:

EntityMetadataWrapperException: Unable to get the data property type as the parent data structure is not set. in EntityStructureWrapper->getPropertyValue() (line 442 of /var/www/kenzo/www.kenzo.com/trunk/sites/all/modules/contrib/entity/includes/entity.wrapper.inc). Backtrace:
EntityStructureWrapper->getPropertyValue('type', Array) entity.wrapper.inc:86
EntityMetadataWrapper->value() entity.wrapper.inc:258
EntityValueWrapper->value() commerce_stock.module:425
commerce_stock_checkout_validate(Object) commerce_stock.module:211
commerce_stock_checkout_form_validate(Array, Array) form.inc:1430
form_execute_handlers('validate', Array, Array) form.inc:1371
_form_validate(Array, Array, 'commerce_checkout_form_checkout') form.inc:1106
drupal_validate_form('commerce_checkout_form_checkout', Array, Array) form.inc:833
drupal_process_form('commerce_checkout_form_checkout', Array, Array) form.inc:364
drupal_build_form('commerce_checkout_form_checkout', Array) form.inc:123
drupal_get_form('commerce_checkout_form_checkout', Object, Array) commerce_checkout.pages.inc:58
commerce_checkout_router(Object, Array) 
call_user_func_array('commerce_checkout_router', Array) menu.inc:503
menu_execute_active_handler() index.php:21

The problem is, that the shipping is added as a line item in the order.

I made a quick fix for it, you will find the patch file here.

Comments

guy_schneerson’s picture

Status: Active » Postponed (maintainer needs more info)

Hi skipyT
If my understanding is correct commerce_product_line_item_types() should return all line_item types that are products so should exclude shipping line items and the "getBundle() == 'product'" cancels the other part of the condition so other product bundles will get excluded, but havent used "getBundle" before so cant be sure.

I cant recreate the problem and suspect it may be related to other custom or contrib modules ( not ruling out it is to do with stock)

skipyT’s picture

Hi guy_shneerson,

I didn't have time today to check the problem, because I had an urgent deadline, and the project wasn't written by me, I only took it yesterday. I will investigate on Monday and I will return with more information, because you are right about commerce_product_line_item_types().

skipyT’s picture

Status: Postponed (maintainer needs more info) » Closed (fixed)

I checked it today morning the fatal error is comming from the: $line_item_wrapper->type->value(), when the line item is shipping.
And is not comming from your module. I'm investigating now what is the problem, cause the shipping is not loaded well.

wgsimon’s picture

Status: Closed (fixed) » Active

Hi

I've encountered the same error. It's hard to say which module it's coming from, stock, shipping or entity. I have posted here as the errors are the same and the suggested fixes are to the shipping module. I am using commerce_stock-7.x-1.0-rc2 and commerce_shipping-7.x-1.0 with the 'Example plugin' shipping method. I can post a precise sequence of steps from a fresh install to reproduce the problem if needed.

If I checkout to the point where shipping is added as a line item but then view the cart and click on the checkout button I get the error:

EntityMetadataWrapperException: Unknown data property commerce_product. in EntityStructureWrapper->getPropertyInfo() (line 339 of [...]\sites\all\modules\contrib\entity\includes\entity.wrapper.inc).

Having got rid this error (see below), if I continue the checkout process, choose the shipping and 'Continue to next step' I get the error mentioned by skipyT above:

EntityMetadataWrapperException: Unable to get the data property type as the parent data structure is not set. in EntityStructureWrapper->getPropertyValue() (line 440 of [...]\sites\all\modules\contrib\entity\includes\entity.wrapper.inc).

This can be fixed using skipyT's suggestion. As mentioned, $line_item_wrapper->type->value() causes the error as this property is not set and $line_item_wrapper->getBundle() can be used instead to get the correct types for product or shipping line items. In commerce_stock_checkout_form_validate() I replaced

	if (in_array($line_item_wrapper->type->value(), commerce_product_line_item_types())) {

with

	if (in_array($line_item_wrapper->getBundle(), commerce_product_line_item_types())) {

... and to fix the first error I was having, in commerce_stock_form_commerce_cart_validate() I wrapped

      $product_id = $line_item_wrapper->commerce_product->product_id->value();
      $product = commerce_product_load($product_id);
      if (!(isset($product->commerce_stock_override['und']) && $product->commerce_stock_override['und'][0]['value'] == 1)) {
        if (commerce_stock_product_check_out_of_stock($product_id, $qty, $remaining_stock)) {
          form_set_error("edit_quantity][$index", t('The maximum stock of %title that can be purchased is %max.', array('%title' => $product->title, '%max' => $remaining_stock)));
        }
      }

with a check for the product

    if ($line_item_wrapper->getBundle() == 'product') {
      $product_id = $line_item_wrapper->commerce_product->product_id->value();
      $product = commerce_product_load($product_id);
      if (!(isset($product->commerce_stock_override['und']) && $product->commerce_stock_override['und'][0]['value'] == 1)) {
        if (commerce_stock_product_check_out_of_stock($product_id, $qty, $remaining_stock)) {
          form_set_error("edit_quantity][$index", t('The maximum stock of %title that can be purchased is %max.', array('%title' => $product->title, '%max' => $remaining_stock)));
        }
      }
    }

Will

guy_schneerson’s picture

thanks wgsimon,
i will try and recreate the problem and get back to you if ill need more details,
The problem with skipyT fix is it allows for only the default product bundle and will disable stock checking for any user created bundles.

guy_schneerson’s picture

Version: 7.x-2.x-dev » 7.x-1.0-rc2
Status: Active » Needs review
StatusFileSize
new3.59 KB

thanks skipyT & wgsimon
I have replaced all instances of $line_item_wrapper->type->value() with $line_item_wrapper->getBundle() fixed the issue and is better code thanks to you both.
I will commit the changes to the dev version that also has other improved EntityMetaData code.

If you can test the dev version (git or should refresh by tomorrow) and let me know, would be of great help as i am planning a full stock 7.x-1.0 soon.

skipyT’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me! I just tested it locally, I don't have the error.

Thanks!

wgsimon’s picture

Many thanks, that works for me too.

guy_schneerson’s picture

Status: Reviewed & tested by the community » Fixed

Thanks guys for testing (will push this soon to an rc3)

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

TyrelDenison’s picture

Status: Closed (fixed) » Active

I am having the same problem with version 2. I have applied the patches manually, as they are meant for version 1, but they do not work. Below is my complete backtrace. Any help would be greatly appreciated as I have been dealing with some manner of this bug ever since the site went live. Stock management was a last minute request that has become a bit of a nightmare.

EntityMetadataWrapperException: Unable to get the data property type as the parent data structure is not set. in EntityStructureWrapper->getPropertyValue() (line 442 of C:\Users\tyrel_denison\LocalPantheon\Damaco-Fulfillment\profiles\commerce_kickstart\modules\entity\includes\entity.wrapper.inc). Backtrace:
EntityStructureWrapper->getPropertyValue('type', Array) entity.wrapper.inc:86
EntityMetadataWrapper->value() entity.wrapper.inc:258
EntityValueWrapper->value() commerce_line_item.module:1381
commerce_line_items_quantity(Object, Array) commerce_cart.module:58
commerce_cart_menu_item_title(1) 
call_user_func_array('commerce_cart_menu_item_title', Array) menu.inc:699
_menu_item_localize(Array, Array, 1) menu.inc:927
_menu_link_translate(Array) menu.inc:1508
_menu_tree_check_access(Array) menu.inc:1511
_menu_tree_check_access(Array) menu.inc:1498
menu_tree_check_access(Array, Array) menu.inc:1351
menu_build_tree('navigation', Array) menu.inc:1314
menu_tree_page_data('navigation', NULL, 1) menu.inc:2374
menu_set_active_trail() menu.inc:2535
menu_get_active_trail() menu.inc:2553
menu_get_active_breadcrumb() common.inc:250
drupal_get_breadcrumb() theme.inc:2476
template_process_page(Array, 'page') theme.inc:1024
theme('page', Array) common.inc:5766
drupal_render(Array) common.inc:5629
drupal_render_page('
guy_schneerson’s picture

Version: 7.x-1.0-rc2 » 7.x-2.x-dev

ok changing the issue to V2
Possibly related to http://drupal.org/node/1606624.

philipz’s picture

Any progress on V2? I have the same issue and I'm not sure if I should try to use patch #7 and apply it to V2.

EDIT: I've changed all $line_item_wrapper->type->value() in commerce_stock.module (3 occurances) to $line_item_wrapper->getBundle() and it works fine now.

Thanks for this module by the way! Really appriciate it!

guy_schneerson’s picture

Got loads on but will do it this week, if not before then this weekend.

guy_schneerson’s picture

StatusFileSize
new3.84 KB

This patch should fix things, it makes for cleaner code using the get getBundle() but the main thing is adding a missing check on the cart validation function.

guy_schneerson’s picture

Status: Active » Needs review

committed http://drupalcode.org/project/commerce_stock.git/commit/0d6848b

please test the dev version (should refresh by tomorrow, check the date to make sure) or pull from git.

Please let me know and if it works will release as 7.x-2.0-alpha2 !!!!

malberts’s picture

I got an error similar to #12.

I can confirm that I do not get it any more with 7.x-2.x-dev (2012-Jun-27).

TyrelDenison’s picture

This patch did not fix the problem for me. For the record, the patch for v1 (when applied to v1) did not resolve it either. If I am alone in this it may be something else in my configuration. I have disabled the shipping rule that deletes shipping line items on cart update and no longer have the error.

malberts’s picture

For the record, my error happened during some commerce_stock call but the Entity* errors were the same.

guy_schneerson’s picture

@TyrelDenison can you provide a the stack call it will allow me to see what code triggers the error
@malberts is #20 before or after the patch, are you still getting errors?

malberts’s picture

@guy_schneerson: #20 is before the patch. I am not getting the error any more (#18). Sorry for the confusion.

Just some more information: I did not capture my backtrace (and I don't have another site to get it from), but the way I got the error was I went to payment and then simulated a failed payment so I ended up back at the review page (/checkout/123/review). When trying to proceed to the next step I would get those Entity* errors. Now that I look at it, my error was actually closer to the OP's error than #12. The key point being that my backtrace mentioned a commerce_stock function call before the Entity* errors appeared.

guy_schneerson’s picture

Hi @malberts that's cool I know where the issue was before the patch, it was cycling through the basket and not checking if line items where products. the backtrace is for @TyrelDenison as he is still getting problems. I cant see how this is related to the stock as this patch should have closed the only hole in the system but a call stack can help identify the issue.

TyrelDenison’s picture

@Guy The backtrace I get is listed in #12. Honestly I'm not even certain that my issue is related to the stock module as it is not mentioned in the backtrace, and I see that it is in the backtrace from the original issue post. All of the symptoms and triggers are the same, but not mention of stock. I think something else may be trying to grab the same stale information that stock was when it was causing the error. Go figure.

guy_schneerson’s picture

Status: Needs review » Fixed

@TyrelDenison Dosent look like a stock issue it may be a problem with a damaged/corrupt line item (i have seen them before). try and test with a different loged in user.
setting to fixed but open it if it turns out to be stock

TyrelDenison’s picture

Oddly enough, this only occurs with anonymous users.

guy_schneerson’s picture

@TyrelDenison try anonymous users on different browsers or clear your cookies. if its only on one of them it is most likely damaged/corrupt line item.

TyrelDenison’s picture

@guy_schneerson It is across all browsers and with cleared cookies. I something is trying to access the shipping line items and it panics when they are not there. For this reason, I disabled the shipping rule I mentioned in #19. rszrama says there should be no real side effect of disabling it based on how I'm calculating things. That will have to work for now, as I have other aspects of the site to finish up. If I find out later it does actually have something to do with stock, I'll report back. Thanks for your help.

hadsie’s picture

StatusFileSize
new798 bytes

I'm in the same boat with this one. The original patch was working for me but doesn't apply against the latest codebase, so I'm attaching a new patch that does. Unfortunately I'm short of time atm to debug this one any further.

guy_schneerson’s picture

Hi @hadsie the patch #16 was already committed see #17 so any previous patches will not work.

as far as the change you include in the patch the second part of the condition is cancelled out by the first.

The function commerce_product_line_item_types() should return 'product' under normal circomstances, what can help is if you try to dump or print_r the autpot of commerce_product_line_item_types() ans let me know what you get, so it would be something like

function commerce_stock_checkout_validate($order_wrapper) {
print_r(commerce_product_line_item_types());
.....
}

output something like:
Array ( [0] => product )

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

guy_schneerson’s picture

Title: Fatal error when order status goes back from review to checkout state » EntityMetadataWrapperException: Unable to get the data property type as the parent data structure is not set
greatmatter’s picture

Status: Closed (fixed) » Active

I hate to reopen such an old issue, but we suddenly started seeing the same error (different line number), and it's sort of major, because it turns out this actually happened a few months ago, and just didn't have enough data to determine the cause... We cannot seem to artificially reproduce the issue. We are using commerce_stock 7.x-2.1.

EntityMetadataWrapperException: Unable to get the data property type as the parent data structure is not set. in EntityStructureWrapper->getPropertyValue() (line 438 of /var/www/vhosts/[SITE]/sites/all/modules/entity/includes/entity.wrapper.inc).

This seems to happen in a very special but important instance. Our client ran a sale with *very* limited stock; the intent was to sell out within 5 minutes. They had a few hundred people looking to buy.

From what we were able to ascertain from logs, with a little speculation, is this:

  1. Product X has 1 item available.
  2. Product Y is not stock limited.
  3. User A adds 1 Product X to cart, and 1 Product Y to cart.
  4. User B adds 1 Product X to cart.
  5. User A checks out, payment gateway hasn't responded...
  6. Simultaneously, User B checks out, payment gateway responds immediately, everything proceeds normally for User B.
  7. ...User A payment gateway responds, records payment to order.
  8. User A sees error message above. It's fatal, so they're confused, and refresh window.
  9. User A sees "out of stock" message, gets very upset, then decides to keep calm and carry on to make payment for product Y left in cart. Payment gateway responds everything proceeds normally for user.
  10. User A checks credit card statement, sees two charges: one for original amount as if Product X had been purchased, and one for new amount without Product X.
  11. Client panic ensues.
  12. Sysadmin (that's me) calms client, then checks payment tab for the order, sees both payments made for order, as well as the PHP error in watchdog.
guy_schneerson’s picture

Hi @greatmatter
The only rule that's gets triggered after payment is the "Stock: Decrease when completing the order process" a recent patch has been submitted to help in validation of non typical circumstances.
Can you check if the patch fixes it for you:
https://www.drupal.org/node/2446713#comment-9689931

guy_schneerson’s picture

Pushed a related patch, if anyone with this issue can test the dev version hopefully this issue is now fixed

guy_schneerson’s picture

Status: Active » Postponed (maintainer needs more info)

Will close in a month or so if no one can report that this is still an issue

guy_schneerson’s picture

Status: Postponed (maintainer needs more info) » Fixed

I asume this is now fixed, but do re-open if comes up again.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.