You are here

function _commerce_file_clean_line_item_wrapper in Commerce File 7

Retrieve a cleanly loaded and de-referenced line item wrapper

3 calls to _commerce_file_clean_line_item_wrapper()
commerce_file_license_issue_by_commerce_line_item in includes/commerce_file.entities.inc
Issue licenses for files in a line item
commerce_file_line_item_owner in ./commerce_file.module
Retrieve the owner account for a line item
commerce_file_refresh_line_item in ./commerce_file.module
Refresh a line item with the current product license data

File

./commerce_file.module, line 1298
Provides integration of file licenses with Commerce

Code

function _commerce_file_clean_line_item_wrapper($dirty_wrapper) {
  $field_name = _commerce_file_get_field_names('line_item_files');

  // exit if no field
  if (!isset($dirty_wrapper->{$field_name})) {
    return;
  }

  // get field items
  $field_items = $dirty_wrapper->{$field_name}
    ->value();

  // determine if wrapper is serialized
  foreach ($dirty_wrapper->{$field_name} as $field_item) {
    if (is_string($field_item->data
      ->value())) {

      // reload since other fields (commerce_unit_price) could be serialize
      $line_item = commerce_line_item_load($dirty_wrapper
        ->getIdentifier());
      return entity_metadata_wrapper('commerce_line_item', $line_item);
    }
  }
  return $dirty_wrapper;
}