You are here

function uc_coupon_validate_multiple in Ubercart Discount Coupons 7.3

Validates a list of coupon codes against a specified order and account.

Parameters

$codes: The codes to be validated.

$order: The order that the coupon is being applied to. If NULL, the current cart contents will be used. If FALSE, product and order validation will be bypassed.

$account: The user who is attempting to use the coupon. If NULL, the current user will be assumed. If FALSE, user validation will be bypassed.

See also

uc_coupon_validate()

uc_coupon_session_validate()

File

./uc_coupon.module, line 610
Provides discount codes and gift certificates for Ubercart.

Code

function uc_coupon_validate_multiple($codes, $order, $account) {
  $order = clone $order;

  // We don't want to modify the order passed in.
  $order->data['coupons'] = array();
  $valids = array();
  $invalids = array();
  foreach ($codes as $code) {
    $coupon = uc_coupon_validate($code, $order, $account);
    if ($coupon->valid) {

      // Process valid coupons.
      $valids[$code] = $coupon;
      $order->data['coupons'][$code] = $coupon->discounts;
    }
    else {
      $invalids[$code] = $code;
    }
  }
  return array(
    'valid' => $valids,
    'invalid' => $invalids,
  );
}