You are here

function uc_atctweaks_feature_form_submit in UC Add to Cart Tweaks 6

Same name and namespace in other branches
  1. 7 uc_atctweaks.module \uc_atctweaks_feature_form_submit()
1 call to uc_atctweaks_feature_form_submit()
uc_atctweaks_nodeapi in ./uc_atctweaks.module
Implementation of hook_nodeapi().

File

./uc_atctweaks.module, line 208
Defines a product feature to tweak the add to cart form behavior.

Code

function uc_atctweaks_feature_form_submit($form, &$form_state) {

  // Build an array of Add to Cart Tweaks data from the form submission.
  $vp_data = array(
    'pfid' => $form_state['values']['pfid'],
    'cart_empty' => $form_state['values']['cart_empty'],
    'redirect' => $form_state['values']['redirect'],
  );

  // Build the product feature description.
  $tweaks_form = _uc_atctweaks_feature_form();
  $description = array(
    t('<b>Add to cart form redirect:</b> @redirect', array(
      '@redirect' => $tweaks_form['redirect']['#options'][$vp_data['redirect']],
    )),
  );
  if ($vp_data['cart_empty']) {
    $description[] = t('The cart will be emptied prior to adding this item to it.');
  }

  // Save the basic product feature data.
  $data = array(
    'pfid' => $vp_data['pfid'],
    'nid' => $form_state['values']['nid'],
    'fid' => 'atctweaks',
    'description' => implode('<br />', $description),
  );
  $form_state['redirect'] = uc_product_feature_save($data);

  // Insert or update the data in the Variable Price products table.
  if (empty($data['pfid'])) {
    $vp_data['pfid'] = db_last_insert_id('uc_product_features', 'pfid');
    $key = NULL;
  }
  else {
    $vp_data['vpid'] = db_result(db_query("SELECT vpid FROM {uc_atctweaks_products} WHERE pfid = %d", $data['pfid']));
    $key = 'vpid';
  }
  drupal_write_record('uc_atctweaks_products', $vp_data, $key);
}