function uc_coupon_condition_order_has_coupon in Ubercart Discount Coupons 7.2
Same name and namespace in other branches
- 6 uc_coupon.ca.inc \uc_coupon_condition_order_has_coupon()
- 7.3 uc_coupon.rules.inc \uc_coupon_condition_order_has_coupon()
Check if an order has a coupon applied.
File
- ./
uc_coupon.rules.inc, line 59 - Rules integration for uc_coupon
Code
function uc_coupon_condition_order_has_coupon($order, $codes = array()) {
$check_codes = array();
// If the order is in checkout by the current user, use the current session coupons.
if (_uc_coupon_is_checkout_order($order)) {
$coupons = uc_coupon_session_validate();
foreach ($coupons as $coupon) {
$check_codes[$coupon->code] = $coupon->code;
}
}
elseif (isset($order->data['coupons'])) {
$check_codes = drupal_map_assoc(array_keys($order->data['coupons']));
}
//dpm($check_codes,'here');
if (count($check_codes) > 0) {
$codes = array_filter($codes);
// If no codes specified, match any coupon.
if (count($codes) == 0) {
return TRUE;
}
// Check codes for exact or wildcard matches.
foreach ($codes as $code) {
foreach (array_keys($check_codes) as $check_code) {
if (preg_match('/^' . str_replace('\\*', '.*?', preg_quote(strtoupper(trim($code)), '/')) . '$/', $check_code)) {
return TRUE;
}
}
}
}
return FALSE;
}