function uc_coupon_purchase_feature_form in Ubercart Discount Coupons 7.2
Same name and namespace in other branches
- 5 uc_coupon_purchase/uc_coupon_purchase.module \uc_coupon_purchase_feature_form()
- 6 uc_coupon_purchase/uc_coupon_purchase.module \uc_coupon_purchase_feature_form()
- 7.3 uc_coupon_purchase/uc_coupon_purchase.module \uc_coupon_purchase_feature_form()
Form builder for hook_uc_product_feature().
1 string reference to 'uc_coupon_purchase_feature_form'
- uc_coupon_purchase_uc_product_feature in uc_coupon_purchase/
uc_coupon_purchase.module - Implements hook_uc_product_feature().
File
- uc_coupon_purchase/
uc_coupon_purchase.module, line 144
Code
function uc_coupon_purchase_feature_form($form, $form_state, $node, $feature) {
$models = array(
NULL => t('Any'),
$node->model => $node->model,
);
if (module_exists('uc_attribute')) {
$adjustments = db_query("SELECT model FROM {uc_product_adjustments} WHERE nid = :nid", array(
':nid' => $node->nid,
));
foreach ($adjustments as $adjustment) {
if (!in_array($adjustment->model, $models)) {
$models[$adjustment->model] = $adjustment->model;
}
}
}
if (!empty($feature)) {
$data = db_query("SELECT * FROM {uc_coupon_purchase} WHERE pfid = :pfid", array(
':pfid' => $feature['pfid'],
))
->fetchObject();
$form['pfid'] = array(
'#type' => 'value',
'#value' => $feature['pfid'],
);
if (!$data) {
$data = new stdClass();
}
}
else {
$data = new stdClass();
}
$coupons = array();
$result = db_query("SELECT cid, name, code FROM {uc_coupons} WHERE status = :status", array(
':status' => 0,
));
foreach ($result as $coupon) {
$coupons[$coupon->cid] = $coupon->name . ' (' . $coupon->code . ')';
}
if (!$coupons) {
drupal_set_message(t('No inactive coupons found. Please <a href="!url">create an inactive coupon</a> to use as a base coupon for purchases.', array(
'!url' => url('admin/store/coupons/add'),
)), 'error');
drupal_goto('node/' . arg(1) . '/edit/features');
}
$form['title'] = array(
'#type' => 'markup',
'#markup' => '<h2>' . t('Coupon creation') . '</h2>',
);
$form['nid'] = array(
'#type' => 'value',
'#value' => $node->nid,
);
$form['model'] = array(
'#type' => 'select',
'#title' => t('Model/SKU'),
'#default_value' => isset($data->model) ? $data->model : NULL,
'#description' => t('Select the model/SKU of the product that cause a coupon to be created.'),
'#options' => $models,
);
$form['base_cid'] = array(
'#type' => 'select',
'#title' => t('Base coupon'),
'#default_value' => isset($data->base_cid) ? $data->base_cid : reset(array_keys($coupons)),
'#description' => t('Select the coupon that will be cloned when a user purchases this product. Only inactive coupons are listed; the purchased coupon will automatically be activated.'),
'#options' => $coupons,
);
return uc_product_feature_form($form, $form_state, $node, $feature);
}