function _uc_coupon_options_list in Ubercart Discount Coupons 7.3
Same name and namespace in other branches
- 7.2 uc_coupon.module \_uc_coupon_options_list()
Helper function to create a list of coupons for form elements.
Parameters
$coupons: An array of validated coupon objects to include in the list.
$in_session: TRUE to include only coupons currently added to the session. FALSE to include those not in the session (e.g. automatic coupons).
Return value
An associative array mapping coupon code to coupon title.
3 calls to _uc_coupon_options_list()
- uc_checkout_pane_coupon_automatic in ./
uc_coupon.module - A checkout pane listing any automatic discounts.
- uc_coupon_form in ./
uc_coupon.module - Form builder for the uc_coupon form.
- uc_coupon_uc_cart_pane in ./
uc_coupon.module - Implements hook_uc_cart_pane().
File
- ./
uc_coupon.module, line 1282 - Provides discount codes and gift certificates for Ubercart.
Code
function _uc_coupon_options_list($coupons, $in_session = TRUE) {
$options = array();
if (!empty($coupons)) {
foreach ($coupons as $coupon) {
if (!$in_session xor uc_coupon_session_get($coupon->code)) {
$options[$coupon->code] = $coupon->title;
if ($coupon->type === 'credit') {
$credit = empty($coupon->usage['value']['codes'][$coupon->code]) ? 0 : $coupon->usage['value']['codes'][$coupon->code];
$credit += empty($coupon->amount) ? 0 : $coupon->amount;
$credit = $credit > $coupon->value ? 0 : $coupon->value - $credit;
$options[$coupon->code] .= ' (' . t('@credit credit remaining', array(
'@credit' => uc_currency_format($credit),
)) . ')';
}
}
}
}
return $options;
}