You are here

function commerce_coupon_load_by_code in Commerce Coupon 7

Same name and namespace in other branches
  1. 7.2 commerce_coupon.module \commerce_coupon_load_by_code()

Loads a coupon by its coupon code.

Parameters

$code: A code of a coupon.

Return value

mixed A coupon object corresponding to the coupon code.

4 calls to commerce_coupon_load_by_code()
commerce_coupon_code_is_valid in ./commerce_coupon.module
Checks if a given coupon is valid for a given order. The validation is done by the rules engine.
commerce_coupon_handler_area_cart_form_submit in includes/views/handlers/commerce_coupon_handler_area_cart_form.inc
Submit: function commerce_coupon_handler_area_cart_form.
commerce_coupon_pane_checkout_form in includes/commerce_coupon.checkout_pane.inc
Payment pane: form callback.
commerce_coupon_pane_checkout_form_submit in includes/commerce_coupon.checkout_pane.inc
We have a valid coupon code, so submit it.

File

./commerce_coupon.module, line 604
Coupon System for Drupal Commerce.

Code

function commerce_coupon_load_by_code($code) {
  $query = new EntityFieldQuery();
  $result = $query
    ->entityCondition('entity_type', 'commerce_coupon')
    ->fieldCondition('commerce_coupon_code', 'value', $code, '=')
    ->addTag('DANGEROUS_ACCESS_CHECK_OPT_OUT')
    ->execute();
  if (empty($result)) {
    return;
  }
  $commerce_coupon = reset($result['commerce_coupon']);
  return commerce_coupon_load($commerce_coupon->coupon_id);
}