You are here

function uc_coupon_load in Ubercart Discount Coupons 6

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

Load a coupon object.

Parameters

$cid: Unique coupon ID.

Return value

$coupon A coupon object.

7 calls to uc_coupon_load()
uc_coupon_delete_confirm_submit in ./uc_coupon.admin.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_feature_form_submit in uc_coupon_purchase/uc_coupon_purchase.module
uc_coupon_purchase_order in uc_coupon_purchase/uc_coupon_purchase.module
Implementation of hook_order().

... See full list

File

./uc_coupon.module, line 291
Provides discount coupons for Ubercart.

Code

function uc_coupon_load($cid) {
  $coupon = db_fetch_object(db_query("SELECT * FROM {uc_coupons} WHERE cid = %d", $cid));
  $coupon->data = $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'];
    }
    else {
      if (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;
}