function commerce_line_items_quantity_by_id in Commerce Core 7
Returns the total quantity of a group of line items identified by ID.
Parameters
int[] $line_item_ids: An array of line item IDs whose quantities should be summed and returned.
string[] $types: An array of line item types to filter by before counting.
Return value
int The quantity of the line items.
2 calls to commerce_line_items_quantity_by_id()
- commerce_order_rules_compare_total_quantity in modules/
order/ commerce_order.rules.inc - Condition callback: compares the total quantity of products on an order against the specified quantity.
- commerce_order_rules_contains_product in modules/
order/ commerce_order.rules.inc - Condition callback: checks to see if a particular product exists on an order in the specified quantity.
File
- modules/
line_item/ commerce_line_item.module, line 1481 - Defines the core Commerce line item entity and API functions interact with line items on orders.
Code
function commerce_line_items_quantity_by_id($line_item_ids, $types = array()) {
if (empty($line_item_ids)) {
return 0;
}
if (empty($types)) {
return db_query("SELECT SUM(quantity) FROM {commerce_line_item} WHERE line_item_id IN(:line_item_ids)", array(
':line_item_ids' => $line_item_ids,
))
->fetchField();
}
else {
return db_query("SELECT SUM(quantity) FROM {commerce_line_item} WHERE line_item_id IN(:line_item_ids) AND type IN (:types)", array(
':line_item_ids' => $line_item_ids,
':types' => $types,
))
->fetchField();
}
}