function uc_product_feature_save in Ubercart 5
Same name and namespace in other branches
- 8.4 uc_product/uc_product.module \uc_product_feature_save()
- 6.2 uc_product/uc_product.module \uc_product_feature_save()
- 7.3 uc_product/uc_product.module \uc_product_feature_save()
Save a product feature to a product node.
Parameters
$data: An array consisting of the following keys:
- pfid: the numeric ID of the product feature when editing an existing one
- nid: the numeric ID of the product node
- fid: the string ID of the feature type
- description: the string description of the feature for the overview table
3 calls to uc_product_feature_save()
- uc_file_feature_form_submit in uc_file/uc_file.module 
- uc_recurring_feature_form_submit in payment/uc_recurring/ uc_recurring.module 
- uc_roles_feature_form_submit in uc_roles/uc_roles.module 
File
- uc_product/uc_product.module, line 2818 
- The product module for Ubercart.
Code
function uc_product_feature_save($data) {
  if (empty($data['nid']) && arg(0) == 'node' && intval(arg(1)) > 0) {
    $data['nid'] = intval(arg(1));
  }
  if (empty($data['pfid'])) {
    if (arg(0) == 'node' && arg(3) == 'features' && intval(arg(5)) > 0) {
      $data['pfid'] = intval(arg(5));
    }
    else {
      $data['pfid'] = db_next_id('{uc_product_features}_pfid');
    }
  }
  // First attempt to update an existing row.
  db_query("UPDATE {uc_product_features} SET description = '%s' WHERE pfid = %d", $data['description'], intval($data['pfid']));
  // Otherwise insert this feature as a new row.
  if (db_affected_rows() == 0) {
    db_query("INSERT INTO {uc_product_features} VALUES (%d, %d, '%s', '%s')", $data['pfid'], $data['nid'], $data['fid'], $data['description']);
    drupal_set_message(t('The product feature has been added.'));
  }
  else {
    drupal_set_message(t('The product feature has been updated.'));
  }
  return 'node/' . $data['nid'] . '/edit/features';
}