I made a custom line item type and tried to access the unit price value like this:

  // Create the new line item.
  $line_item = commerce_line_item_new('my_line_item', $order->order_id);
  $line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);
  $amount = $line_item_wrapper->commerce_unit_price->value();

All I get is fatal errors about using ->value() on a non object.

Same problem when I try $line_item_wrapper->getPropertyInfo().

Tried using commerce product line items, same problem. Is this a bug or expected behaviour?

Comments

thedavidmeister’s picture

Version: 7.x-1.x-dev » 7.x-1.7
rszrama’s picture

Category: bug » support
Status: Active » Closed (works as designed)

It sounds to me like for one reason or another your custom line item type never got the required fields attached to it. Looking at your field list will confirm that's the case (or at the line item type overview screen). Note that the Line Item module adds these fields when a line item type module is first installed - so if you added the hooks, tweaked the line item type name, etc. after already installing your custom module, this would not have happened. Maybe you just need to uninstall / reinstall it on a clean site. In any event, I doubt there's a bug here - just an incomplete line item type definition.