function commerce_coupon_code_exists in Commerce Coupon 7
Same name and namespace in other branches
- 7.2 commerce_coupon.module \commerce_coupon_code_exists()
Checks if a given coupon code exists.
Parameters
$code: Coupon code to check.
Return value
boolean Returns TRUE if the coupon exists, otherwise return FALSE.
2 calls to commerce_coupon_code_exists()
- commerce_coupon_form_validate in includes/
commerce_coupon_ui.forms.inc - Form API submit callback for the type form.
- commerce_coupon_generate_coupon_code in ./
commerce_coupon.module - Generates a new unique coupon code.
File
- ./
commerce_coupon.module, line 778 - Coupon System for Drupal Commerce.
Code
function commerce_coupon_code_exists($code) {
$query = new EntityFieldQuery();
$query
->entityCondition('entity_type', 'commerce_coupon')
->fieldCondition('commerce_coupon_code', 'value', $code, '=');
$result = $query
->execute();
if (empty($result)) {
return FALSE;
}
return TRUE;
}