You are here

function uc_product_feature_save in Ubercart 6.2

Same name and namespace in other branches
  1. 8.4 uc_product/uc_product.module \uc_product_feature_save()
  2. 5 uc_product/uc_product.module \uc_product_feature_save()
  3. 7.3 uc_product/uc_product.module \uc_product_feature_save()

Saves a product feature to a product node.

Parameters

$data: An array consisting of the following keys:

  • pfid: (optional) When editing an existing product feature, the numeric ID of the feature.
  • nid: The numeric ID of the product node.
  • fid: The string ID of the feature type.
  • description: The string describing the feature for the overview table.
2 calls to uc_product_feature_save()
uc_file_feature_form_submit in uc_file/uc_file.module
Submit handler for uc_file_feature_form().
uc_roles_feature_form_submit in uc_roles/uc_roles.module
Submission handler for uc_roles_feature_form().

File

uc_product/uc_product.module, line 1969
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));
    }
  }
  if (!empty($data['pfid']) && db_result(db_query("SELECT COUNT(*) FROM {uc_product_features} WHERE pfid = %d", intval($data['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']));
    drupal_set_message(t('The product feature has been updated.'));
  }
  else {

    // Otherwise insert this feature as a new row.
    db_query("INSERT INTO {uc_product_features} (nid, fid, description) VALUES (%d, '%s', '%s')", $data['nid'], $data['fid'], $data['description']);
    drupal_set_message(t('The product feature has been added.'));
  }
  return 'node/' . $data['nid'] . '/edit/features';
}