You are here

function commerce_option_new in Commerce Product Option 7.2

Same name and namespace in other branches
  1. 7 commerce_option.module \commerce_option_new()

Initialize a new commerce option.

2 calls to commerce_option_new()
commerce_option_form_alter in ./commerce_option.module
Implements hook_form_alter().
commerce_option_get_option_set_fields in ./commerce_option.admin.inc
Ajax callback that replaces the fields-part of the form with the fields defined in the Commerce Option Set (type).
1 string reference to 'commerce_option_new'
commerce_option_entity_info in ./commerce_option.module
Implements hook_entity_info().

File

./commerce_option.module, line 331

Code

function commerce_option_new($values) {
  if (!isset($values['set_id'])) {

    // Try and get the existing sets so we can provide a default value for the
    // bundle key. Otherwise just set to true to avoid errors in Entity API.
    $values['set_id'] = TRUE;
    $option_sets = commerce_option_set_load_multiple(FALSE);
    if (!empty($option_sets)) {
      $values['set_id'] = current($option_sets)->set_id;
    }
  }
  $values['created'] = REQUEST_TIME;
  return entity_get_controller('commerce_option')
    ->create($values);
}