function commerce_discount_usage_get_usage in Commerce Discount 7
Get usage of a discount, excluding a certain order id.
Parameters
string $discount_name: The discount name.
bool $exclude_order_id: If TRUE, the order id will be excluded from the SQL request.
Return value
int Return the number of usage.
2 calls to commerce_discount_usage_get_usage()
- commerce_discount_handler_field_commerce_discount_analytics::render in includes/
views/ handlers/ commerce_discount_handler_field_commerce_discount_analytics.inc - Render the field.
- commerce_discount_usage_max_usage in ./
commerce_discount.rules.inc - Rules condition callback: evaluate maximum usage of a discount.
File
- ./
commerce_discount.module, line 1236 - Defines the discount and discount offer entities, bundles and functionality.
Code
function commerce_discount_usage_get_usage($discount_name, $exclude_order_id = FALSE) {
$query = db_select('commerce_discount_usage', 'g')
->fields('g')
->condition('g.discount', $discount_name);
if ($exclude_order_id) {
$query
->condition('g.order_id', $exclude_order_id, '<>');
}
return (int) $query
->countQuery()
->execute()
->fetchField();
}