You are here

function uc_coupon_load in Ubercart Discount Coupons 7.2

Same name and namespace in other branches
  1. 5 uc_coupon.module \uc_coupon_load()
  2. 6 uc_coupon.module \uc_coupon_load()
  3. 7.3 uc_coupon.module \uc_coupon_load()

Load a coupon object.

Parameters

$cid: Unique coupon ID.

Return value

$coupon A coupon object.

8 calls to uc_coupon_load()
uc_coupon_delete in ./uc_coupon.entity.inc
uc_coupon_find in ./uc_coupon.module
Load a coupon (single or bulk) from the supplied code.
uc_coupon_handler_field_codes::pre_render in views/uc_coupon_handler_field_codes.inc
Expand the coupon codes for each coupon in the result set.
uc_coupon_purchase_create_action in uc_coupon_purchase/uc_coupon_purchase.rules.inc
Action callback to give user a coupon
uc_coupon_purchase_feature_form_submit in uc_coupon_purchase/uc_coupon_purchase.module
Submit handler for uc_coupon_purchase_feature form.

... See full list

File

./uc_coupon.entity.inc, line 11

Code

function uc_coupon_load($cid) {
  $coupon = db_query("SELECT * FROM {uc_coupons} WHERE cid = :cid", array(
    ':cid' => $cid,
  ))
    ->fetchObject();
  $coupon = is_object($coupon) ? $coupon : new stdClass();
  $coupon->data = isset($coupon->data) ? unserialize($coupon->data) : array();

  // Convert old coupons that could not specify "per order" when restricted.
  if (!isset($coupon->data['apply_to'])) {
    if (isset($coupon->data['max_applicable_products_value']) && isset($coupon->data['max_applicable_products']) && $coupon->data['max_applicable_products']) {

      // Coupon was restricted to X cheapest or most expensive products.
      $coupon->data['apply_to'] = $coupon->data['max_applicable_products_value'];
      $coupon->data['apply_count'] = $coupon->data['max_applicable_products'];
    }
    elseif (isset($coupon->data['products']) || isset($coupon->data['skus']) || isset($coupon->data['terms']) || isset($coupon->data['product_types'])) {

      // Coupon has product restrictions, so was applied to each matching product.
      $coupon->data['apply_to'] = 'products';
    }
    else {

      // Coupon had no product restrictions, so was applied once to the subtotal.
      $coupon->data['apply_to'] = 'subtotal';
    }
  }
  unset($coupon->data['max_applicable_products']);
  unset($coupon->data['max_applicable_products_value']);

  // Allow other modules to alter the coupon data.
  drupal_alter('uc_coupon', $coupon);
  return $coupon;
}