function commerce_coupon_cache_coupon_count in Commerce Coupon 7.2
Calculate and store the coupon count for a discount.
For discounts with a very large number of coupons, this operation can be a bit slow to do dynamically so it is better to cache it.
Parameters
object $discount: A discount entity.
Return value
int The number of coupons related to a particular discount.
1 call to commerce_coupon_cache_coupon_count()
File
- ./
commerce_coupon.module, line 1741 - Provides coupon functionality for Drupal Commerce.
Code
function commerce_coupon_cache_coupon_count($discount) {
// Cache a coupon count for this discount.
$discount_wrapper = entity_metadata_wrapper('commerce_discount', $discount);
cache_clear_all('discount_coupon_count_' . $discount->discount_id, 'cache');
// Fill cache with new value.
$cache = $discount_wrapper->coupon_count
->value();
return $cache;
}