I originally posted this here, but since that issue was marked closed a long time ago, I'm opening a fresh issue for the current module version.

Basically, the Product Option module has a typo in its hook_entity_property_info() implementation that keeps it from working properly with the Entity API in some cases (like fetching Commerce Option entities by Line Item ID).

Specifically, commerce_option_entity_property_info() sets "schema_field" instead of "schema field" (check the hook doc here) for the "line_item_id", "created", and "changed" properties (though it's set correctly for the first few properties for some reason):

/**
 * Implements hook_entity_property_info().
 */
function commerce_option_entity_property_info() {
  $info = array();

  $info['commerce_option']['properties'] = array(
    //...
    'product_id' => array(
      'type' => 'integer',
      'label' => t('Product id'),
      'schema field' => 'product_id',
      'required' => TRUE,
    ),
    'line_item_id' => array(
      'type' => 'integer',
      'label' => t('Line item id'),
      'schema_field' => 'line_item_id',
      'setter callback' => 'entity_property_verbatim_set',
      'required' => TRUE,
    ),
    // ...
  );

Where I ran into this was with Rules. Rules can't fetch Commerce Options by their "line_item_id" property, even though that option is available in the Rules UI. Commerce does the fetch using entity_property_query(), which determines that the entity property isn't queryable since it doesn't have a "schema field" element and subsequently returns NULL. Check out the second line of the function in entity.property.inc:

/**
 * Queries for entities having the given property value.
 *
 * @param $entity_type
 *   The type of the entity.
 * @param $property
 *   The name of the property to query for.
 * @param $value
 *   A single property value or an array of possible values to query for.
 * @param $limit
 *   Limit the numer of results. Defaults to 30.
 *
 * @return
 *   An array of entity ids or NULL if there is no information how to query for
 *   the given property.
 */
function entity_property_query($entity_type, $property, $value, $limit = 30) {
  $properties = entity_get_all_property_info($entity_type);
  $info = $properties[$property] + array('type' => 'text', 'queryable' => !empty($properties[$property]['schema field']));
  // ...
}

I think if we just fix the commerce_option_entity_property_info() hook implementation to use "schema field" instead of "schema_field", everything will be just fine.

Comments

bjcooper created an issue. See original summary.

bjcooper’s picture

Issue summary: View changes
bjcooper’s picture

I do confirm that changing the hook_entity_property_info() keys from "schema_field" to "schema field" causes the entity_property_query() (and Rules that use it for Commerce Options) to start working as advertised.

solideogloria’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

Fixed broken hyperlink.

Confirmed that the property is set wrong. The entity API specifies schema field in its documentation. This can also be seen by viewing entity.api.php, because the comments above hook_entity_property_info() list the following:

/**
...
 *     - schema field: (optional) In case the property is directly based upon
 *       a field specified in the entity's hook_schema(), the name of the field.
 */
solideogloria’s picture

Whoops, forgot to attach the patch.