You are here

function uc_recurring_feature_form_submit in Ubercart 5

File

payment/uc_recurring/uc_recurring.module, line 483
Allows you to add a recurring fee to a product/SKU to handle subscription type services.

Code

function uc_recurring_feature_form_submit($form_id, $form_values) {
  if (empty($form_values['pfid'])) {
    $fee['pfid'] = db_next_id('{uc_product_features}_pfid');
  }
  else {
    $fee['pfid'] = $form_values['pfid'];
  }
  $fee = array(
    'pfid' => $fee['pfid'],
    'model' => $form_values['model'],
    'fee_amount' => $form_values['fee_amount'],
    'initial_charge' => $form_values['initial_charge_value'] . ' ' . $form_values['initial_charge_unit'],
    'regular_interval' => $form_values['regular_interval_value'] . ' ' . $form_values['regular_interval_unit'],
    'number_intervals' => intval($form_values['number_intervals']),
  );
  uc_recurring_fee_save('product', $fee);
  $args = array(
    '@product' => empty($fee['model']) ? t('this product') : t('product @model', array(
      '@model' => $fee['model'],
    )),
    '!amount' => uc_currency_format($fee['fee_amount']),
    '!initial' => $fee['initial_charge'],
    '!regular' => $fee['regular_interval'],
    '!intervals' => t('!num times', array(
      '!num' => $fee['number_intervals'] - 1,
    )),
  );
  $data = array(
    'pfid' => $fee['pfid'],
    'nid' => $form_values['nid'],
    'fid' => 'recurring',
    'description' => t('When @product is purchased, add a fee for !amount charged first after !initial and every !regular after that !intervals.', $args),
  );
  return uc_product_feature_save($data);
}